SimpleServlets v5.5.0

com.simpleservlets.pageprocessor
Class HTMLObjectsPageHandler

java.lang.Object
  extended by com.simpleservlets.pageprocessor.HTMLObjectsPageHandler
All Implemented Interfaces:
PageHandler
Direct Known Subclasses:
GenericErrorPage, GenericReloadPage

public abstract class HTMLObjectsPageHandler
extends Object
implements PageHandler

This class bridges the world of HTML Objects and PageProcessor. It implements the PageHandler interface and creates a generic HTMLElement container to be filled in by the subclass. When the page is ready, the sendPage(PageContext, HTMLElement) method is called to send the content to the browser. Pages that are permitted to be directly requested by a browser will want to override the processRequest(PageContext, HTMLElement) method. Pages that want to specify a header for the top of the page will want to override the createHeader(PageContext, HTMLElement) method. Pages that want to specify a footer for the bottom of the page will want to override the createFooter(PageContext, HTMLElement) method.

Author:
Paul Hyde

Field Summary
protected  HTMLColor defaultPageBackgroundColor
           
protected  String defaultTitle
           
 
Constructor Summary
protected HTMLObjectsPageHandler()
          Sets the default title to "Untitled" and the default page background color to white.
protected HTMLObjectsPageHandler(String defaultTitle)
          Sets the specified default title and the sets the default page background color to white.
protected HTMLObjectsPageHandler(String defaultTitle, HTMLColor defaultPageBackgroundColor)
          Sets the specified default title and the specified default page background color.
 
Method Summary
protected  void createFooter(PageContext pc, HTMLElement con)
          Subclasses override this method to provide a "footer" that should be at the bottom of the page.
protected  void createHeader(PageContext pc, HTMLElement con)
          Subclasses override this method to provide a "header" that should be at the top of the page.
protected  HTMLColor getPageBackgroundColor(PageContext pc)
          Returns the background color that should be currently used for this page.
protected  String getTitle(PageContext pc)
          Returns the HTML page title that should be currently used for this page.
 void processRequest(PageContext pc)
          This implementation of the PageHandler method creates an HTML element container and then calls processRequest(PageContext, HTMLElement) to fill up the container.
protected  void processRequest(PageContext pc, HTMLElement con)
          This method is called whenever there is a request aimed at this page.
protected  void sendPage(PageContext pc, HTMLElement con)
          This method is called from the subclass to indicate that this page should be delivered to the browser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultTitle

protected final String defaultTitle

defaultPageBackgroundColor

protected final HTMLColor defaultPageBackgroundColor
Constructor Detail

HTMLObjectsPageHandler

protected HTMLObjectsPageHandler(String defaultTitle,
                                 HTMLColor defaultPageBackgroundColor)
Sets the specified default title and the specified default page background color. The getTitle(PageContext) method can be overridden in subclasses to return a title that overrides this default title. The getPageBackgroundColor(PageContext) method can be overridden in subclasses to return a color that overrides this default background color.


HTMLObjectsPageHandler

protected HTMLObjectsPageHandler(String defaultTitle)
Sets the specified default title and the sets the default page background color to white.


HTMLObjectsPageHandler

protected HTMLObjectsPageHandler()
Sets the default title to "Untitled" and the default page background color to white.

Method Detail

processRequest

public final void processRequest(PageContext pc)
                          throws PageProcessorException
This implementation of the PageHandler method creates an HTML element container and then calls processRequest(PageContext, HTMLElement) to fill up the container. This method can not be overridden in subclass (if you have a need to directly handle processRequest then you can implement PageHandler directly).

Specified by:
processRequest in interface PageHandler
Throws:
PageProcessorException

processRequest

protected void processRequest(PageContext pc,
                              HTMLElement con)
                       throws PageProcessorException
This method is called whenever there is a request aimed at this page. Subclasses override this method and fill up the specified container: con with the main content of the page. The subclass should then call sendPage(PageContext, HTMLElement) to deliver this page to the browser.

This class' implementation (when not overridden) always throws a PageProcessorException to indicate that the page is not permitted to be accessed directly. Subclasses override this method to allow a page to be directly requested.

Parameters:
pc - the context of the request/response cycle
con - the container to fill up with the page's content
Throws:
PageProcessorException - can be optionally thrown to indicate that the page could not be created.

sendPage

protected void sendPage(PageContext pc,
                        HTMLElement con)
                 throws PageProcessorException
This method is called from the subclass to indicate that this page should be delivered to the browser. This method takes the specified HTMLElement and bundles it with the header and footer and sends the page off. This method calls these methods while assembling the page:

If classes other than the subclass should be allowed to call this method, then the subclass can override this method enlarging the access scope from protected to public like this:

 public void sendPage(PageContext pc, HTMLElement con) 
         throws PageProcessorException {
 
     super.sendPage(pc, con);
 }
 

Parameters:
pc - the context to use for sending the page
con - the container that forms the main content of the page.
Throws:
PageProcessorException - if there is trouble generating the header or footer, or sending the page.

getPageBackgroundColor

protected HTMLColor getPageBackgroundColor(PageContext pc)
                                    throws PageProcessorException
Returns the background color that should be currently used for this page. Subclasses can override this method when the page's background color is not fixed for all users for all time. If the page's background color is fixed for all users for the lifetime of the servlet, then the page's default background color can be specified at construction and there's no need to override this method.

Parameters:
pc - the context is made available in case it is needed to determine the value to return.
Throws:
PageProcessorException - can be optionally thrown by a subclass so signal that there was an unexpected problem determining the value to return.

getTitle

protected String getTitle(PageContext pc)
                   throws PageProcessorException
Returns the HTML page title that should be currently used for this page. Subclasses can override this method when the page's title is not fixed for all users for all time. If the page's title is fixed for all users for the lifetime of the servlet, then the page's default title can be specified at construction and there's no need to override this method.

Parameters:
pc - the context is made available in case it is needed to determine the value to return.
Throws:
PageProcessorException - can be optionally thrown by a subclass so signal that there was an unexpected problem determining the value to return.

createHeader

protected void createHeader(PageContext pc,
                            HTMLElement con)
                     throws PageProcessorException
Subclasses override this method to provide a "header" that should be at the top of the page. This class' implementation does nothing (so implementations that don't want a header simply don't bother to override this method).

Parameters:
pc - the context is made available in case it is needed to determine elements of the header.
con - the container that the header element(s) should be added to.
Throws:
PageProcessorException - can be optionally thrown by a subclass so signal that there was an unexpected problem generating the header.

createFooter

protected void createFooter(PageContext pc,
                            HTMLElement con)
                     throws PageProcessorException
Subclasses override this method to provide a "footer" that should be at the bottom of the page. This class' implementation does nothing (so implementations that don't want a footer simply don't bother to override this method).

Parameters:
pc - the context is made available in case it is needed to determine elements of the footer.
con - the container that the footer element(s) should be added to.
Throws:
PageProcessorException - can be optionally thrown by a subclass so signal that there was an unexpected problem generating the footer.

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.