toolbox.web
Class BaseWebAction

Package class diagram package BaseWebAction
java.lang.Object
  extended by toolbox.web.BaseWebAction
Direct Known Subclasses:
AbstractStringWebAction, AbstractXMLWebAction, Dir2WSILAction, InvalidateSessionAction, WSILAction

public class BaseWebAction
extends java.lang.Object

Base class that may be extended when implementing the WebAction interface.

This class provides an implementation of the create() method and provides access to the action configuration properties.


Constructor Summary
protected BaseWebAction()
          protected constructor.
 
Method Summary
 void create(java.lang.String name, Controller controller, javax.servlet.ServletContext context)
          A default implementation of the create() method specified in the WebAction interface.
protected  void dispatch(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.ServletContext context, java.lang.String template)
          Dispatches the given request and response to the given template.
protected  org.w3c.dom.Document getBodyAsDocument(javax.servlet.http.HttpServletRequest request)
          Convenience method to return the given HTTP request's body as an XML Document instance.
protected  java.lang.String getBodyAsString(javax.servlet.http.HttpServletRequest request)
          Convenience method to return the given HTTP request body as a String instance.
protected  java.lang.String getDisplayTemplate()
          Returns the location of the display template.
protected  java.lang.String getFailureTemplate()
          Returns the location of the failure template.
protected  javax.servlet.ServletContext getForeignContext(java.lang.String foreignContext, javax.servlet.ServletContext context)
          Return the foreign context represented by the given string.
protected  java.lang.String getGlobalProperty(java.lang.String name)
          Return the named global configuration property.
protected  java.lang.String getMessage()
          Returns the default display message
protected  java.lang.String getName()
          Return the name of this action.
protected  java.util.Map getProperties()
          Return configuration properties as a Map.
protected  java.lang.String getProperty(java.lang.String name)
          Return the named configuration property.
protected  java.lang.String getResource()
          Return the name of the resource configured for this action.
protected  java.util.ResourceBundle getResourceBundle(java.util.Locale locale)
          Return the resource bundle configured for this action.
protected  java.lang.String getResourceString(java.util.ResourceBundle bundle, java.lang.String key, java.lang.Object[] args)
          Return a resource string from the given bundle and format the string using the array of parameters provided.
protected  java.lang.String getResourceString(java.lang.String key)
          Return a resource string from the bundle configured for this action
protected  java.lang.String getResourceString(java.lang.String key, java.util.Locale locale)
          Return a resource string from the bundle configured for this action
protected  java.lang.String getResourceString(java.lang.String key, java.lang.Object[] args)
          Return a resource string from the bundle configured for this action and format the string using the List of parameters provided.
protected  java.lang.String getResourceString(java.lang.String key, java.lang.Object[] args, java.util.Locale locale)
          Return a resource string from the bundle configured for this action and format the string using the List of parameters provided.
protected  java.lang.String getSuccessTemplate()
          Returns the location of the success template.
protected  java.lang.String getTemplate(java.lang.String name)
          Return the location of the named template.
protected  Validator getValidator()
          Returns the validator instance for this action.
protected  void logConfig(java.lang.String msg)
          Log a config message.
protected  void logFine(java.lang.String msg)
          Log a fine message.
protected  void logFiner(java.lang.String msg)
          Log a finer message.
protected  void logFinest(java.lang.String msg)
          Log a finest message.
protected  void logInfo(java.lang.String msg)
          Log an info message.
protected  void logSevere(java.lang.String msg, java.lang.Throwable ex)
          Log a severe message.
protected  void logWarning(java.lang.String msg, java.lang.Throwable ex)
          Log a warning message.
protected  void redirect(javax.servlet.http.HttpServletResponse response, java.lang.String redirect)
          Perform a redirect to the given target URL.
protected  java.util.List split(java.util.List list, int pageSize)
          Split the given list into equal sub lists and return a new list containing all the created sub lists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseWebAction

protected BaseWebAction()
protected constructor.

Method Detail

create

public void create(java.lang.String name,
                   Controller controller,
                   javax.servlet.ServletContext context)
            throws ConfException
A default implementation of the create() method specified in the WebAction interface.

This method sets the relevant template, message and name parameters for the implemented action.

Parameters:
name - Action name.
controller - Controller that created this action.
context - Current servlet context.
Throws:
ConfException - if the action cannot be created.

getValidator

protected Validator getValidator()
Returns the validator instance for this action.

Returns:
Validator instance.

getName

protected java.lang.String getName()
Return the name of this action.

Returns:
String containing the name of this action.

getDisplayTemplate

protected java.lang.String getDisplayTemplate()
Returns the location of the display template. This is a convenience method that will try and find a template that was configured with the name "display".

Returns:
String containing the location of the display template.

getSuccessTemplate

protected java.lang.String getSuccessTemplate()
Returns the location of the success template. This is a convenience method that will try and find a template that was configured with the name "success".

Returns:
String containing the location of the display template.

getFailureTemplate

protected java.lang.String getFailureTemplate()
Returns the location of the failure template. This is a convenience method that will try and find a template that was configured with the name "failure".

Returns:
String containing the location of the display template.

getTemplate

protected java.lang.String getTemplate(java.lang.String name)
Return the location of the named template.

Parameters:
name - String containing a template name.
Returns:
String containing the location of the named template.

getMessage

protected java.lang.String getMessage()
Returns the default display message

Returns:
String containing the default display message.

getResource

protected java.lang.String getResource()
Return the name of the resource configured for this action.

Returns:
String containing the name of the resource configured for for this action.

getProperty

protected java.lang.String getProperty(java.lang.String name)
Return the named configuration property.

Parameters:
name - String containing the name of the poperty to return.
Returns:
String containing the value of the property or null if it does not exist.

