net.sourceforge.stripes.controller
Class StripesFilter

java.lang.Object
  extended by net.sourceforge.stripes.controller.StripesFilter
All Implemented Interfaces:
Filter

public class StripesFilter
extends Object
implements Filter

The Stripes filter is used to ensure that all requests coming to a Stripes application are handled in the same way. It detects and wraps any requests that contain multipart/form data, so that they may be treated much like any other request. Also ensures that all downstream components have access to essential configuration and services whether the request goes through the dispatcher, or straight to a JSP.

Author:
Tim Fennell

Field Summary
static String CONFIG_CLASS
          Key used to lookup the name of the Configuration class used to configure Stripes.
 
Constructor Summary
StripesFilter()
           
 
Method Summary
 void destroy()
          Calls the cleanup() method on the log to release resources held by commons logging.
 void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
          Performs the primary work of the filter, including constructing a StripesRequestWrapper to wrap the HttpServletRequest, and using the configured LocalePicker to decide which Locale will be used to process the request.
protected  void flashInbound(HttpServletRequest req)
          Checks to see if there is a flash scope identified by a parameter to the current request, and if there is, retrieves items from the flash scope and moves them back to request attributes.
protected  void flashOutbound(HttpServletRequest req)
          Manages the work that ensures that flash scopes get cleaned up properly when requests go missing.
static Configuration getConfiguration()
          Returns the Configuration that is being used to process the current request.
 Configuration getInstanceConfiguration()
          Returns the configuration for this instance of the StripesFilter for any class that has a reference to the filter.
 void init(FilterConfig filterConfig)
          Performs the necessary initialization for the StripesFilter.
protected  StripesRequestWrapper wrapRequest(HttpServletRequest servletRequest)
          Wraps the HttpServletRequest with a StripesServletRequest.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG_CLASS

public static final String CONFIG_CLASS
Key used to lookup the name of the Configuration class used to configure Stripes.

See Also:
Constant Field Values
Constructor Detail

StripesFilter

public StripesFilter()
Method Detail

init

public void init(FilterConfig filterConfig)
          throws ServletException
Performs the necessary initialization for the StripesFilter. Mainly this involves deciding what configuration class to use, and then instantiating and initializing the chosen Configuration.

Specified by:
init in interface Filter
Throws:
ServletException - thrown if a problem is encountered initializing Stripes

getConfiguration

public static Configuration getConfiguration()
Returns the Configuration that is being used to process the current request.


getInstanceConfiguration

public Configuration getInstanceConfiguration()
Returns the configuration for this instance of the StripesFilter for any class that has a reference to the filter. For normal runtime access to the configuration during a request cycle, call getConfiguration() instead.

Returns:
the Configuration of this instance of the StripesFilter

doFilter

public void doFilter(ServletRequest servletRequest,
                     ServletResponse servletResponse,
                     FilterChain filterChain)
              throws IOException,
                     ServletException
Performs the primary work of the filter, including constructing a StripesRequestWrapper to wrap the HttpServletRequest, and using the configured LocalePicker to decide which Locale will be used to process the request.

Specified by:
doFilter in interface Filter
Throws:
IOException
ServletException

wrapRequest

protected StripesRequestWrapper wrapRequest(HttpServletRequest servletRequest)
                                     throws StripesServletException
Wraps the HttpServletRequest with a StripesServletRequest. This is done to ensure that any form posts that contain file uploads get handled appropriately.

Parameters:
servletRequest - the HttpServletRequest handed to the dispatcher by the container
Returns:
an instance of StripesRequestWrapper, which is an HttpServletRequestWrapper
Throws:
StripesServletException - if the wrapper cannot be constructed

flashInbound

protected void flashInbound(HttpServletRequest req)

Checks to see if there is a flash scope identified by a parameter to the current request, and if there is, retrieves items from the flash scope and moves them back to request attributes.


flashOutbound

protected void flashOutbound(HttpServletRequest req)
Manages the work that ensures that flash scopes get cleaned up properly when requests go missing. Firstly timestamps the current flash scope (if one exists) to record the time that the request exited the container. Then checks all flash scopes to make sure none have been hanging out for more than a minute.


destroy

public void destroy()
Calls the cleanup() method on the log to release resources held by commons logging.

Specified by:
destroy in interface Filter


? Copyright 2005-2006, Stripes Development Team.