com.opensymphony.webwork.dispatcher.multipart
Class MultiPartRequestWrapper

java.lang.Object
  extended byjavax.servlet.ServletRequestWrapper
      extended byjavax.servlet.http.HttpServletRequestWrapper
          extended bycom.opensymphony.webwork.dispatcher.multipart.MultiPartRequestWrapper
All Implemented Interfaces:
HttpServletRequest, ServletRequest

public class MultiPartRequestWrapper
extends HttpServletRequestWrapper

Parses a multipart request and provides a wrapper around the request. The parsing implementation used depends on the webwork.multipart.parser setting. It should be set to a class which extends MultiPartRequest.

Webwork ships with three implementations, PellMultiPartRequest, and CosMultiPartRequest and JakartaMultiPartRequest. The Pell implementation is the default. The webwork.multipart.parser property should be set to pell for the Pell implementation and cos for the Jason Hunter implementation.

The files are uploaded when the object is instantiated. If there are any errors they are logged using addError(String). An action handling a multipart form should first check hasErrors() before doing any other processing.

Author:
Matt Baldree

Field Summary
protected static org.apache.commons.logging.Log log
           
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
MultiPartRequestWrapper(HttpServletRequest request, String saveDir, int maxSize)
          Instantiates the appropriate MultiPartRequest parser implementation and processes the data.
 
Method Summary
protected  void addError(String anErrorMessage)
          Adds an error message.
 String getContentType(String fieldName)
          Deprecated. use getContentTypes(String) instead
 String[] getContentTypes(String name)
          Get an array of content encoding for the specified input field name or null if no content type was specified.
 Collection getErrors()
          Returns a collection of any errors generated when parsing the multipart request.
 File getFile(String fieldName)
          Deprecated. use getFiles(String) instead
 Enumeration getFileNames()
          Deprecated. use getFileParameterNames() instead
 String[] getFileNames(String fieldName)
          Get a String array of the file names for uploaded files
 Enumeration getFileParameterNames()
          Get an enumeration of the parameter names for uploaded files
 File[] getFiles(String fieldName)
          Get a File[] for the given input field name.
 String getFilesystemName(String fieldName)
          Deprecated. use getFileSystemNames(String) instead
 String[] getFileSystemNames(String fieldName)
          Get the filename(s) of the file(s) uploaded for the given input field name.
 String getParameter(String name)
           
 Map getParameterMap()
           
 Enumeration getParameterNames()
           
 String[] getParameterValues(String name)
           
 boolean hasErrors()
          Returns true if any errors occured when parsing the HTTP multipart request, false otherwise.
protected  Enumeration mergeParams(Enumeration params1, Enumeration params2)
          Merges 2 enumeration of parameters as one.
 
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, getLocale, getLocales, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, 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, getLocale, getLocales, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
 

Field Detail

log

protected static final org.apache.commons.logging.Log log
Constructor Detail

MultiPartRequestWrapper

public MultiPartRequestWrapper(HttpServletRequest request,
                               String saveDir,
                               int maxSize)
                        throws IOException
Instantiates the appropriate MultiPartRequest parser implementation and processes the data.

Parameters:
request - the servlet request object
saveDir - directory to save the file(s) to
maxSize - maximum file size allowed
Method Detail

getFileNames

public Enumeration getFileNames()
Deprecated. use getFileParameterNames() instead


getFileParameterNames

public Enumeration getFileParameterNames()
Get an enumeration of the parameter names for uploaded files

Returns:
enumeration of parameter names for uploaded files

getContentType

public String getContentType(String fieldName)
Deprecated. use getContentTypes(String) instead


getContentTypes

public String[] getContentTypes(String name)
Get an array of content encoding for the specified input field name or null if no content type was specified.

Parameters:
name - input field name
Returns:
an array of content encoding for the specified input field name

getFile

public File getFile(String fieldName)
Deprecated. use getFiles(String) instead


getFiles

public File[] getFiles(String fieldName)
Get a File[] for the given input field name.

Parameters:
fieldName - input field name
Returns:
a File[] object for files associated with the specified input field name

getFileNames

public String[] getFileNames(String fieldName)
Get a String array of the file names for uploaded files

Returns:
a String[] of file names for uploaded files

getFilesystemName

public String getFilesystemName(String fieldName)
Deprecated. use getFileSystemNames(String) instead


getFileSystemNames

public String[] getFileSystemNames(String fieldName)
Get the filename(s) of the file(s) uploaded for the given input field name. Returns null if the file is not found.

Parameters:
fieldName - input field name
Returns:
the filename(s) of the file(s) uploaded for the given input field name or null if name not found.

getParameter

public String getParameter(String name)
See Also:
ServletRequest.getParameter(String)

getParameterMap

public Map getParameterMap()
See Also:
ServletRequest.getParameterMap()

getParameterNames

public Enumeration getParameterNames()
See Also:
ServletRequest.getParameterNames()

getParameterValues

public String[] getParameterValues(String name)
See Also:
ServletRequest.getParameterValues(String)

hasErrors

public boolean hasErrors()
Returns true if any errors occured when parsing the HTTP multipart request, false otherwise.

Returns:
true if any errors occured when parsing the HTTP multipart request, false otherwise.

getErrors

public Collection getErrors()
Returns a collection of any errors generated when parsing the multipart request.

Returns:
the error Collection.

addError

protected void addError(String anErrorMessage)
Adds an error message.

Parameters:
anErrorMessage - the error message to report.

mergeParams

protected Enumeration mergeParams(Enumeration params1,
                                  Enumeration params2)
Merges 2 enumeration of parameters as one.

Parameters:
params1 - the first enumeration.
params2 - the second enumeration.
Returns:
a single Enumeration of all elements from both Enumerations.

WebWork Project Page