getProperties

protected java.util.Map getProperties()
Return configuration properties as a Map.

Returns:
Map containing all the action configuration properties.

getGlobalProperty

protected java.lang.String getGlobalProperty(java.lang.String name)
Return the named global configuration property.

Parameters:
name - String containing the name of the global poperty to return.
Returns:
String containing the value of the global property or null if it does not exist.

getResourceBundle

protected java.util.ResourceBundle getResourceBundle(java.util.Locale locale)
                                              throws javax.servlet.ServletException
Return the resource bundle configured for this action.

Parameters:
locale - Attempt to return a resource for this locale.
Returns:
ResourceBundle
Throws:
javax.servlet.ServletException

getResourceString

protected java.lang.String getResourceString(java.lang.String key,
                                             java.util.Locale locale)
                                      throws javax.servlet.ServletException
Return a resource string from the bundle configured for this action

Parameters:
key - String key to use for resource lookup.
locale - The current request locale.
Throws:
javax.servlet.ServletException - if the resource cannot be found.

getResourceString

protected java.lang.String getResourceString(java.lang.String key)
                                      throws javax.servlet.ServletException
Return a resource string from the bundle configured for this action

Parameters:
key - String key to use for resource lookup.
Throws:
javax.servlet.ServletException - if the resource cannot be found.

getResourceString

protected java.lang.String getResourceString(java.lang.String key,
                                             java.lang.Object[] args,
                                             java.util.Locale locale)
                                      throws javax.servlet.ServletException
Return a resource string from the bundle configured for this action and format the string using the List of parameters provided.

Parameters:
key - String key use for resource lookup.
args - Object array containing arguments.
locale - The current request locale.
Throws:
javax.servlet.ServletException - if the resource cannot be found.

getResourceString

protected java.lang.String getResourceString(java.lang.String key,
                                             java.lang.Object[] args)
                                      throws javax.servlet.ServletException
Return a resource string from the bundle configured for this action and format the string using the List of parameters provided.

Parameters:
key - String key use for resource lookup.
args - Object array containing arguments.
Throws:
javax.servlet.ServletException - if the resource cannot be found.

getResourceString

protected java.lang.String getResourceString(java.util.ResourceBundle bundle,
                                             java.lang.String key,
                                             java.lang.Object[] args)
                                      throws javax.servlet.ServletException
Return a resource string from the given bundle and format the string using the array of parameters provided.

Parameters:
bundle - ResourceBundle to use.
key - String key use for resource lookup.
args - Object array containing arguments.
Throws:
javax.servlet.ServletException - if the resource cannot be found.

getBodyAsString

protected java.lang.String getBodyAsString(javax.servlet.http.HttpServletRequest request)
                                    throws java.io.IOException
Convenience method to return the given HTTP request body as a String instance.

Parameters:
request - Convert this request's body into a String.
Returns:
String instance containing the request body.
Throws:
java.io.IOException - if the body cannot be read.

getBodyAsDocument

protected org.w3c.dom.Document getBodyAsDocument(javax.servlet.http.HttpServletRequest request)
                                          throws java.io.IOException
Convenience method to return the given HTTP request's body as an XML Document instance.

Parameters:
request - Convert this request's body into a Document.
Returns:
Document instance containing the request body.
Throws:
java.io.IOException - if the body cannot be read.

split

protected java.util.List split(java.util.List list,
                               int pageSize)
Split the given list into equal sub lists and return a new list containing all the created sub lists.

Parameters:
list - The List that must be split.
pageSize - The number of entries per sub list.
Returns:
List instance containing all the sub lists.

logFinest

protected void logFinest(java.lang.String msg)
Log a finest message.

Parameters:
msg - String containing message to log.

logFiner

protected void logFiner(java.lang.String msg)
Log a finer message.

Parameters:
msg - String containing message to log.

logFine

protected void logFine(java.lang.String msg)
Log a fine message.

Parameters:
msg - String containing message to log.

logConfig

protected void logConfig(java.lang.String msg)
Log a config message.

Parameters:
msg - String containing message to log.

logInfo

protected void logInfo(java.lang.String msg)
Log an info message.

Parameters:
msg - String containing message to log.

logWarning

protected void logWarning(java.lang.String msg,
                          java.lang.Throwable ex)
Log a warning message.

Parameters:
msg - String containing message to log.
ex - Optional throwable to include in the log.

logSevere

protected void logSevere(java.lang.String msg,
                         java.lang.Throwable ex)
Log a severe message.

Parameters:
msg - String containing message to log.
ex - Optional throwable to include in the log.

redirect

protected void redirect(javax.servlet.http.HttpServletResponse response,
                        java.lang.String redirect)
                 throws java.io.IOException
Perform a redirect to the given target URL.

Parameters:
response - Servlet response.
redirect - String containing the redirect URL.
Throws:
java.io.IOException

dispatch

protected void dispatch(javax.servlet.ServletRequest request,
                        javax.servlet.ServletResponse response,
                        javax.servlet.ServletContext context,
                        java.lang.String template)
                 throws javax.servlet.ServletException,
                        java.io.IOException
Dispatches the given request and response to the given template.

Parameters:
request - Servlet request.
response - Servlet response.
context - Servlet context.
template - Target template.
Throws:
javax.servlet.ServletException
java.io.IOException

getForeignContext

protected javax.servlet.ServletContext getForeignContext(java.lang.String foreignContext,
                                                         javax.servlet.ServletContext context)
Return the foreign context represented by the given string. The context must exist in the same server instance as the calling context.

Parameters:
foreignContext - String representing the foreing context.
context - Current context instance.
Returns:
ServletContext instance represented by the given string.