org.apache.click.service
Class CommonsFileUploadService

java.lang.Object
  extended by org.apache.click.service.CommonsFileUploadService
All Implemented Interfaces:
FileUploadService

public class CommonsFileUploadService
extends Object
implements FileUploadService

Provides an Apache Commons FileUploadService class.

To prevent users from uploading exceedingly large files you can configure CommonsFileUploadService through the properties sizeMax and fileSizeMax.

For example:

 <file-upload-service>
     <!-- Set the total request maximum size to 10mb (10 x 1024 x 1024 = 10485760). -->
     <property name="sizeMax" value="10485760"/>

     <!-- Set the maximum individual file size to 2mb (2 x 1024 x 1024 = 2097152). -->
     <property name="fileSizeMax" value="2097152"/>
 </file-upload-service> 
Note that this is a global configuration and applies to the all file uploads of the application.

If you would like to specify a custom FileUploadService implementation use the classname attribute:

 <file-upload-service classname="com.mycorp.util.CustomFileUploadService">
     <property name="customProperty" value="customValue"/>
 </file-upload-service> 


Field Summary
protected  long fileSizeMax
          The maximum individual file size in bytes.
protected  long sizeMax
          The total request maximum size in bytes.
 
Fields inherited from interface org.apache.click.service.FileUploadService
UPLOAD_EXCEPTION
 
Constructor Summary
CommonsFileUploadService()
           
 
Method Summary
 FileItemFactory createFileItemFactory(HttpServletRequest request)
          Create and return a new Commons Upload FileItemFactory instance.
 long getFileSizeMax()
          Return maximum individual size in bytes.
 long getSizeMax()
          Return the total request maximum size in bytes.
 void onDestroy()
          Destroy the FileUploadService.
 void onInit(ServletContext servletContext)
          Initialize the FileUploadService with the given application servlet context.
 List<FileItem> parseRequest(HttpServletRequest request)
          Return a parsed list of FileItem from the request.
 void setFileSizeMax(long value)
          Set the maximum individual size in bytes.
 void setSizeMax(long value)
          Set the total request maximum size in bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sizeMax

protected long sizeMax
The total request maximum size in bytes. By default there is no limit.


fileSizeMax

protected long fileSizeMax
The maximum individual file size in bytes. By default there is no limit.

Constructor Detail

CommonsFileUploadService

public CommonsFileUploadService()
Method Detail

onInit

public void onInit(ServletContext servletContext)
            throws Exception
Description copied from interface: FileUploadService
Initialize the FileUploadService with the given application servlet context.

This method is invoked after the FileUploadService has been constructed.

Note you can access ConfigService by invoking ClickUtils.getConfigService(javax.servlet.ServletContext)

Specified by:
onInit in interface FileUploadService
Parameters:
servletContext - the application servlet context
Throws:
Exception - if an error occurs initializing the FileUploadService
See Also:
FileUploadService.onInit(ServletContext)

onDestroy

public void onDestroy()
Description copied from interface: FileUploadService
Destroy the FileUploadService.

Specified by:
onDestroy in interface FileUploadService
See Also:
FileUploadService.onDestroy()

parseRequest

public List<FileItem> parseRequest(HttpServletRequest request)
                            throws FileUploadException
Description copied from interface: FileUploadService
Return a parsed list of FileItem from the request.

Specified by:
parseRequest in interface FileUploadService
Parameters:
request - the servlet request
Returns:
the list of FileItem instances parsed from the request
Throws:
FileUploadException - if request cannot be parsed
See Also:
FileUploadService.parseRequest(HttpServletRequest)

getFileSizeMax

public long getFileSizeMax()
Return maximum individual size in bytes. By default there is no limit.

Returns:
the fileSizeMax

setFileSizeMax

public void setFileSizeMax(long value)
Set the maximum individual size in bytes. By default there is no limit.

Parameters:
value - the fileSizeMax to set

getSizeMax

public long getSizeMax()
Return the total request maximum size in bytes. By default there is no limit.

Returns:
the setSizeMax

setSizeMax

public void setSizeMax(long value)
Set the total request maximum size in bytes. By default there is no limit.

Parameters:
value - the setSizeMax to set

createFileItemFactory

public FileItemFactory createFileItemFactory(HttpServletRequest request)
Create and return a new Commons Upload FileItemFactory instance.

Parameters:
request - the servlet request
Returns:
a new Commons FileUpload FileItemFactory instance