org.apache.struts2.dispatcher.multipart
Class MultiPartRequestWrapper

java.lang.Object
  extended by javax.servlet.ServletRequestWrapper
      extended by javax.servlet.http.HttpServletRequestWrapper
          extended by org.apache.struts2.dispatcher.StrutsRequestWrapper
              extended by org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public class MultiPartRequestWrapper
extends StrutsRequestWrapper

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

The struts.multipart.parser property should be set to jakarta for the Jakarta implementation, 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.

An alternate implementation, PellMultiPartRequest, is provided as a plugin.


Field Summary
protected static Logger LOG
           
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
MultiPartRequestWrapper(MultiPartRequest multiPartRequest, javax.servlet.http.HttpServletRequest request, java.lang.String saveDir)
          Process file downloads and log any errors.
 
Method Summary
protected  void addError(java.lang.String anErrorMessage)
          Adds an error message.
 java.lang.String[] getContentTypes(java.lang.String name)
          Get an array of content encoding for the specified input field name or null if no content type was specified.
 java.util.Collection<java.lang.String> getErrors()
          Returns a collection of any errors generated when parsing the multipart request.
 java.lang.String[] getFileNames(java.lang.String fieldName)
          Get a String array of the file names for uploaded files
 java.util.Enumeration<java.lang.String> getFileParameterNames()
          Get an enumeration of the parameter names for uploaded files
 java.io.File[] getFiles(java.lang.String fieldName)
          Get a java.io.File[] for the given input field name.
 java.lang.String[] getFileSystemNames(java.lang.String fieldName)
          Get the filename(s) of the file(s) uploaded for the given input field name.
 java.lang.String getParameter(java.lang.String name)
           
 java.util.Map getParameterMap()
           
 java.util.Enumeration getParameterNames()
           
 java.lang.String[] getParameterValues(java.lang.String name)
           
 boolean hasErrors()
          Returns true if any errors occured when parsing the HTTP multipart request, false otherwise.
protected  java.util.Enumeration mergeParams(java.util.Enumeration params1, java.util.Enumeration params2)
          Merges 2 enumeration of parameters as one.
 
Methods inherited from class org.apache.struts2.dispatcher.StrutsRequestWrapper
getAttribute
 
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
getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocale, getLocales, 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
getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
 

Field Detail

LOG

protected static final Logger LOG
Constructor Detail

MultiPartRequestWrapper

public MultiPartRequestWrapper(MultiPartRequest multiPartRequest,
                               javax.servlet.http.HttpServletRequest request,
                               java.lang.String saveDir)
Process file downloads and log any errors.

Parameters:
request - Our HttpServletRequest object
saveDir - Target directory for any files that we save
multiPartRequest - Our MultiPartRequest object
Method Detail

getFileParameterNames

public java.util.Enumeration<java.lang.String> getFileParameterNames()
Get an enumeration of the parameter names for uploaded files

Returns:
enumeration of parameter names for uploaded files

getContentTypes

public java.lang.String[] getContentTypes(java.lang.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

getFiles

public java.io.File[] getFiles(java.lang.String fieldName)
Get a java.io.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 java.lang.String[] getFileNames(java.lang.String fieldName)
Get a String array of the file names for uploaded files

Parameters:
fieldName - Field to check for file names.
Returns:
a String[] of file names for uploaded files

getFileSystemNames

public java.lang.String[] getFileSystemNames(java.lang.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 java.lang.String getParameter(java.lang.String name)
Specified by:
getParameter in interface javax.servlet.ServletRequest
Overrides:
getParameter in class javax.servlet.ServletRequestWrapper
See Also:
ServletRequest.getParameter(String)

getParameterMap

public java.util.Map getParameterMap()
Specified by:
getParameterMap in interface javax.servlet.ServletRequest
Overrides:
getParameterMap in class javax.servlet.ServletRequestWrapper
See Also:
ServletRequest.getParameterMap()

getParameterNames

public java.util.Enumeration getParameterNames()
Specified by:
getParameterNames in interface javax.servlet.ServletRequest
Overrides:
getParameterNames in class javax.servlet.ServletRequestWrapper
See Also:
ServletRequest.getParameterNames()

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Specified by:
getParameterValues in interface javax.servlet.ServletRequest
Overrides:
getParameterValues in class javax.servlet.ServletRequestWrapper
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 java.util.Collection<java.lang.String> getErrors()
Returns a collection of any errors generated when parsing the multipart request.

Returns:
the error Collection.

addError

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

Parameters:
anErrorMessage - the error message to report.

mergeParams

protected java.util.Enumeration mergeParams(java.util.Enumeration params1,
                                            java.util.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.


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.