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(LocalizedMessage)
. An action handling a multipart form should first check hasErrors()
before doing any other processing.
An alternate implementation, PellMultiPartRequest, is provided as a plugin.
Modifier and Type | Field and Description |
---|---|
protected static org.apache.logging.log4j.Logger |
LOG |
Constructor and Description |
---|
MultiPartRequestWrapper(MultiPartRequest multiPartRequest,
javax.servlet.http.HttpServletRequest request,
String saveDir,
LocaleProvider provider) |
MultiPartRequestWrapper(MultiPartRequest multiPartRequest,
javax.servlet.http.HttpServletRequest request,
String saveDir,
LocaleProvider provider,
boolean disableRequestAttributeValueStackLookup)
Process file downloads and log any errors.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addError(LocalizedMessage anErrorMessage)
Adds an error message when it isn't already added.
|
protected LocalizedMessage |
buildErrorMessage(Throwable e,
Object[] args) |
void |
cleanUp() |
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<LocalizedMessage> |
getErrors()
Returns a collection of any errors generated when parsing the multipart request.
|
String[] |
getFileNames(String fieldName)
Get a String array of the file names for uploaded files
|
Enumeration<String> |
getFileParameterNames()
Get an enumeration of the parameter names for uploaded files
|
UploadedFile[] |
getFiles(String fieldName)
Get a
File[] for the given input field name. |
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.
|
protected void |
setLocale(javax.servlet.http.HttpServletRequest request) |
getAttribute
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
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
public MultiPartRequestWrapper(MultiPartRequest multiPartRequest, javax.servlet.http.HttpServletRequest request, String saveDir, LocaleProvider provider, boolean disableRequestAttributeValueStackLookup)
multiPartRequest
- Our MultiPartRequest objectrequest
- Our HttpServletRequest objectsaveDir
- Target directory for any files that we saveprovider
- locale providerdisableRequestAttributeValueStackLookup
- disable the request attribute value stack lookuppublic MultiPartRequestWrapper(MultiPartRequest multiPartRequest, javax.servlet.http.HttpServletRequest request, String saveDir, LocaleProvider provider)
protected void setLocale(javax.servlet.http.HttpServletRequest request)
protected LocalizedMessage buildErrorMessage(Throwable e, Object[] args)
public Enumeration<String> getFileParameterNames()
public String[] getContentTypes(String name)
name
- input field namepublic UploadedFile[] getFiles(String fieldName)
File[]
for the given input field name.fieldName
- input field namepublic String[] getFileNames(String fieldName)
fieldName
- Field to check for file names.public String[] getFileSystemNames(String fieldName)
fieldName
- input field namepublic String getParameter(String name)
getParameter
in interface javax.servlet.ServletRequest
getParameter
in class javax.servlet.ServletRequestWrapper
ServletRequest.getParameter(String)
public Map getParameterMap()
getParameterMap
in interface javax.servlet.ServletRequest
getParameterMap
in class javax.servlet.ServletRequestWrapper
ServletRequest.getParameterMap()
public Enumeration getParameterNames()
getParameterNames
in interface javax.servlet.ServletRequest
getParameterNames
in class javax.servlet.ServletRequestWrapper
ServletRequest.getParameterNames()
public String[] getParameterValues(String name)
getParameterValues
in interface javax.servlet.ServletRequest
getParameterValues
in class javax.servlet.ServletRequestWrapper
ServletRequest.getParameterValues(String)
public boolean hasErrors()
public Collection<LocalizedMessage> getErrors()
protected void addError(LocalizedMessage anErrorMessage)
anErrorMessage
- the error message to report.protected Enumeration mergeParams(Enumeration params1, Enumeration params2)
params1
- the first enumeration.params2
- the second enumeration.public void cleanUp()
Copyright © 2000–2020 Apache Software Foundation. All rights reserved.