com.opensymphony.webwork.dispatcher
Class DispatcherUtils

java.lang.Object
  extended by com.opensymphony.webwork.dispatcher.DispatcherUtils

public class DispatcherUtils
extends Object

A utility class whereby FilterDispatcher delegate most of its tasks to. A static singleton that gets initlialized upon the call to it's initalize(ServletContext) method

Version:
$Date: 2007-07-22 11:13:22 +0800 (Sun, 22 Jul 2007) $ $Id: DispatcherUtils.java 2937 2007-07-22 03:13:22Z tm_jee $
Author:
patrick, Rainer Hermanns, tm_jee
See Also:
FilterDispatcher

Nested Class Summary
 class DispatcherUtils.Locator
          Simple accessor for a static method
 
Field Summary
protected  boolean devMode
           
protected  boolean paramsWorkaroundEnabled
           
 
Constructor Summary
protected DispatcherUtils(ServletContext servletContext)
           
 
Method Summary
 void cleanup()
           
 Map createContextMap(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping, ServletContext context)
           
 HashMap createContextMap(Map requestMap, Map parameterMap, Map sessionMap, Map applicationMap, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
          Merges all application and servlet attributes into a single HashMap to represent the entire Action context.
static DispatcherUtils getInstance()
           
static int getMaxSize()
          Returns the maximum upload size allowed for multipart requests (this is configurable).
 String getSaveDir(ServletContext servletContext)
          Returns the path to save uploaded files to (this is configurable).
protected  void init(ServletContext servletContext)
           
static void initialize(ServletContext servletContext)
           
static boolean isPortletSupportActive()
          Returns true, if portlet support is active, false otherwise.
 void prepare(HttpServletRequest request, HttpServletResponse response)
           
 void sendError(HttpServletRequest request, HttpServletResponse response, ServletContext ctx, int code, Exception e)
          Sends an HTTP error response code.
 void serviceAction(HttpServletRequest request, HttpServletResponse response, ServletContext context, ActionMapping mapping)
          Loads the action and executes it.
static void setInstance(DispatcherUtils instance)
           
static void setPortletSupportActive(boolean portletSupportActive)
          Set the flag that portlet support is active or not.
 HttpServletRequest wrapRequest(HttpServletRequest request, ServletContext servletContext)
          Wraps and returns the given response or returns the original response object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

devMode

protected boolean devMode

paramsWorkaroundEnabled

protected boolean paramsWorkaroundEnabled
Constructor Detail

DispatcherUtils

protected DispatcherUtils(ServletContext servletContext)
Method Detail

initialize

public static void initialize(ServletContext servletContext)

getInstance

public static DispatcherUtils getInstance()

setInstance

public static void setInstance(DispatcherUtils instance)

cleanup

public void cleanup()

init

protected void init(ServletContext servletContext)

serviceAction

public void serviceAction(HttpServletRequest request,
                          HttpServletResponse response,
                          ServletContext context,
                          ActionMapping mapping)
                   throws ServletException
Loads the action and executes it. This method first creates the action context from the given parameters then loads an ActionProxy from the given action name and namespace. After that, the action is executed and output channels throught the response object. Actions not found are sent back to the user via the sendError(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletContext, int, java.lang.Exception) method, using the 404 return code. All other errors are reported by throwing a ServletException.

Parameters:
request - the HttpServletRequest object
response - the HttpServletResponse object
mapping - the action mapping object
Throws:
ServletException - when an unknown error occurs (not a 404, but typically something that would end up as a 5xx by the servlet container)

createContextMap

public Map createContextMap(HttpServletRequest request,
                            HttpServletResponse response,
                            ActionMapping mapping,
                            ServletContext context)

createContextMap

public HashMap createContextMap(Map requestMap,
                                Map parameterMap,
                                Map sessionMap,
                                Map applicationMap,
                                HttpServletRequest request,
                                HttpServletResponse response,
                                ServletContext servletContext)
Merges all application and servlet attributes into a single HashMap to represent the entire Action context.

Parameters:
requestMap - a Map of all request attributes.
parameterMap - a Map of all request parameters.
sessionMap - a Map of all session attributes.
applicationMap - a Map of all servlet context attributes.
request - the HttpServletRequest object.
response - the HttpServletResponse object.
servletContext - the ServletContext object.
Returns:
a HashMap representing the Action context.

getMaxSize

public static int getMaxSize()
Returns the maximum upload size allowed for multipart requests (this is configurable).

Returns:
the maximum upload size allowed for multipart requests

getSaveDir

public String getSaveDir(ServletContext servletContext)
Returns the path to save uploaded files to (this is configurable).

Returns:
the path to save uploaded files to

prepare

public void prepare(HttpServletRequest request,
                    HttpServletResponse response)

wrapRequest

public HttpServletRequest wrapRequest(HttpServletRequest request,
                                      ServletContext servletContext)
                               throws IOException
Wraps and returns the given response or returns the original response object. This is used to transparently handle multipart data as a wrapped class around the given request. Override this method to handle multipart requests in a special way or to handle other types of requests. Note, MultiPartRequestWrapper is flexible - you should look to that first before overriding this method to handle multipart data.

Parameters:
request - the HttpServletRequest object.
Returns:
a wrapped request or original request.
Throws:
IOException
See Also:
MultiPartRequestWrapper

sendError

public void sendError(HttpServletRequest request,
                      HttpServletResponse response,
                      ServletContext ctx,
                      int code,
                      Exception e)
Sends an HTTP error response code.

Parameters:
request - the HttpServletRequest object.
response - the HttpServletResponse object.
code - the HttpServletResponse error code (see HttpServletResponse for possible error codes).
e - the Exception that is reported.

isPortletSupportActive

public static boolean isPortletSupportActive()
Returns true, if portlet support is active, false otherwise.

Returns:
true, if portlet support is active, false otherwise.

setPortletSupportActive

public static void setPortletSupportActive(boolean portletSupportActive)
Set the flag that portlet support is active or not.

Parameters:
portletSupportActive - true or false

WebWork Project Page