SimpleServlets v5.5.0

com.simpleservlets.pageprocessor
Class PageProcessor

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.simpleservlets.pageprocessor.PageProcessor
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public abstract class PageProcessor
extends HttpServlet

This abstract class is subclassed by the application-specific class where the abstract setup() method is implemented. If any shutdown tasks need to be done, override the shutdown() method. The init(), destroy, doPost(), and doGet() methods are rarely overridden (and if any of these are overridden, care must be taken to avoid breaking PageProcessor.

Author:
Paul Hyde
See Also:
Serialized Form

Field Summary
static String ERROR_PAGE_NAME
          Reserved page name for the error page.
static String RELOAD_PAGE_NAME
          Reserved page name for the "reload warning" page.
 
Constructor Summary
protected PageProcessor()
           
 
Method Summary
 void addPage(PageHandler handler, String pageName)
          Add a PageHandler and associate it with the specified page name.
 void destroy()
          Generally this should not be overridden in subclasses—use shutdown() instead.
protected  void doGet(HttpServletRequest req, HttpServletResponse res)
          Generally this should not be overridden in subclasses—use PageHandler instead.
protected  void doHeadCustom(HttpServletRequest req, HttpServletResponse resp)
          Generally this should not be overridden in subclasses—use PageHandler instead.
protected  void doPost(HttpServletRequest req, HttpServletResponse res)
          Generally this should not be overridden in subclasses—use PageHandler instead.
 PageHandler getErrorPage()
          Returns the page handler designated as the error page.
 PageHandler getFrontPage()
          Returns the page handler designated as the front page.
 String getFrontPageName()
          Returns the name of the front page, or null if no front page has been specified yet.
 ValueMap getInitValues()
          A mapping of all the web-app initialization parameters.
 PageHandler getPage(String pageName)
          Returns the page handler for the page with the specified name.
 PageHandler getPage(String pageName, Class<? extends PageHandler> pageType)
          Returns the page handler for the page with the specified name.
 String getPageName(PageHandler handler)
          Returns the name that was associated with the specified PageHandler.
 ReloadPageHandler getReloadPage()
          Returns the page handler designated for reload/refresh attempts.
 InputStream getResourceAsStream(String pathToResource)
          Retrieves a stream to a resource typically in the web-app context, typically from a file in a WAR-file.
 ValueMap getResourceAsValueMap(String pathToResource)
          Creates a ValueMap from a resource typically in the web-app context, typically from a file in a WAR-file.
protected  Session.Manager getSessionManager()
           
 void init()
          Generally this should not be overridden in subclasses—use setup() instead.
 boolean isFrontPageAvailable()
          Returns true if there is a front page stored.
 boolean isPageAvailable(String pageName)
          Returns true if there is a page stored for the specified page name.
 void setErrorPage(PageHandler handler)
          Indicates the page to use when an uncaught exception occurs.
 void setFrontPage(PageHandler handler, String pageName)
          Add a PageHandler and associate it with the specified page name.
 void setReloadPage(ReloadPageHandler handler)
          Indicates the page to use when the user presses reload/refresh.
abstract  void setup()
          Implemented by subclasses to configure initial settings.
 void showReloadPage(PageContext pc)
          Requests that the reload/refresh warning page be shown.
 void showReloadPage(PageContext pc, String continuePage)
          Requests that the reload/refresh warning page be shown.
 void shutdown()
          Called from the destroy() method of the servlet.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_PAGE_NAME

public static final String ERROR_PAGE_NAME
Reserved page name for the error page. This name must be used as the only name for the error page for PageProcessor to function correctly. Also, no other page may use this reserved page name. The name of this page is always: "PageProcessorErrorPage".

See Also:
Constant Field Values

RELOAD_PAGE_NAME

public static final String RELOAD_PAGE_NAME
Reserved page name for the "reload warning" page. This name must be used as the only name for the reload page for PageProcessor to function correctly. Also, no other page may use this reserved page name. The name of this page is always: "PageProcessorReloadPage".

See Also:
Constant Field Values
Constructor Detail

PageProcessor

protected PageProcessor()
Method Detail

setup

public abstract void setup()
                    throws PageProcessorException
Implemented by subclasses to configure initial settings. Called one time—before any page requests are serviced (called at the end of the servlet's init() method). Both getInitValues() and getSessionManager() may be safely called from within setup().

Throws:
PageProcessorException

getInitValues

public ValueMap getInitValues()
A mapping of all the web-app initialization parameters.


getResourceAsStream

public InputStream getResourceAsStream(String pathToResource)
                                throws PageProcessorException
Retrieves a stream to a resource typically in the web-app context, typically from a file in a WAR-file. Path usually begins with "/", but this is not required.

See IOTools.getInputStreamForResource(String) as a more direct way of getting a stream. During initialization, PageProcessor registers itself as a IOTools.ServletResourceLocator with IOTools.

Throws:
PageProcessorException - if the specified resource can not be found in the web-app context.

getResourceAsValueMap

public ValueMap getResourceAsValueMap(String pathToResource)
                               throws PageProcessorException
Creates a ValueMap from a resource typically in the web-app context, typically from a file in a WAR-file. Path usually begins with "/", but this is not required.

See ValueMap.createFromResource(String) as a more direct way of getting a map. During initialization, PageProcessor registers itself as a IOTools.ServletResourceLocator with IOTools.

Throws:
PageProcessorException - if the resource does not exist or if there are problems reading from the specified file.

getSessionManager

protected Session.Manager getSessionManager()

setFrontPage

public void setFrontPage(PageHandler handler,
                         String pageName)
Add a PageHandler and associate it with the specified page name. This page will also be marked as the "front page". The "front page" is returned for unknown page names and when no page name is specified.


isFrontPageAvailable

public boolean isFrontPageAvailable()
Returns true if there is a front page stored.


getFrontPage

public PageHandler getFrontPage()
                         throws PageProcessorException
Returns the page handler designated as the front page.

Throws:
PageProcessorException - if no front page has been set.

getFrontPageName

public String getFrontPageName()
Returns the name of the front page, or null if no front page has been specified yet.


setErrorPage

public void setErrorPage(PageHandler handler)
Indicates the page to use when an uncaught exception occurs. If this method is never called, or if null is passed in, GenericErrorPage is used. There is always an error page defined.


getErrorPage

public PageHandler getErrorPage()
Returns the page handler designated as the error page.


setReloadPage

public void setReloadPage(ReloadPageHandler handler)
Indicates the page to use when the user presses reload/refresh. If this method is never called, or if null is passed in, GenericReloadPage is used. There is always a reload page defined.


getReloadPage

public ReloadPageHandler getReloadPage()
Returns the page handler designated for reload/refresh attempts.


showReloadPage

public void showReloadPage(PageContext pc)
                    throws PageProcessorException
Requests that the reload/refresh warning page be shown.

Throws:
PageProcessorException

showReloadPage

public void showReloadPage(PageContext pc,
                           String continuePage)
                    throws PageProcessorException
Requests that the reload/refresh warning page be shown. The continuePage indicates the page that the "no reload" page should provide a link to for the user to "continue" on to after reading the warning.

Parameters:
pc - context of the current request/response cycle
continuePage - the page to link to from the warning page. If null is passed in, then the link will be to the original requested page that was part of the reload triggering.
Throws:
PageProcessorException

addPage

public void addPage(PageHandler handler,
                    String pageName)
Add a PageHandler and associate it with the specified page name.


isPageAvailable

public boolean isPageAvailable(String pageName)
Returns true if there is a page stored for the specified page name.


getPage

public PageHandler getPage(String pageName,
                           Class<? extends PageHandler> pageType)
                    throws PageProcessorException
Returns the page handler for the page with the specified name.

Throws:
PageProcessorException - if no page with that name can be found, or if the page found does not match the pageType specified.

getPage

public PageHandler getPage(String pageName)
                    throws PageProcessorException
Returns the page handler for the page with the specified name.

Throws:
PageProcessorException - if no page with that name can be found.

getPageName

public String getPageName(PageHandler handler)
                   throws PageProcessorException
Returns the name that was associated with the specified PageHandler.

Parameters:
handler - to look up name for
Returns:
the name associated with the specified handler
Throws:
PageProcessorException - if no name has been associated, or if 2+ names were associated with the same handler.

shutdown

public void shutdown()
Called from the destroy() method of the servlet. Default implementation does nothing, override if any specific cleanup must be done.


init

public void init()
          throws ServletException
Generally this should not be overridden in subclasses—use setup() instead. If in a rare case this method does need to be overridden, be sure to call super.init() first.

Overrides:
init in class GenericServlet
Throws:
ServletException

destroy

public void destroy()
Generally this should not be overridden in subclasses—use shutdown() instead. If in a rare case this method does need to be overridden, be sure to call super.destory() first.

Specified by:
destroy in interface Servlet
Overrides:
destroy in class GenericServlet

doGet

protected void doGet(HttpServletRequest req,
                     HttpServletResponse res)
              throws ServletException,
                     IOException
Generally this should not be overridden in subclasses—use PageHandler instead.

Overrides:
doGet in class HttpServlet
Throws:
ServletException
IOException

doHeadCustom

protected void doHeadCustom(HttpServletRequest req,
                            HttpServletResponse resp)
                     throws ServletException,
                            IOException
Generally this should not be overridden in subclasses—use PageHandler instead. This implementation overrides the default in HttpServlet and does NOT call doGet()!

Throws:
ServletException
IOException

doPost

protected void doPost(HttpServletRequest req,
                      HttpServletResponse res)
               throws ServletException,
                      IOException
Generally this should not be overridden in subclasses—use PageHandler instead.

Overrides:
doPost in class HttpServlet
Throws:
ServletException
IOException

SimpleServlets v5.5.0

Copyright © 2001-2007 Programix Incorporated. All rights reserved. SimpleServlets is free and is OSI Certified Open Source Software under the BSD license.