/*
 * 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.jsp;

import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.ui.*;

public class UtilMenuHeaderItemTag extends VeniceBodyTagSupport
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private String href = null;
  private String selected = null;
  private int real_type = -1;
  private boolean is_selected = false;
  private String text = null;

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

  public int doStartTag()
  {
    if ((selected!=null) && selected.equals("true"))
      is_selected = true;
    return EVAL_BODY_BUFFERED;

  } // end doStartTag

  public int doAfterBody()
  {
    // throw away the actual body contents
    return SKIP_BODY;

  } // end doAfterBody

  public int doEndTag() throws JspTagException
  {
    // Do some shorts-checking on our stored data.
    if (href==null)
      throw new JspTagException("<util:menuheaderitem/> does not have a <util:href/>!");
    if (real_type<0)
      throw new JspTagException("<util:menuheaderitem/> type= attribute not a valid link type");
    if (text==null)
      throw new JspTagException("<util:menuheaderitem/> does not have a <util:text/>!");

    // Save off the completed menu item.
    UtilMenuHeaderTag parent = (UtilMenuHeaderTag)findAncestorWithClass(this,UtilMenuHeaderTag.class);
    if (parent==null)
      throw new JspTagException("<util:menuheaderitem/> must be inside a <util:menuheader/>");
    parent.pushItem(href,real_type,text,is_selected);
    href = null;
    real_type = -1;
    text = null;
    return EVAL_PAGE;

  } // end doEndTag

  public void release()
  {
    super.release();
    selected = null;
    is_selected = false;

  } // end release

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

  public void setSelected(String s)
  {
    selected = s;

  } // end setSelected

  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  final void setLink(String href, int type)
  {
    this.href = href;
    this.real_type = type;

  } // end setLink

  final void setText(String text)
  {
    this.text = text;

  } // end setText

} // end class UtilMenuHeaderItemTag

