Class DefaultUploadService
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.apache.fulcrum.upload.DefaultUploadService
-
- All Implemented Interfaces:
org.apache.avalon.framework.activity.Initializable,org.apache.avalon.framework.configuration.Configurable,org.apache.avalon.framework.context.Contextualizable,org.apache.avalon.framework.logger.LogEnabled,UploadService
public class DefaultUploadService extends org.apache.avalon.framework.logger.AbstractLogEnabled implements UploadService, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable
This class is an implementation of
UploadService.Files will be stored in temporary disk storage on in memory, depending on request size, and will be available from the
org.apache.fulcrum.util.parser.ParameterParserasorg.apache.commons.fileupload.FileItemobjects.This implementation of
UploadServicehandles multiple files per single html form, sent using multipart/form-data encoding type, as specified by RFC 1867. Useorg.apache.fulcrum.parser.ParameterParser#getFileItems(String)to acquire an array oforg.apache.commons.fileupload.FileItemobjects associated with given html form.- Version:
- $Id$
- Author:
- Rafal Krzewski, Daniel Rall, Jason van Zyl
-
-
Field Summary
-
Fields inherited from interface org.apache.fulcrum.upload.UploadService
CONTENT_DISPOSITION, CONTENT_TYPE, FORM_DATA, HEADER_ENCODING_DEFAULT, HEADER_ENCODING_KEY, MIXED, MULTIPART, MULTIPART_FORM_DATA, MULTIPART_MIXED, REPOSITORY_DEFAULT, REPOSITORY_KEY, REPOSITORY_PARAMETER, ROLE, SIZE_MAX_DEFAULT, SIZE_MAX_KEY, SIZE_THRESHOLD_DEFAULT, SIZE_THRESHOLD_KEY
-
-
Constructor Summary
Constructors Constructor Description DefaultUploadService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(org.apache.avalon.framework.configuration.Configuration conf)Avalon component lifecycle methodvoidcontextualize(org.apache.avalon.framework.context.Context context)Avalon component lifecycle methodStringgetHeaderEncoding()Retrieves the value of theheaderEncodingproperty ofUploadService.org.apache.commons.fileupload.FileItemIteratorgetItemIterator(javax.portlet.ActionRequest req)Processes an RFC 1867 compliantmultipart/form-datastream.org.apache.commons.fileupload.FileItemIteratorgetItemIterator(HttpServletRequest req)Processes an RFC 1867 compliantmultipart/form-datastream.StringgetRepository()The location used to temporarily store files that are larger than the size threshold.longgetSizeMax()The maximum allowed upload sizelonggetSizeThreshold()The threshold beyond which files are written directly to disk.voidinitialize()Avalon component lifecycle method Initializes the service.booleanisMultipart(javax.portlet.ActionRequest req)Utility method that determines whether the request contains multipart content.booleanisMultipart(HttpServletRequest req)Utility method that determines whether the request contains multipart content.List<org.apache.commons.fileupload.FileItem>parseRequest(javax.portlet.ActionRequest req)Parses a RFC 1867 compliantmultipart/form-datastream.List<org.apache.commons.fileupload.FileItem>parseRequest(javax.portlet.ActionRequest req, int sizeThreshold, int sizeMax, String path)Parses a RFC 1867 compliantmultipart/form-datastream.protected List<org.apache.commons.fileupload.FileItem>parseRequest(javax.portlet.ActionRequest req, int sizeMax, org.apache.commons.fileupload.disk.DiskFileItemFactory factory)Parses a RFC 1867 compliantmultipart/form-datastream.List<org.apache.commons.fileupload.FileItem>parseRequest(javax.portlet.ActionRequest req, String path)Parses a RFC 1867 compliantmultipart/form-datastream.List<org.apache.commons.fileupload.FileItem>parseRequest(HttpServletRequest req)Parses a RFC 1867 compliantmultipart/form-datastream.List<org.apache.commons.fileupload.FileItem>parseRequest(HttpServletRequest req, int sizeThreshold, int sizeMax, String path)Parses a RFC 1867 compliantmultipart/form-datastream.protected List<org.apache.commons.fileupload.FileItem>parseRequest(HttpServletRequest req, int sizeMax, org.apache.commons.fileupload.disk.DiskFileItemFactory factory)Parses a RFC 1867 compliantmultipart/form-datastream.List<org.apache.commons.fileupload.FileItem>parseRequest(HttpServletRequest req, String path)Parses a RFC 1867 compliantmultipart/form-datastream.
-
-
-
Constructor Detail
-
DefaultUploadService
public DefaultUploadService()
-
-
Method Detail
-
getSizeMax
public long getSizeMax()
The maximum allowed upload size- Specified by:
getSizeMaxin interfaceUploadService- Returns:
- The maximum upload size.
-
getSizeThreshold
public long getSizeThreshold()
The threshold beyond which files are written directly to disk.- Specified by:
getSizeThresholdin interfaceUploadService- Returns:
- The threshold beyond which files are written directly to disk.
-
getRepository
public String getRepository()
The location used to temporarily store files that are larger than the size threshold.- Specified by:
getRepositoryin interfaceUploadService- Returns:
- The repository.
-
getHeaderEncoding
public String getHeaderEncoding()
Description copied from interface:UploadServiceRetrieves the value of the
headerEncodingproperty ofUploadService.- Specified by:
getHeaderEncodingin interfaceUploadService- Returns:
- Returns the headerEncoding.
-
parseRequest
public List<org.apache.commons.fileupload.FileItem> parseRequest(HttpServletRequest req) throws org.apache.avalon.framework.service.ServiceException
Parses a RFC 1867 compliant
multipart/form-datastream.- Specified by:
parseRequestin interfaceUploadService- Parameters:
req- The servlet request to be parsed.- Returns:
- list of file items
- Throws:
org.apache.avalon.framework.service.ServiceException- Problems reading/parsing the request or storing the uploaded file(s).
-
parseRequest
public List<org.apache.commons.fileupload.FileItem> parseRequest(HttpServletRequest req, String path) throws org.apache.avalon.framework.service.ServiceException
Parses a RFC 1867 compliant
multipart/form-datastream.- Specified by:
parseRequestin interfaceUploadService- Parameters:
req- The servlet request to be parsed.path- The location where the files should be stored.- Returns:
- List of FileItem parts
- Throws:
org.apache.avalon.framework.service.ServiceException- Problems reading/parsing the request or storing the uploaded file(s).
-
parseRequest
public List<org.apache.commons.fileupload.FileItem> parseRequest(HttpServletRequest req, int sizeThreshold, int sizeMax, String path) throws org.apache.avalon.framework.service.ServiceException
Parses a RFC 1867 compliant
multipart/form-datastream.- Specified by:
parseRequestin interfaceUploadService- Parameters:
req- The servlet request to be parsed.sizeThreshold- the max size in bytes to be stored in memorysizeMax- the maximum allowed upload size in bytespath- The location where the files should be stored.- Returns:
- list of file items
- Throws:
org.apache.avalon.framework.service.ServiceException- Problems reading/parsing the request or storing the uploaded file(s).
-
parseRequest
protected List<org.apache.commons.fileupload.FileItem> parseRequest(HttpServletRequest req, int sizeMax, org.apache.commons.fileupload.disk.DiskFileItemFactory factory) throws org.apache.avalon.framework.service.ServiceException
Parses a RFC 1867 compliant
multipart/form-datastream.- Parameters:
req- The servlet request to be parsed.sizeMax- the maximum allowed upload size in bytesfactory- the file item factory to use- Returns:
- list of file items
- Throws:
org.apache.avalon.framework.service.ServiceException- Problems reading/parsing the request or storing the uploaded file(s).
-
getItemIterator
public org.apache.commons.fileupload.FileItemIterator getItemIterator(HttpServletRequest req) throws org.apache.avalon.framework.service.ServiceException
Processes an RFC 1867 compliantmultipart/form-datastream.- Specified by:
getItemIteratorin interfaceUploadService- Parameters:
req- The servlet request to be parsed.- Returns:
- An iterator to instances of
FileItemStreamparsed from the request, in the order that they were transmitted. - Throws:
org.apache.avalon.framework.service.ServiceException- if there are problems reading/parsing the request or storing files. This may also be a network error while communicating with the client or a problem while storing the uploaded content.
-
parseRequest
public List<org.apache.commons.fileupload.FileItem> parseRequest(javax.portlet.ActionRequest req) throws org.apache.avalon.framework.service.ServiceException
Parses a RFC 1867 compliant
multipart/form-datastream.- Specified by:
parseRequestin interfaceUploadService- Parameters:
req- The portlet request to be parsed.- Returns:
- List of FileItem parts
- Throws:
org.apache.avalon.framework.service.ServiceException- Problems reading/parsing the request or storing the uploaded file(s).
-
parseRequest
public List<org.apache.commons.fileupload.FileItem> parseRequest(javax.portlet.ActionRequest req, String path) throws org.apache.avalon.framework.service.ServiceException
Parses a RFC 1867 compliant
multipart/form-datastream.- Specified by:
parseRequestin interfaceUploadService- Parameters:
req- The portlet request to be parsed.path- The location where the files should be stored.- Returns:
- List of FileItem parts
- Throws:
org.apache.avalon.framework.service.ServiceException- Problems reading/parsing the request or storing the uploaded file(s).
-
parseRequest
public List<org.apache.commons.fileupload.FileItem> parseRequest(javax.portlet.ActionRequest req, int sizeThreshold, int sizeMax, String path) throws org.apache.avalon.framework.service.ServiceException
Parses a RFC 1867 compliant
multipart/form-datastream.- Specified by:
parseRequestin interfaceUploadService- Parameters:
req- The portlet request to be parsed.sizeThreshold- the max size in bytes to be stored in memorysizeMax- the maximum allowed upload size in bytespath- The location where the files should be stored.- Returns:
- The list of FileItem parts uploaded
- Throws:
org.apache.avalon.framework.service.ServiceException- Problems reading/parsing the request or storing the uploaded file(s).
-
parseRequest
protected List<org.apache.commons.fileupload.FileItem> parseRequest(javax.portlet.ActionRequest req, int sizeMax, org.apache.commons.fileupload.disk.DiskFileItemFactory factory) throws org.apache.avalon.framework.service.ServiceException
Parses a RFC 1867 compliant
multipart/form-datastream.- Parameters:
req- The portlet request to be parsed.sizeMax- the maximum allowed upload size in bytesfactory- the file item factory to use- Returns:
- The list of FileItem parts uploaded
- Throws:
org.apache.avalon.framework.service.ServiceException- Problems reading/parsing the request or storing the uploaded file(s).
-
getItemIterator
public org.apache.commons.fileupload.FileItemIterator getItemIterator(javax.portlet.ActionRequest req) throws org.apache.avalon.framework.service.ServiceException
Processes an RFC 1867 compliantmultipart/form-datastream.- Specified by:
getItemIteratorin interfaceUploadService- Parameters:
req- The portlet request to be parsed.- Returns:
- An iterator to instances of
FileItemStreamparsed from the request, in the order that they were transmitted. - Throws:
org.apache.avalon.framework.service.ServiceException- if there are problems reading/parsing the request or storing files. This may also be a network error while communicating with the client or a problem while storing the uploaded content.
-
isMultipart
public boolean isMultipart(HttpServletRequest req)
Utility method that determines whether the request contains multipart content.- Specified by:
isMultipartin interfaceUploadService- Parameters:
req- The servlet request to be evaluated. Must be non-null.- Returns:
trueif the request is multipart;falseotherwise.
-
isMultipart
public boolean isMultipart(javax.portlet.ActionRequest req)
Utility method that determines whether the request contains multipart content.- Specified by:
isMultipartin interfaceUploadService- Parameters:
req- The portlet request to be evaluated. Must be non-null.- Returns:
trueif the request is multipart;falseotherwise.
-
configure
public void configure(org.apache.avalon.framework.configuration.Configuration conf)
Avalon component lifecycle method- Specified by:
configurein interfaceorg.apache.avalon.framework.configuration.Configurable
-
initialize
public void initialize() throws Exception
Avalon component lifecycle method Initializes the service. This method processes the repository path, to make it relative to the web application root, if necessary- Specified by:
initializein interfaceorg.apache.avalon.framework.activity.Initializable- Throws:
Exception
-
contextualize
public void contextualize(org.apache.avalon.framework.context.Context context) throws org.apache.avalon.framework.context.ContextException
Avalon component lifecycle method- Specified by:
contextualizein interfaceorg.apache.avalon.framework.context.Contextualizable- Throws:
org.apache.avalon.framework.context.ContextException
-
-