PAJES 3.0.21

org.pajes.servlet
Class PajeServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.pajes.servlet.PajeServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
BlankPajeServlet, DataAccessPajeServlet, StaticPajeServlet, TraceServlet

public abstract class PajeServlet
extends javax.servlet.http.HttpServlet

Base class for all servlets that utilise the PAJES servlet framework, to provide automatic decoding of encrypted query string parameters, and transparent handling of multi-part requests (file uploads).

This class does NOT authenticate access to resources. If authentication is required, sub-class AuthenticatedPajeServlet instead, or use the authentication services of the servlet container.

As with "standard" servlets, sub-classes should implement the doGet or doPost method.

See Also:
Serialized Form

Constructor Summary
PajeServlet()
           
 
Method Summary
 Paje createPaje(javax.servlet.http.HttpServletRequest request)
          Creates a Paje from the PajeFactory associated with this servlet.
 Paje createPaje(java.lang.String[] keys, java.lang.String[] arguments, javax.servlet.http.HttpServletRequest request)
          Creates a Paje from the PajeFactory associated with this servlet.
 Paje createPaje(java.lang.String key, java.lang.String[] arguments, javax.servlet.http.HttpServletRequest request)
          Creates a Paje from the PajeFactory associated with this servlet.
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Provides an automatic redirect to the doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method.
protected  void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Provides an automatic redirect to the doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method.
static java.lang.String getAbsoluteHREF(javax.servlet.http.HttpServletRequest request, java.lang.String relativeHREF)
          Returns a concatenated string of the following values: getBaseHREF(javax.servlet.http.HttpServletRequest) the relativeHREF parameter If the relativeHREF parameter startes with a '/', it will be removed before being concatenated to the base URL.
static java.lang.String getBaseHREF(javax.servlet.http.HttpServletRequest request)
          Returns a concatenated string of the following request values: getScheme() "://" getServerName() ":" getServerPort() getContextPath() '/'
 int getMaxFileUploadSize()
          Returns the maximum number of bytes that can be uploaded to this servlet.
 PajeFactory getPajeFactory()
          Returns the PajeFactory that will be used by this servlet to generate Paje instances.
 java.net.URL getResource(java.lang.String resource, javax.servlet.http.HttpServletRequest request)
          Convenience method to return a URL to a localized resource.
 UploadedFile getUploadedFile(javax.servlet.http.HttpServletRequest request, java.lang.String sourceFileName)
          Convenience method to return the specified uploaded file instance.
 java.util.Enumeration<java.lang.String> getUploadedFileNames(javax.servlet.http.HttpServletRequest request)
          Convenience method to return an Enumeration of String objects containing the names of the files uploaded in this request.
