HDIV API 2.0.4

org.hdiv.config.multipart
Class SpringMVCMultipartConfig

java.lang.Object
  extended by org.hdiv.config.multipart.SpringMVCMultipartConfig
All Implemented Interfaces:
IMultipartConfig

public class SpringMVCMultipartConfig
extends java.lang.Object
implements IMultipartConfig

Class containing multipart request configuration.

NOTE: This multipart resolver requires Commons FileUpload 1.1 or higher.

Since:
HDIV 2.0.3
Author:
Gorka Vicente

Field Summary
 
Fields inherited from interface org.hdiv.config.multipart.IMultipartConfig
ATTRIBUTE_MAX_LENGTH_EXCEEDED, DEFAULT_SIZE_MAX, DEFAULT_SIZE_THRESHOLD, FILEUPLOAD_EXCEPTION
 
Constructor Summary
SpringMVCMultipartConfig()
           
 
Method Summary
 void addFileParameter(RequestWrapper request, org.apache.commons.fileupload.FileItem item)
          Adds a file parameter to the set of file parameters for this request and also to the list of all parameters.
 void addTextParameter(RequestWrapper request, org.apache.commons.fileupload.FileItem fileItem)
          Adds a regular text parameter to the set of text parameters for this request.
protected  java.lang.String determineEncoding(javax.servlet.http.HttpServletRequest request)
          Determine the encoding for the given request.
protected  java.lang.String getDefaultEncoding()
           
 java.lang.String getRepositoryPath(javax.servlet.ServletContext servletContext)
          Returns the path to the temporary directory to be used for uploaded files which are written to disk.
 void handleMultipartRequest(RequestWrapper request, javax.servlet.ServletContext servletContext)
          Parses the input stream and partitions the parsed items into a set of form fields and a set of file items.
protected  org.apache.commons.fileupload.disk.DiskFileItemFactory newFileItemFactory()
          Factory method for a Commons DiskFileItemFactory instance.
protected  org.apache.commons.fileupload.FileUpload newFileUpload(org.apache.commons.fileupload.FileItemFactory fileItemFactory)
          Initialize the underlying org.apache.commons.fileupload.servlet.ServletFileUpload instance.
protected  void parseFileItems(RequestWrapper request, java.util.List fileItems)
          Parse the given List of Commons FileItems into a Spring MultipartParsingResult, containing Spring MultipartFile instances and a Map of multipart parameter.
protected  org.apache.commons.fileupload.FileUpload prepareFileUpload(java.lang.String encoding)
          Determine an appropriate FileUpload instance for the given encoding.
 void setMultipartResolver(org.springframework.web.multipart.commons.CommonsMultipartResolver multipartResolver)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpringMVCMultipartConfig

public SpringMVCMultipartConfig()
Method Detail

handleMultipartRequest

public void handleMultipartRequest(RequestWrapper request,
                                   javax.servlet.ServletContext servletContext)
                            throws org.apache.commons.fileupload.FileUploadException,
                                   org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException,
                                   org.springframework.web.multipart.MaxUploadSizeExceededException
Parses the input stream and partitions the parsed items into a set of form fields and a set of file items.

Specified by:
handleMultipartRequest in interface IMultipartConfig
Parameters:
request - The multipart request wrapper.
servletContext - Our ServletContext object
Throws:
org.apache.commons.fileupload.FileUploadException - if an unrecoverable error occurs.
DiskFileUpload.SizeLimitExceededException - if size limit exceeded
org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException
org.springframework.web.multipart.MaxUploadSizeExceededException

parseFileItems

protected void parseFileItems(RequestWrapper request,
                              java.util.List fileItems)
Parse the given List of Commons FileItems into a Spring MultipartParsingResult, containing Spring MultipartFile instances and a Map of multipart parameter.

Parameters:
request - the request to parse
fileItems - the Commons FileIterms to parse
See Also:
CommonsMultipartFile.CommonsMultipartFile(org.apache.commons.fileupload.FileItem)

addTextParameter

public void addTextParameter(RequestWrapper request,
                             org.apache.commons.fileupload.FileItem fileItem)
Adds a regular text parameter to the set of text parameters for this request. Handles the case of multiple values for the same parameter by using an array for the parameter value.

Specified by:
addTextParameter in interface IMultipartConfig
Parameters:
request - The request in which the parameter was specified
fileItem - The file item for the parameter to add
encoding - the character encoding to use

addFileParameter

public void addFileParameter(RequestWrapper request,
                             org.apache.commons.fileupload.FileItem item)
Adds a file parameter to the set of file parameters for this request and also to the list of all parameters.

Specified by:
addFileParameter in interface IMultipartConfig
Parameters:
request - The request in which the parameter was specified.
item - The file item for the parameter to add.

getRepositoryPath

public java.lang.String getRepositoryPath(javax.servlet.ServletContext servletContext)
Description copied from interface: IMultipartConfig
Returns the path to the temporary directory to be used for uploaded files which are written to disk. The directory used is determined from the first of the following to be non-empty.
  1. A temp dir explicitly defined using the saveDir attribute of the <multipartConfig> element in the Spring config file.
  2. The temp dir specified by the javax.servlet.context.tempdir attribute.

Specified by:
getRepositoryPath in interface IMultipartConfig
Parameters:
servletContext - servlet context
Returns:
The path to the directory to be used to store uploaded files.

setMultipartResolver

public void setMultipartResolver(org.springframework.web.multipart.commons.CommonsMultipartResolver multipartResolver)
Parameters:
multipartResolver - the multipart resolver to set

determineEncoding

protected java.lang.String determineEncoding(javax.servlet.http.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

getDefaultEncoding

protected java.lang.String getDefaultEncoding()

prepareFileUpload

protected org.apache.commons.fileupload.FileUpload prepareFileUpload(java.lang.String encoding)
Determine an appropriate FileUpload instance for the given encoding.

Default implementation returns the shared FileUpload instance if the encoding matches, else creates a new FileUpload instance with the same configuration other than the desired encoding.

Parameters:
encoding - the character encoding to use
Returns:
an appropriate FileUpload instance.

newFileItemFactory

protected org.apache.commons.fileupload.disk.DiskFileItemFactory newFileItemFactory()
Factory method for a Commons DiskFileItemFactory instance.

Default implementation returns a standard DiskFileItemFactory. Can be overridden to use a custom subclass, e.g. for testing purposes.

Returns:
the new DiskFileItemFactory instance

newFileUpload

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

Parameters:
fileItemFactory - the Commons FileItemFactory to use
Returns:
the new ServletFileUpload instance

HDIV 2.0.4

Copyright © 2008 hdiv.org. All Rights Reserved.