PageMixer API - 3.1

jp.ne.dti.lares.foozy.pagemixer.servlet
Class PageServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--jp.ne.dti.lares.foozy.pagemixer.servlet.PageServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
DefaultPageServlet, DefaultPageServlet, I18NDefaultPageServlet, I18NDefaultPageServlet, LocalePageServlet, LocalePageServlet, MonoPageServlet, MonoPageServlet

public class PageServlet
extends javax.servlet.http.HttpServlet

Base Servlet class.

This provides template to combine modules shown below for response page renderring on PageMixer framework:

These modules allow you to customize renderring procedure with minimum work.

For example, when you want to read HTML page source not from file but from DB, what you should do are:

You can use your custom modules by (1)defining class derived from this, which specifies your custom modules as parameters of base class constructor, or (2)specifing class name of them in deployment descriptor as "servlet.contextFactory", "servlet.localeFactory", "servlet.forwardStrategy", "servlet.filterFactory", "servlet.pageFactory", "servlet.locatorFactory" and/or "servlet.producerFactory" 'init-param' of Servlet.

This template class provides mechanism to re-use Filter on the thread on which it is created. This reduces cost to create Filter.

To reduce memory consumption, this invokes expiration method per specified millisec interval, if it is specified and grater than 0. System.currentTimeMills() - interval is passed to expiration method as limit.

Since:
PageMixer 3.0
See Also:
Serialized Form

Field Summary
static java.lang.String PARAM_CONTEXT_FACTORY
          Name of servlet init-param to create "ContextFactory".
static java.lang.String PARAM_EXPIRE_INTERVAL
          Name of servlet init-param of expiration interval(millisec).
static java.lang.String PARAM_FILTER_FACTORY
          Name of servlet init-param to create "FilterFactory".
static java.lang.String PARAM_FORWARD_STRATEGY
          Name of servlet init-param to create "ForwardStrategy".
static java.lang.String PARAM_LOCALE_FACTORY
          Name of servlet init-param to create "LocaleFactory".
static java.lang.String PARAM_LOCATOR_FACTORY
          Name of servlet init-param to create "LocatorFactory".
static java.lang.String PARAM_PAGE_FACTORY
          Name of servlet init-param to create "PageFactory".
static java.lang.String PARAM_PRODUCER_FACTORY
          Name of servlet init-param to create "ProducerFactory".
 
Constructor Summary
PageServlet(ContextFactory contextFactory, LocaleFactory localeFactory, ForwardStrategy forwardStrategy, FilterFactory filterFactory, PageFactory pageFactory, LocatorFactory locatorFactory, ProducerFactory producerFactory)
          Construct.
 
Method Summary
 void destroy()
          Finalize.
protected  void doAction(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Template of servlet process to render response page or forward control.
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Respond to "GET" request from client.
protected  void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Respond to "POST" request from client.
 void init()
          Initialize.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, 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

PARAM_CONTEXT_FACTORY

public static final java.lang.String PARAM_CONTEXT_FACTORY
Name of servlet init-param to create "ContextFactory".

This has value "servlet.contextFactory".


PARAM_LOCALE_FACTORY

public static final java.lang.String PARAM_LOCALE_FACTORY
Name of servlet init-param to create "LocaleFactory".

This has value "servlet.localeFactory".


PARAM_FORWARD_STRATEGY

public static final java.lang.String PARAM_FORWARD_STRATEGY
Name of servlet init-param to create "ForwardStrategy".

This has value "servlet.forwardStrategy".


PARAM_FILTER_FACTORY

public static final java.lang.String PARAM_FILTER_FACTORY
Name of servlet init-param to create "FilterFactory".

This has value "servlet.filterFactory".


PARAM_PAGE_FACTORY

public static final java.lang.String PARAM_PAGE_FACTORY
Name of servlet init-param to create "PageFactory".

This has value "servlet.pageFactory".


PARAM_LOCATOR_FACTORY

public static final java.lang.String PARAM_LOCATOR_FACTORY
Name of servlet init-param to create "LocatorFactory".

This has value "servlet.locatorFactory".


PARAM_PRODUCER_FACTORY

public static final java.lang.String PARAM_PRODUCER_FACTORY
Name of servlet init-param to create "ProducerFactory".

This has value "servlet.producerFactory".


PARAM_EXPIRE_INTERVAL

public static final java.lang.String PARAM_EXPIRE_INTERVAL
Name of servlet init-param of expiration interval(millisec).

This has value "servlet.expireInterval".

Constructor Detail

PageServlet

public PageServlet(ContextFactory contextFactory,
                   LocaleFactory localeFactory,
                   ForwardStrategy forwardStrategy,
                   FilterFactory filterFactory,
                   PageFactory pageFactory,
                   LocatorFactory locatorFactory,
                   ProducerFactory producerFactory)
Construct.

This class uses class(es) specified in deployment descriptor, event though construction parameter corresponded to it is not null.

Earlier version implementation had different priority policy: it used construction parameter rather than one specified in deployment descriptor.

Parameters:
contextFactory - to create ConsumerContext
localeFactory - to create Locale
forwardStrategy - to decide control forwarding
filterFactory - to create Filter
pageFactory - to create Page
locatorFactory - to create Locator
producerFactory - to create Producer.Factory
Method Detail

doAction

protected final void doAction(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws javax.servlet.ServletException,
                              java.io.IOException
Template of servlet process to render response page or forward control.
  1. create context by ContextFactory#create()
  2. get servlet path from 'request'
  3. create Locale by LocaleFactory#create()
  4. get PageEntry by PageEntryFactory#create() or PageEntryFactory#create(), with above path and locale
  5. get encoding from PageEntry
  6. set encoding into context by encoding key for parameter decoding, if above encoding is not null
  7. get forward destination by ForwardStrategy.forwards(ConsumerContext)
  8. forward control to another page, if above destination is not null
  9. set conent type given from PageEntry into HttpServletResponse
  10. create Filter by Filter.Factory
  11. process Token stream produced by Producer in PageEntry by above Filter
  12. page renderring is finished

This implementation recognizes fail of PageEntryFactory invocations as "404"(Not Found) error. In this case, this invokes HttpServletResponse#sendError() and returns.

Parameters:
request - of this request
response - of this request

init

public void init()
          throws javax.servlet.ServletException
Initialize.

For each values specified at construction time, this does in steps shown below.

  1. examine value is null or not
  2. use specified value if it is not null
  3. otherwise, create object of class specicifed in deployment descriptor
  4. use created one if success
  5. otherwise, use base class

Because PageFactory is abstract class, creation fail of this causes servlet initialization error.

This invokes:

Then, this create PageEntryFactory.

Overrides:
init in class javax.servlet.GenericServlet

destroy

public void destroy()
Finalize.

This invokes:

Overrides:
destroy in class javax.servlet.GenericServlet

doGet

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws javax.servlet.ServletException,
                     java.io.IOException
Respond to "GET" request from client.

This invokes doAction(HttpServletRequest, HttpServletResponse).

Overrides:
doGet in class javax.servlet.http.HttpServlet

doPost

protected void doPost(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
               throws javax.servlet.ServletException,
                      java.io.IOException
Respond to "POST" request from client.

This invokes doAction(HttpServletRequest, HttpServletResponse).

Overrides:
doPost in class javax.servlet.http.HttpServlet

PageMixer API - 3.1