/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.ui.conf.jsp;

import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import org.apache.log4j.*;
import com.silverwrist.venice.ui.*;

public class PostTextTag extends VeniceConfBodyTagSupport
{
  /*--------------------------------------------------------------------------------
   * Static data members
   *--------------------------------------------------------------------------------
   */

  private static Category logger = Category.getInstance(PostTextTag.class);

  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private String name = null;
  private String bodytext = null;

  /*--------------------------------------------------------------------------------
   * Overrides from class BodyTagSupport
   *--------------------------------------------------------------------------------
   */

  public int doStartTag() throws JspException
  {
    if (logger.isDebugEnabled())
      logger.debug("PostTextTag.doStartTag(): entry");
    if (name==null)
      throw new JspTagException("<post:text/> name= attribute not specified!");
    return EVAL_BODY_BUFFERED;

  } // end doStartTag

  public int doAfterBody() throws JspException
  {
    if (logger.isDebugEnabled())
      logger.debug("PostTextTag.doAfterBody(): entry");
    bodytext = getBodyContent().getString();
    return SKIP_BODY;

  } // end doAfterBody

  public int doEndTag() throws JspException
  {
    if (logger.isDebugEnabled())
      logger.debug("PostTextTag.doEndTag(): entry");
    PostBoxTag postbox = (PostBoxTag)findAncestorWithClass(this,PostBoxTag.class);
    if (postbox==null)
      throw new JspTagException("<post:text/> tag must be within a <post:box/> tag!");
    postbox.setText(name,bodytext);
    bodytext = null;
    return EVAL_PAGE;

  } // end doEndTag

  public void release()
  {
    super.release();
    name = null;

  } // end release

  /*--------------------------------------------------------------------------------
   * Attribute set functions
   *--------------------------------------------------------------------------------
   */

  public void setName(String v)
  {
    if (logger.isDebugEnabled())
      logger.debug("PostTextTag.setName(\"" + v + "\"): entry");
    name = v;

  } // end setName

} // end class PostTextTag
