package moreservlets.tags;

import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import moreservlets.listeners.*;

/** The InitialCompanyNameListener class has static
 *  methods that permit access to the current and former
 *  company names. But, using these methods in JSP requires
 *  explicit Java code, and creating beans that provided
 *  the information would have yielded a cumbersome result.
 *  So, we simply move the code into a custom tag.
 *  <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 CompanyNameTag extends TagSupport {
  public int doStartTag() {
    try {
      ServletContext context = pageContext.getServletContext();
      String companyName = 
        InitialCompanyNameListener.getCompanyName(context);
      JspWriter out = pageContext.getOut();
      out.print(companyName);
    } catch(IOException ioe) {
      System.out.println("Error printing company name.");
    }
    return(SKIP_BODY);
  }
}
