org.springframework.web.portlet.multipart
Class CommonsPortletMultipartResolver

java.lang.Object
  extended by org.springframework.web.multipart.commons.CommonsFileUploadSupport
      extended by org.springframework.web.portlet.multipart.CommonsPortletMultipartResolver
All Implemented Interfaces:
PortletContextAware, PortletMultipartResolver

public class CommonsPortletMultipartResolver
extends CommonsFileUploadSupport
implements PortletMultipartResolver, PortletContextAware

PortletMultipartResolver implementation for Jakarta Commons FileUpload 1.1 or above. Commons FileUpload 1.2 or above is recommended.

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).

Since:
2.0
Author:
Juergen Hoeller
See Also:
CommonsPortletMultipartResolver(javax.portlet.PortletContext), setResolveLazily(boolean), CommonsMultipartResolver, PortletFileUpload, DiskFileItemFactory

Nested Class Summary
 
Nested classes/interfaces inherited from class org.springframework.web.multipart.commons.CommonsFileUploadSupport
CommonsFileUploadSupport.MultipartParsingResult
 
Field Summary
 
Fields inherited from class org.springframework.web.multipart.commons.CommonsFileUploadSupport
logger
 
Constructor Summary
CommonsPortletMultipartResolver()
          Constructor for use as bean.
CommonsPortletMultipartResolver(javax.portlet.PortletContext portletContext)
          Constructor for standalone usage.
 
Method Summary
 void cleanupMultipart(MultipartActionRequest request)
          Cleanup any resources used for the multipart handling, such as storage for any uploaded file(s).
protected  String determineEncoding(javax.portlet.ActionRequest request)
          Determine the encoding for the given request.
 boolean isMultipart(javax.portlet.ActionRequest request)
          Determine if the given request contains multipart content.
protected  FileUpload newFileUpload(FileItemFactory fileItemFactory)
          Initialize the underlying org.apache.commons.fileupload.portlet.PortletFileUpload instance.
protected  CommonsFileUploadSupport.MultipartParsingResult parseRequest(javax.portlet.ActionRequest request)
          Parse the given portlet request, resolving its multipart elements.
 MultipartActionRequest resolveMultipart(javax.portlet.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(javax.portlet.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.
 
Methods inherited from class org.springframework.web.multipart.commons.CommonsFileUploadSupport
cleanupFileItems, getDefaultEncoding, getFileItemFactory, getFileUpload, isUploadTempDirSpecified, newFileItemFactory, parseFileItems, prepareFileUpload, setDefaultEncoding, setMaxInMemorySize, setMaxUploadSize, setUploadTempDir
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommonsPortletMultipartResolver

public CommonsPortletMultipartResolver()
Constructor for use as bean. Determines the portlet container's temporary directory via the PortletContext passed in as through the PortletContextAware interface (typically by an ApplicationContext).

See Also:
setPortletContext(javax.portlet.PortletContext), PortletContextAware

CommonsPortletMultipartResolver

public CommonsPortletMultipartResolver(javax.portlet.PortletContext portletContext)
Constructor for standalone usage. Determines the portlet container's temporary directory via the given PortletContext.

Parameters:
portletContext - the PortletContext to use
Method Detail

setResolveLazily

public void setResolveLazily(boolean resolveLazily)
Set whether to resolve the multipart request lazily at the time of file or parameter access.

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.


newFileUpload

protected FileUpload newFileUpload(FileItemFactory fileItemFactory)
Initialize the underlying org.apache.commons.fileupload.portlet.PortletFileUpload instance. Can be overridden to use a custom subclass, e.g. for testing purposes.

Specified by:
newFileUpload in class CommonsFileUploadSupport
Parameters:
fileItemFactory - the Commons FileItemFactory to build upon
Returns:
the new PortletFileUpload instance

setPortletContext

public void setPortletContext(javax.portlet.PortletContext portletContext)
Description copied from interface: PortletContextAware
Set the PortletContext that this object runs in.

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.

Specified by:
setPortletContext in interface PortletContextAware
Parameters:
portletContext - PortletContext object to be used by this object

isMultipart

public boolean isMultipart(javax.portlet.ActionRequest request)
Description copied from interface: PortletMultipartResolver
Determine if the given request contains multipart content.

Will typically check for content type "multipart/form-data", but the actually accepted requests might depend on the capabilities of the resolver implementation.

Specified by:
isMultipart in interface PortletMultipartResolver
Parameters:
request - the portlet request to be evaluated
Returns:
whether the request contains multipart content

resolveMultipart

public MultipartActionRequest resolveMultipart(javax.portlet.ActionRequest request)
                                        throws MultipartException
Description copied from interface: PortletMultipartResolver
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.

Specified by:
resolveMultipart in interface PortletMultipartResolver
Parameters:
request - the portlet request to wrap (must be of a multipart content type)
Returns:
the wrapped portlet request
Throws:
MultipartException - if the portlet request is not multipart, or if implementation-specific problems are encountered (such as exceeding file size limits)
See Also:
MultipartRequest.getFile(java.lang.String), MultipartRequest.getFileNames(), MultipartRequest.getFileMap(), PortletRequest.getParameter(java.lang.String), PortletRequest.getParameterNames(), PortletRequest.getParameterMap()

parseRequest

protected CommonsFileUploadSupport.MultipartParsingResult parseRequest(javax.portlet.ActionRequest request)
                                                                throws MultipartException
Parse the given portlet request, resolving its multipart elements.

Parameters:
request - the request to parse
Returns:
the parsing result
Throws:
MultipartException - if multipart resolution failed.

determineEncoding

protected String determineEncoding(javax.portlet.ActionRequest request)
Determine the encoding for the given request. Can be overridden in subclasses.

The default implementation checks the request encoding, falling back to the default encoding specified for this resolver.

Parameters:
request - current portlet request
Returns:
the encoding for the request (never null)
See Also:
ActionRequest.getCharacterEncoding(), CommonsFileUploadSupport.setDefaultEncoding(java.lang.String)

cleanupMultipart

public void cleanupMultipart(MultipartActionRequest request)
Description copied from interface: PortletMultipartResolver
Cleanup any resources used for the multipart handling, such as storage for any uploaded file(s).

Specified by:
cleanupMultipart in interface PortletMultipartResolver
Parameters:
request - the request to cleanup resources for


Copyright © 2002-2008 The Spring Framework.