package test;

import java.io.*;

import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

/**
 * IfSessionTag evaluates its contents if the session attribute exists.
 */
public class IfSessionTag extends TagSupport  {
  private String attr;

  /**
   * The JSP page will set the attribute before calling doStartTag
   */
  public void setAttr(String attr)
  {
    this.attr = attr;
  }
  
  /**
   * Returns SKIP_BODY to skip and EVAL_BODY_INCLUDE to evaluate.
   */
  public int doStartTag() throws JspException
  {
    HttpSession session = pageContext.getSession();

    if (session == null || session.getAttribute(attr) == null)
      return SKIP_BODY;
    else
      return EVAL_BODY_INCLUDE;
  }
}
