The Spring Framework

org.springframework.web.multipart.cos
Class CosMultipartResolver

java.lang.Object
  extended by org.springframework.web.multipart.cos.CosMultipartResolver
All Implemented Interfaces:
ServletContextAware, MultipartResolver

public class CosMultipartResolver
extends Object
implements MultipartResolver, ServletContextAware

MultipartResolver implementation for Jason Hunter's COS (com.oreilly.servlet). Works with a COS MultipartRequest underneath.

Provides "maxUploadSize" and "defaultEncoding" settings as bean properties; see respective MultipartRequest constructor parameters for details. Default maximum file size is unlimited; fallback encoding is the platform's default.

Since:
06.10.2003
Author:
Juergen Hoeller
See Also:
CosMultipartHttpServletRequest, MultipartRequest

Field Summary
protected  Log logger
          Logger available to subclasses
static String MULTIPART_CONTENT_TYPE
          Constant identifier for the mulipart content type : 'multipart/form-data'.
 
Constructor Summary
CosMultipartResolver()
          Constructor for use as bean.
CosMultipartResolver(ServletContext servletContext)
          Constructor for standalone usage.
 
Method Summary
 void cleanupMultipart(MultipartHttpServletRequest request)
          Cleanup any resources used for the multipart handling, like a storage for the uploaded files.
protected  String determineEncoding(HttpServletRequest request)
          Determine the encoding for the given request.
protected  String getDefaultEncoding()
          Return the default character encoding to use for parsing requests.
protected  int getMaxUploadSize()
          Return the maximum allowed size (in bytes) before uploads are refused.
protected  File getUploadTempDir()
          Return the temporary directory where uploaded files get stored.
 boolean isMultipart(HttpServletRequest request)
          Determine if the given request contains multipart content.
protected  com.oreilly.servlet.MultipartRequest newMultipartRequest(HttpServletRequest request)
          Create a com.oreilly.servlet.MultipartRequest for the given HTTP request.
 MultipartHttpServletRequest resolveMultipart(HttpServletRequest request)
          Parse the given HTTP request into multipart files and parameters, and wrap the request inside a MultipartHttpServletRequest object that provides access to file descriptors and makes contained parameters accessible via the standard ServletRequest methods.
 void setDefaultEncoding(String defaultEncoding)
          Set the default character encoding to use for parsing requests, to be applied to headers of individual parts and to form fields.
 void setMaxUploadSize(int maxUploadSize)
          Set the maximum allowed size (in bytes) before uploads are refused
 void setServletContext(ServletContext servletContext)
          Set the ServletContext that this object runs in.
 void setUploadTempDir(Resource uploadTempDir)
          Set the temporary directory where uploaded files get stored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MULTIPART_CONTENT_TYPE

public static final String MULTIPART_CONTENT_TYPE
Constant identifier for the mulipart content type : 'multipart/form-data'.

See Also:
Constant Field Values

logger

protected final Log logger
Logger available to subclasses

Constructor Detail

CosMultipartResolver

public CosMultipartResolver()
Constructor for use as bean. Determines the servlet container's temporary directory via the ServletContext passed in as through the ServletContextAware interface (typically by a WebApplicationContext).

See Also:
setServletContext(javax.servlet.ServletContext), ServletContextAware, WebApplicationContext

CosMultipartResolver

public CosMultipartResolver(ServletContext servletContext)
Constructor for standalone usage. Determines the servlet container's temporary directory via the given ServletContext.

Parameters:
servletContext - the ServletContext to use (must not be null)
Throws:
IllegalArgumentException - if the supplied ServletContext is null
Method Detail

setMaxUploadSize

public void setMaxUploadSize(int maxUploadSize)
Set the maximum allowed size (in bytes) before uploads are refused. -1 indicates no limit (the default).

Parameters:
maxUploadSize - the maximum file size allowed

getMaxUploadSize

protected int getMaxUploadSize()
Return the maximum allowed size (in bytes) before uploads are refused.


setDefaultEncoding

public void setDefaultEncoding(String defaultEncoding)
Set the default character encoding to use for parsing requests, to be applied to headers of individual parts and to form fields. Default is ISO-8859-1, according to the Servlet spec.

If the request specifies a character encoding itself, the request encoding will override this setting. This also allows for generically overriding the character encoding in a filter that invokes the ServletRequest.setCharacterEncoding method.

Parameters:
defaultEncoding - the character encoding to use
See Also:
determineEncoding(javax.servlet.http.HttpServletRequest), ServletRequest.getCharacterEncoding(), ServletRequest.setCharacterEncoding(java.lang.String), WebUtils.DEFAULT_CHARACTER_ENCODING

getDefaultEncoding

protected String getDefaultEncoding()
Return the default character encoding to use for parsing requests.


setUploadTempDir

public void setUploadTempDir(Resource uploadTempDir)
                      throws IOException
Set the temporary directory where uploaded files get stored. Default is the servlet container's temporary directory for the web application.

Throws:
IOException
See Also:
WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE

getUploadTempDir

protected File getUploadTempDir()
Return the temporary directory where uploaded files get stored.


setServletContext

public void setServletContext(ServletContext servletContext)
Description copied from interface: ServletContextAware
Set the ServletContext 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:
setServletContext in interface ServletContextAware
Parameters:
servletContext - ServletContext object to be used by this object
See Also:
InitializingBean.afterPropertiesSet(), ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)

isMultipart

public boolean isMultipart(HttpServletRequest request)
Description copied from interface: MultipartResolver
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 MultipartResolver
Parameters:
request - the servlet request to be evaluated
Returns:
whether the request contains multipart content

resolveMultipart

public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request)
                                             throws MultipartException
Description copied from interface: MultipartResolver
Parse the given HTTP request into multipart files and parameters, and wrap the request inside a MultipartHttpServletRequest object that provides access to file descriptors and makes contained parameters accessible via the standard ServletRequest methods.

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

newMultipartRequest

protected com.oreilly.servlet.MultipartRequest newMultipartRequest(HttpServletRequest request)
                                                            throws IOException
Create a com.oreilly.servlet.MultipartRequest for the given HTTP request. Can be overridden to use a custom subclass, e.g. for testing purposes.

Parameters:
request - current HTTP request
Returns:
the new MultipartRequest
Throws:
IOException - if thrown by the MultipartRequest constructor

determineEncoding

protected String determineEncoding(HttpServletRequest 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 HTTP request
Returns:
the encoding for the request (never null)
See Also:
ServletRequest.getCharacterEncoding(), setDefaultEncoding(java.lang.String)

cleanupMultipart

public void cleanupMultipart(MultipartHttpServletRequest request)
Description copied from interface: MultipartResolver
Cleanup any resources used for the multipart handling, like a storage for the uploaded files.

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

The Spring Framework

Copyright © 2002-2007 The Spring Framework.