net.sourceforge.stripes.controller
Class StripesRequestWrapper

java.lang.Object
  extended by javax.servlet.ServletRequestWrapper
      extended by javax.servlet.http.HttpServletRequestWrapper
          extended by net.sourceforge.stripes.controller.StripesRequestWrapper
All Implemented Interfaces:
HttpServletRequest, ServletRequest

public class StripesRequestWrapper
extends HttpServletRequestWrapper

HttpServletRequestWrapper that is used to make the file upload functionality transparent. Every request handled by Stripes is wrapped. Those containing multipart form file uploads are parsed and treated differently, while normal requests are silently wrapped and all calls are delegated to the real request.

Author:
Tim Fennell

Field Summary
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
StripesRequestWrapper(HttpServletRequest request)
          Constructor that will, if the POST is multi-part, parse the POST data and make it available through the normal channels.
 
Method Summary
protected  void constructMultipartWrapper(HttpServletRequest request)
          Responsible for constructing the MultipartWrapper object and setting it on to the instance variable 'multipart'.
static StripesRequestWrapper findStripesWrapper(ServletRequest request)
          Looks for the StripesRequesetWrapper for the specific request and returns it.
 Enumeration<String> getFileParameterNames()
          Returns the names of request parameters that represent files being uploaded by the user.
 FileBean getFileParameterValue(String name)
          Returns a FileBean representing an uploaded file with the form field name = "name".
 Locale getLocale()
          Provides access to the Locale being used to process the request.
 Enumeration<Locale> getLocales()
          Returns a single element enumeration containing the selected Locale for this request.
 String getParameter(String name)
          Retrieves the first value of the specified parameter from the request.
 net.sourceforge.stripes.controller.MergedParameterMap getParameterMap()
          If the request is a clean URL, then extract the parameters from the URI and merge with the parameters from the query string and/or request body.
 Enumeration<String> getParameterNames()
          Fetches just the names of regular parameters and does not include file upload parameters.
 String[] getParameterValues(String name)
          Returns all values sent in the request for a given parameter name.
 boolean isMultipart()
          Returns true if this request is wrapping a multipart request, false otherwise.
 void popUriParameters()
          Restore the URI parameters to the state they were in before the previous call to pushUriParameters(HttpServletRequestWrapper).
 void pushUriParameters(HttpServletRequestWrapper request)
          Extract new URI parameters from the URI of the given request and merge them with the previous URI parameters.
protected  void setLocale(Locale locale)
          Used by the dispatcher to set the Locale chosen by the configured LocalePicker.
 
Methods inherited from class javax.servlet.http.HttpServletRequestWrapper
getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getIntHeader, getMethod, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isUserInRole
 
Methods inherited from class javax.servlet.ServletRequestWrapper
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocalName, getLocalPort, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding, setRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocalName, getLocalPort, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
 

Constructor Detail

StripesRequestWrapper

public StripesRequestWrapper(HttpServletRequest request)
                      throws StripesServletException
Constructor that will, if the POST is multi-part, parse the POST data and make it available through the normal channels. If the request is not a multi-part post then it is just wrapped and the behaviour is unchanged.

Parameters:
request - the HttpServletRequest to wrap this is not a file size limit, but a post size limit.
Throws:
FileUploadLimitExceededException - if the total post size is larger than the limit
StripesServletException - if any other error occurs constructing the wrapper
Method Detail

findStripesWrapper

public static StripesRequestWrapper findStripesWrapper(ServletRequest request)
Looks for the StripesRequesetWrapper for the specific request and returns it. This is done by checking to see if the request is a StripesRequestWrapper, and if not, successively unwrapping the request until the StripesRequestWrapper is found.

Parameters:
request - the ServletRequest that is wrapped by a StripesRequestWrapper
Returns:
the StripesRequestWrapper that is wrapping the supplied request
Throws:
IllegalStateException - if the request is not wrapped by Stripes

constructMultipartWrapper

protected void constructMultipartWrapper(HttpServletRequest request)
                                  throws StripesServletException
Responsible for constructing the MultipartWrapper object and setting it on to the instance variable 'multipart'.

Parameters:
request - the HttpServletRequest to wrap this is not a file size limit, but a post size limit.
Throws:
StripesServletException - if any other error occurs constructing the wrapper

isMultipart

public boolean isMultipart()
Returns true if this request is wrapping a multipart request, false otherwise.


getParameterNames

public Enumeration<String> getParameterNames()
Fetches just the names of regular parameters and does not include file upload parameters. If the request is multipart then the information is sourced from the parsed multipart object otherwise it is just pulled out of the request in the usual manner.

Specified by:
getParameterNames in interface ServletRequest
Overrides:
getParameterNames in class ServletRequestWrapper

getParameterValues

public String[] getParameterValues(String name)
Returns all values sent in the request for a given parameter name. If the request is multipart then the information is sourced from the parsed multipart object otherwise it is just pulled out of the request in the usual manner. Values are consistent with HttpServletRequest.getParameterValues(String). Values for file uploads cannot be retrieved in this way (though parameters sent along with file uploads can).

Specified by:
getParameterValues in interface ServletRequest
Overrides:
getParameterValues in class ServletRequestWrapper

getParameter

public String getParameter(String name)
Retrieves the first value of the specified parameter from the request. If the parameter was not sent, null will be returned.

Specified by:
getParameter in interface ServletRequest
Overrides:
getParameter in class ServletRequestWrapper

getParameterMap

public net.sourceforge.stripes.controller.MergedParameterMap getParameterMap()
If the request is a clean URL, then extract the parameters from the URI and merge with the parameters from the query string and/or request body.

Specified by:
getParameterMap in interface ServletRequest
Overrides:
getParameterMap in class ServletRequestWrapper

pushUriParameters

public void pushUriParameters(HttpServletRequestWrapper request)
Extract new URI parameters from the URI of the given request and merge them with the previous URI parameters.


popUriParameters

public void popUriParameters()
Restore the URI parameters to the state they were in before the previous call to pushUriParameters(HttpServletRequestWrapper).


getLocale

public Locale getLocale()
Provides access to the Locale being used to process the request.

Specified by:
getLocale in interface ServletRequest
Overrides:
getLocale in class ServletRequestWrapper
Returns:
a Locale object representing the chosen locale for the request.
See Also:
LocalePicker

getLocales

public Enumeration<Locale> getLocales()
Returns a single element enumeration containing the selected Locale for this request.

Specified by:
getLocales in interface ServletRequest
Overrides:
getLocales in class ServletRequestWrapper
See Also:
LocalePicker

setLocale

protected void setLocale(Locale locale)
Used by the dispatcher to set the Locale chosen by the configured LocalePicker.


getFileParameterNames

public Enumeration<String> getFileParameterNames()
Returns the names of request parameters that represent files being uploaded by the user. If no file upload parameters are submitted returns an empty enumeration.


getFileParameterValue

public FileBean getFileParameterValue(String name)
Returns a FileBean representing an uploaded file with the form field name = "name". If the form field was present in the request, but no file was uploaded, this method will return null.

Parameters:
name - the form field name of type file
Returns:
a FileBean if a file was actually submitted by the user, otherwise null


? Copyright 2005-2006, Stripes Development Team.