public class CommonsPortletMultipartResolver extends CommonsFileUploadSupport implements PortletMultipartResolver, PortletContextAware
PortletMultipartResolver
implementation for
Apache Commons FileUpload
1.2 or above.
Provides "maxUploadSize", "maxInMemorySize" and "defaultEncoding" settings as
bean properties (inherited from CommonsFileUploadSupport
). See corresponding
PortletFileUpload / DiskFileItemFactory properties ("sizeMax", "sizeThreshold",
"headerEncoding") for details in terms of defaults and accepted values.
Saves temporary files to the portlet container's temporary directory. Needs to be initialized either by an application context or via the constructor that takes a PortletContext (for standalone usage).
CommonsPortletMultipartResolver(javax.portlet.PortletContext)
,
setResolveLazily(boolean)
,
CommonsMultipartResolver
,
PortletFileUpload
,
DiskFileItemFactory
CommonsFileUploadSupport.MultipartParsingResult
logger
Constructor and Description |
---|
CommonsPortletMultipartResolver()
Constructor for use as bean.
|
CommonsPortletMultipartResolver(PortletContext portletContext)
Constructor for standalone usage.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanupMultipart(MultipartActionRequest request)
Cleanup any resources used for the multipart handling,
such as storage for any uploaded file(s).
|
protected String |
determineEncoding(ActionRequest request)
Determine the encoding for the given request.
|
boolean |
isMultipart(ActionRequest request)
Determine if the given request contains multipart content.
|
protected org.apache.commons.fileupload.FileUpload |
newFileUpload(org.apache.commons.fileupload.FileItemFactory fileItemFactory)
Initialize the underlying
org.apache.commons.fileupload.portlet.PortletFileUpload
instance. |
protected CommonsFileUploadSupport.MultipartParsingResult |
parseRequest(ActionRequest request)
Parse the given portlet request, resolving its multipart elements.
|
MultipartActionRequest |
resolveMultipart(ActionRequest request)
Parse the given portlet request into multipart files and parameters,
and wrap the request inside a MultipartActionRequest object
that provides access to file descriptors and makes contained
parameters accessible via the standard PortletRequest methods.
|
void |
setPortletContext(PortletContext portletContext)
Set the PortletContext that this object runs in.
|
void |
setResolveLazily(boolean resolveLazily)
Set whether to resolve the multipart request lazily at the time of
file or parameter access.
|
cleanupFileItems, getDefaultEncoding, getFileItemFactory, getFileUpload, isUploadTempDirSpecified, newFileItemFactory, parseFileItems, prepareFileUpload, setDefaultEncoding, setMaxInMemorySize, setMaxUploadSize, setUploadTempDir
public CommonsPortletMultipartResolver()
public CommonsPortletMultipartResolver(PortletContext portletContext)
portletContext
- the PortletContext to usepublic void setResolveLazily(boolean resolveLazily)
Default is "false", resolving the multipart elements immediately, throwing
corresponding exceptions at the time of the resolveMultipart(javax.portlet.ActionRequest)
call.
Switch this to "true" for lazy multipart parsing, throwing parse exceptions
once the application attempts to obtain multipart files or parameters.
protected org.apache.commons.fileupload.FileUpload newFileUpload(org.apache.commons.fileupload.FileItemFactory fileItemFactory)
org.apache.commons.fileupload.portlet.PortletFileUpload
instance. Can be overridden to use a custom subclass, e.g. for testing purposes.newFileUpload
in class CommonsFileUploadSupport
fileItemFactory
- the Commons FileItemFactory to build uponpublic void setPortletContext(PortletContext portletContext)
PortletContextAware
Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ApplicationContextAware's setApplicationContext.
setPortletContext
in interface PortletContextAware
portletContext
- PortletContext object to be used by this objectpublic boolean isMultipart(ActionRequest request)
PortletMultipartResolver
Will typically check for content type
"multipart/form-data
", but the actually accepted requests
might depend on the capabilities of the resolver implementation.
isMultipart
in interface PortletMultipartResolver
request
- the portlet request to be evaluatedpublic MultipartActionRequest resolveMultipart(ActionRequest request) throws MultipartException
PortletMultipartResolver
resolveMultipart
in interface PortletMultipartResolver
request
- the portlet request to wrap (must be of a multipart content type)MultipartException
- if the portlet request
is not multipart, or if implementation-specific problems are encountered
(such as exceeding file size limits)MultipartRequest.getFile(java.lang.String)
,
MultipartRequest.getFileNames()
,
MultipartRequest.getFileMap()
,
PortletRequest.getParameter(java.lang.String)
,
PortletRequest.getParameterNames()
,
PortletRequest.getParameterMap()
protected CommonsFileUploadSupport.MultipartParsingResult parseRequest(ActionRequest request) throws MultipartException
request
- the request to parseMultipartException
- if multipart resolution failed.protected String determineEncoding(ActionRequest request)
The default implementation checks the request encoding, falling back to the default encoding specified for this resolver.
request
- current portlet requestnull
)ClientDataRequest.getCharacterEncoding()
,
CommonsFileUploadSupport.setDefaultEncoding(java.lang.String)
public void cleanupMultipart(MultipartActionRequest request)
PortletMultipartResolver
cleanupMultipart
in interface PortletMultipartResolver
request
- the request to cleanup resources for