protected  void handleException(java.lang.Throwable throwable, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Deprecated. Removed in Release 2.1.0 - no longer called and no replacement.
 void init(javax.servlet.ServletConfig config)
          Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
 void log(java.lang.String msg)
          Writes the specified message to a servlet log file, prepended by the servlet's name.
 void log(java.lang.String message, java.lang.Throwable t)
          Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file, prepended by the servlet's name.
protected  void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Over-rides the HttpServlet service method to provide access to PAJES facilities.
static void setInputFieldsFromRequestAttributes(javax.servlet.http.HttpServletRequest request, Container container, java.lang.String prefix)
          Convenience method to assign request attribute values to Input fields where the name attribute of the Input field matches the name of the request attribute.
static void setInputFieldsFromRequestParameters(javax.servlet.http.HttpServletRequest request, Container container)
          Convenience method to assign request parameter values to Input fields where the name attribute of the Input field matches the name of the request parameter.
 void setMaxFileUploadSize(int bytes)
          Sets the maximum number of bytes that can be uploaded to this servlet.
protected  void setPajeFactory(PajeFactory factory)
          Sets the PajeFactory that will be used by this servlet to generate Paje instances.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PajeServlet

public PajeServlet()
Method Detail

getAbsoluteHREF

public static java.lang.String getAbsoluteHREF(javax.servlet.http.HttpServletRequest request,
                                               java.lang.String relativeHREF)
Returns a concatenated string of the following values: If the relativeHREF parameter startes with a '/', it will be removed before being concatenated to the base URL.

Parameters:
request - the object that contains the request the client made of the servlet.
relativeHREF - the realtive address of the URL,
Returns:
a String specifying the absolute URL of a resource in the context.

getBaseHREF

public static java.lang.String getBaseHREF(javax.servlet.http.HttpServletRequest request)
Returns a concatenated string of the following request values:

Parameters:
request - the object that contains the request the client made of the servlet.
Returns:
a String specifying the base portion of the request URL that indicates the scheme, server, port and context of the request.

setInputFieldsFromRequestAttributes

public static void setInputFieldsFromRequestAttributes(javax.servlet.http.HttpServletRequest request,
                                                       Container container,
                                                       java.lang.String prefix)
Convenience method to assign request attribute values to Input fields where the name attribute of the Input field matches the name of the request attribute. Values will only be assigned if the names and number of fields and values match exactly.

Parameters:
request - the object that contains the request the client made of the servlet.
container - the Container sub-class which contains the Input fields. It is most efficient to pass in the lowest level container possible (i.e. the Form instance) rather than the Paje instance.
prefix - the String prefix assigned to attribute names.

setInputFieldsFromRequestParameters

public static void setInputFieldsFromRequestParameters(javax.servlet.http.HttpServletRequest request,
                                                       Container container)
Convenience method to assign request parameter values to Input fields where the name attribute of the Input field matches the name of the request parameter. Values will only be assigned if the names and number of fields and values match exactly.

Parameters:
request - the object that contains the request the client made of the servlet.
container - the Container sub-class which contains the Input fields. It is most effecient to pass in the lowest level container possible (i.e. the Form instance) rather than the Paje instance.

createPaje

public Paje createPaje(javax.servlet.http.HttpServletRequest request)
                throws java.lang.IllegalStateException,
                       java.io.IOException
Creates a Paje from the PajeFactory associated with this servlet.

Parameters:
request - the request object from which the preferred locales will be obtained.
Returns:
the most preferred available localized version of the resource located at the named path, or the base resource if no available localized version exists, or null if there is no resource at that path.
Throws:
java.lang.IllegalStateException - if the PajeFactory has not been defined.
java.io.IOException - if an IO exception occurs.
See Also:
setPajeFactory(org.pajes.html.PajeFactory), PajeFactory.create(javax.servlet.http.HttpServletRequest)

createPaje

public Paje createPaje(java.lang.String key,
                       java.lang.String[] arguments,
                       javax.servlet.http.HttpServletRequest request)
                throws java.lang.IllegalStateException,
                       java.io.IOException
Creates a Paje from the PajeFactory associated with this servlet.

Parameters:
key - the key which will uniquely identify this source file.
arguments - the array of arguments that will be substituted into the resource path pattern to give a path to an alternate source file.
request - the request object from which the preferred locales will be obtained.
Returns:
the most preferred available localized version of the resource located at the named path, or the base resource if no available localized version exists, or null if there is no resource at any path.
Throws:
java.lang.IllegalStateException - if the PajeFactory has not been defined.
java.io.IOException - if an IO exception occurs.
See Also:
setPajeFactory(org.pajes.html.PajeFactory), PajeFactory.create(java.lang.String, java.lang.String[], javax.servlet.http.HttpServletRequest)

createPaje

public Paje createPaje(java.lang.String[] keys,
                       java.lang.String[] arguments,
                       javax.servlet.http.HttpServletRequest request)
                throws java.lang.IllegalStateException,
                       java.io.IOException
Creates a Paje from the PajeFactory associated with this servlet.

Parameters:
keys - the array of keys which will identify the sequence in which the source file resources will be searched in order to locate the most appropriate match.
arguments - the array of arguments that will be substituted into the resource path pattern to give a path to an alternate source file.
request - the request object from which the preferred locales will be obtained.
Returns:
the most preferred available localized version of the resource located at the named path, or the base resource if no available localized version exists, or the default document if there is no matching resource at any of the paths.
Throws:
java.lang.IllegalStateException - if the PajeFactory has not been defined.
java.io.IOException - if an IO exception occurs.
See Also:
setPajeFactory(org.pajes.html.PajeFactory), PajeFactory.create(java.lang.String[], java.lang.String[], javax.servlet.http.HttpServletRequest)

getMaxFileUploadSize

public int getMaxFileUploadSize()
Returns the maximum number of bytes that can be uploaded to this servlet. The default is 1,048,510 (1 Megabyte).

Returns:
the maximum number of bytes that can be uploaded.
See Also:
setMaxFileUploadSize(int)

getPajeFactory

public PajeFactory getPajeFactory()
Returns the PajeFactory that will be used by this servlet to generate Paje instances.

Returns:
the factory that will be used by this servlet to generate Pajes.
See Also:
setPajeFactory(org.pajes.html.PajeFactory)

getResource

public java.net.URL getResource(java.lang.String resource,
                                javax.servlet.http.HttpServletRequest request)
                         throws java.net.MalformedURLException
Convenience method to return a URL to a localized resource. If the resource begins with a "/", it is interpreted as relative to the current context root and ServletContext.getResource will be used to retrieve the URL, otherwise the request will be passed to the ClassLoader to search its own and the system class path.

Processing takes the following steps:

  1. Separate the [file name] portion and the [file type] portion of the requested resource, using the final period (".") in the path as the delimiter.
  2. For each locale specified on the request, and in preference order:
    1. Determine if a resource exists with a name constructed as:
             [file name]_language_country_variant.[file type]
       
      If such a resource exists, return the URL and stop further processing.
    2. Determine if a resource exists with a name constructed as:
             [file name]_language_country.[file type]
       
      If such a resource exists, return the URL and stop further processing.
    3. Determine if a resource exists with a name constructed as:
             [file name]_language.[file type]
       
      If such a resource exists, return the URL and stop further processing.
    4. Determine if a resource exists with a name constructed as:
             [file name].[file type]
       
      If such a resource exists, return the URL and stop further processing.
  3. If no localized version of the resource exists, determine if the base resource exists, and if such a resource exists, return the URL and stop further processing.
  4. Return null.

Note that if internationalisation is turned off, this method will not attempt to locate a localised resource.

Parameters:
resource - a String identifying the resource.
request - the request object from which the list of preferred locales is determined.
Returns:
the localized resource located at the named path, or null if there is no resource at that path
Throws:
java.net.MalformedURLException - if a malformed URL is encountered

getUploadedFile

public UploadedFile getUploadedFile(javax.servlet.http.HttpServletRequest request,
                                    java.lang.String sourceFileName)
Convenience method to return the specified uploaded file instance.

Parameters:
request - the object that contains the request the client made of the servlet.
sourceFileName - the file name of the uploaded file to be retrieved.
Returns:
the uploaded file definition.
See Also:
getUploadedFileNames(javax.servlet.http.HttpServletRequest)

getUploadedFileNames

public java.util.Enumeration<java.lang.String> getUploadedFileNames(javax.servlet.http.HttpServletRequest request)
Convenience method to return an Enumeration of String objects containing the names of the files uploaded in this request. If the request has no uploaded files, returns an empty Enumeration .

Parameters:
request - the object that contains the request the client made of the servlet.
Returns:
an Enumeration of String objects, each String containing the source file name of an uploaded file; or an empty Enumeration if the request has no uploaded files.
See Also:
getUploadedFile(javax.servlet.http.HttpServletRequest, java.lang.String)

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Called by the servlet container to indicate to a servlet that the servlet is being placed into service.

This implementation stores the ServletConfig object it receives from the servlet container for later use. When overriding this form of the method, call super.init(config).

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
config - the ServletConfig object that contains configutation information for this servlet
Throws:
javax.servlet.ServletException - if an exception occurs that interrupts the servlet's normal operation

log

public void log(java.lang.String msg)
Writes the specified message to a servlet log file, prepended by the servlet's name.

Overrides:
log in class javax.servlet.GenericServlet
Parameters:
msg - a String specifying the message to be written to the log file

log

public void log(java.lang.String message,
                java.lang.Throwable t)
Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file, prepended by the servlet's name.

Overrides:
log in class javax.servlet.GenericServlet
Parameters:
message - a String that describes the error or exception
t - the java.lang.Throwable error or exception

setMaxFileUploadSize

public void setMaxFileUploadSize(int bytes)
Sets the maximum number of bytes that can be uploaded to this servlet.

The default value is determined from the web application deployment descriptor. To set the default value, create a <context-param> with a <param-name> of org.pajes.servlet.Browser.maxFileUploadSize , and a <param-value> containing the maximum number of bytes. For example:

    <context-param>
        <param-name>org.pajes.servlet.Browser.maxFileUploadSize</param-name>
        <param-value>1048510</param-value>
    </context-param>
 

If the <context-param> does not exist, or the <param-value> does not contain a valid number, the default value of 1048510 will be used.

Parameters:
bytes - the maximum number of bytes that can be uploaded.

doGet

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws javax.servlet.ServletException,
                     java.io.IOException
Provides an automatic redirect to the doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - the request object.
response - the response object.
Throws:
javax.servlet.ServletException - if the request could not be handled.
java.io.IOException - if an input or output error is detected when the servlet handles the request.

doPost

protected void doPost(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
               throws javax.servlet.ServletException,
                      java.io.IOException
Provides an automatic redirect to the doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
request - the request object.
response - the response object.
Throws:
javax.servlet.ServletException - if the request could not be handled.
java.io.IOException - if an input or output error is detected when the servlet handles the request.

handleException

@Deprecated
protected void handleException(java.lang.Throwable throwable,
                                          javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response)
                        throws java.io.IOException,
                               javax.servlet.ServletException
Deprecated. Removed in Release 2.1.0 - no longer called and no replacement.

Deprecated.

Parameters:
throwable - the throwable instance caught by the service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method.
request - the object that contains the request the client made of the servlet.
response - the object that contains the response the servlet returns to the client.
Throws:
java.io.IOException - if an input or output error is detected when the servlet handles the request.
javax.servlet.ServletException - if the request could not be handled.

service

protected void service(javax.servlet.http.HttpServletRequest request,
                       javax.servlet.http.HttpServletResponse response)
                throws java.io.IOException,
                       javax.servlet.ServletException
Over-rides the HttpServlet service method to provide access to PAJES facilities.

Overrides:
service in class javax.servlet.http.HttpServlet
Parameters:
request - the object that contains the request the client made of the servlet.
response - the object that contains the response the servlet returns to the client.
Throws:
java.io.IOException - if an input or output error is detected when the servlet handles the request.
javax.servlet.ServletException - if the request could not be handled.

setPajeFactory

protected void setPajeFactory(PajeFactory factory)
Sets the PajeFactory that will be used by this servlet to generate Paje instances.

Parameters:
factory - the factory that will be used by this servlet to generate Pajes.
See Also:
createPaje(javax.servlet.http.HttpServletRequest), createPaje(java.lang.String, java.lang.String[], javax.servlet.http.HttpServletRequest), createPaje(java.lang.String[], java.lang.String[], javax.servlet.http.HttpServletRequest)

PAJES 3.0.21

Copyright 1998-2007 Viridian Pty Limited. All Rights Reserved.