org.apache.struts2.dispatcher.multipart
public class: MultiPartRequestWrapper [javadoc |
source]
java.lang.Object
javax.servlet.ServletRequestWrapper
javax.servlet.http.HttpServletRequestWrapper
org.apache.struts2.dispatcher.StrutsRequestWrapper
org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper
All Implemented Interfaces:
HttpServletRequest, ServletRequest
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
org.apache.struts2.dispatcher.multipart.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 final Log | log | |
| Collection | errors | |
| MultiPartRequest | multi | |
| Constructor: |
public MultiPartRequestWrapper(MultiPartRequest multiPartRequest,
HttpServletRequest request,
String saveDir) {
super(request);
multi = multiPartRequest;
try {
multi.parse(request, saveDir);
for (Object o : multi.getErrors()) {
String error = (String) o;
addError(error);
}
} catch (IOException e) {
addError("Cannot parse request: "+e.toString());
}
}
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 from org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper Summary: |
|---|
|
addError, getContentTypes, getErrors, getFileNames, getFileParameterNames, getFileSystemNames, getFiles, getParameter, getParameterMap, getParameterNames, getParameterValues, hasErrors, mergeParams |
| Methods from org.apache.struts2.dispatcher.StrutsRequestWrapper: |
|---|
|
getAttribute |
| Methods from javax.servlet.http.HttpServletRequestWrapper: |
|---|
|
getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getIntHeader, getMethod, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestURI, getRequestURL, getRequestedSessionId, getServletPath, getSession, getSession, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromURL, isRequestedSessionIdFromUrl, isRequestedSessionIdValid, isUserInRole |
| Methods from javax.servlet.ServletRequestWrapper: |
|---|
|
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocalName, getLocalPort, getLocale, getLocales, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding, setRequest |
| Method from org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper Detail: |
protected void addError(String anErrorMessage) {
if (errors == null) {
errors = new ArrayList< String >();
}
errors.add(anErrorMessage);
}
|
public String[] getContentTypes(String name) {
if (multi == null) {
return null;
}
return multi.getContentType(name);
}
Get an array of content encoding for the specified input field name or null if
no content type was specified. |
public Collection getErrors() {
return errors;
}
Returns a collection of any errors generated when parsing the multipart request. |
public String[] getFileNames(String fieldName) {
if (multi == null) {
return null;
}
return multi.getFileNames(fieldName);
}
Get a String array of the file names for uploaded files |
public Enumeration getFileParameterNames() {
if (multi == null) {
return null;
}
return multi.getFileParameterNames();
}
Get an enumeration of the parameter names for uploaded files |
public String[] getFileSystemNames(String fieldName) {
if (multi == null) {
return null;
}
return multi.getFilesystemName(fieldName);
}
Get the filename(s) of the file(s) uploaded for the given input field name.
Returns null if the file is not found. |
public File[] getFiles(String fieldName) {
if (multi == null) {
return null;
}
return multi.getFile(fieldName);
}
|
public String getParameter(String name) {
return ((multi == null) || (multi.getParameter(name) == null)) ? super.getParameter(name) : multi.getParameter(name);
}
|
public Map getParameterMap() {
Map< String, String[] > map = new HashMap< String, String[] >();
Enumeration enumeration = getParameterNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
map.put(name, this.getParameterValues(name));
}
return map;
}
|
public Enumeration getParameterNames() {
if (multi == null) {
return super.getParameterNames();
} else {
return mergeParams(multi.getParameterNames(), super.getParameterNames());
}
}
|
public String[] getParameterValues(String name) {
return ((multi == null) || (multi.getParameterValues(name) == null)) ? super.getParameterValues(name) : multi.getParameterValues(name);
}
|
public boolean hasErrors() {
return !((errors == null) || errors.isEmpty());
}
Returns true if any errors occured when parsing the HTTP multipart request, false otherwise. |
protected Enumeration mergeParams(Enumeration params1,
Enumeration params2) {
Vector temp = new Vector();
while (params1.hasMoreElements()) {
temp.add(params1.nextElement());
}
while (params2.hasMoreElements()) {
temp.add(params2.nextElement());
}
return temp.elements();
}
Merges 2 enumeration of parameters as one. |