package com.elseforif.servlet; import com.elseforif.servlet.utility.constraint.JVCServletParameterConstraints; import com.elseforif.servlet.utility.constraint.ServletParameters; import com.elseforif.servlet.utility.ElseForIfHTMLWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import java.io.PrintWriter; /** * This is the base class for the servlets of which elseforif.com is composed. * It incorporates a menu mode, which merely governs which menu items are * enabled for each page. This also integrates a custom print writer, * which references the aforementioned menu mode via 'getMenuMode()', * among other things. * * @author Jason Van Cleve */ abstract public class ElseForIfServlet extends JVCServlet { public static final int MENU_MODE_NONE = 0; public static final int MENU_MODE_HOME = 1; public static final int MENU_MODE_PRODUCTS = 2; public static final int MENU_MODE_SERVICES = 3; public static final int MENU_MODE_DEVELOPMENT = 4; public static final int MENU_MODE_CONTACT = 5; public static final String P_SENDER = "sender"; public static final String P_CATEGORY = "category"; public static final String P_BODY = "body"; public static final String P_CONFIRMED = "confirmed"; public static final String ATTRIBUTE_CONTACT_EMAIL_PARAMETERS = "attributeContactEmail"; protected JVCServletParameterConstraints m_parameterConstraints = null; protected int m_menuMode = MENU_MODE_NONE; /** * Return my "menu mode", an integer indicating how the menu (and the "penu") * reflect individual pages. * * @return my menu mode indicator */ public int getMenuMode() { return m_menuMode; } /** * Initialize this servlet for use. Subclasses should remember to call * this method when overriding it, even though they may reset some of the * values defined here. * * @param servletConfig an object containing this servlet's configuration */ public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); m_title = "This is Else For If."; m_description = "Else For If, an independent, full-service Web site" + " construction shop. We build dynamic, data-driven Web sites" + " based on open source software, HTML and XHTML, Java servlets" + ", CSS, JavaScript and applets, and we do database design" + ", imaging, and more."; m_keywords = "else for if, elseforif, web site, web design, web development" + ", independent, pacific northwest, construction, solutions, training" + ", imaging, open-source, full-service, full service" + ", software development, consulting, scalable, interactive" + ", data-driven, java, servlets, applets, javascript, html, xhtml" + ", xml, linux, apache, lamp, open standards"; m_truncateClassNamePrefix = "com.elseforif.servlet."; } /** * Create an ElseForIfHTMLWriter and call a form of 'doBoth()' that includes * it. Flush and close the writer upon return. This method is called by * my superclass, JVCServlet. * * @param request a servlet request * @param response a servlet response * @param session the user's session */ protected void doBoth(HttpServletRequest request, HttpServletResponse response, HttpSession session, PrintWriter printWriter) throws Exception { ServletParameters in = (m_parameterConstraints != null) ? m_parameterConstraints.getParameters(request) : null; ElseForIfHTMLWriter out = new ElseForIfHTMLWriter(printWriter, in); doBoth(request, response, session, in, out); } /** * This is the default service method for Else For If servlets, adding * an explicit ElseForIfHTMLWriter to the signature. Most subclasses * will override this method. * * @param request a servlet request * @param response the response for that request * @param session the user's session object * @param out a custom HTML output writer */ protected abstract void doBoth(HttpServletRequest request, HttpServletResponse response, HttpSession session, ServletParameters in, ElseForIfHTMLWriter out) throws Exception; }