package moreservlets.tags;

import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import moreservlets.listeners.*;

/** If the number of active sessions is above the limit,
 *  this prints a warning. Otherwise, it does nothing.
 *  <P>
 *  Taken from More Servlets and JavaServer Pages
 *  from Prentice Hall and Sun Microsystems Press,
 *  http://www.moreservlets.com/.
 *  &copy; 2002 Marty Hall; may be freely used or adapted.
 */

public class SessionCountWarningTag extends TagSupport {
  public int doStartTag() {
    try {
      String warning =
        ActiveSessionCounter.getSessionCountWarning();
      if (warning != null) {
        JspWriter out = pageContext.getOut();
        out.println("<H1><FONT COLOR=\"RED\">");
        out.println(warning);
        out.println("</FONT></H1>");
      }
    } catch(IOException ioe) {
      System.out.println("Error printing session warning.");
    }
    return(SKIP_BODY);
  }
}
