org.codehaus.waffle.io
Class RequestFileUploader

java.lang.Object
  extended by org.codehaus.waffle.io.RequestFileUploader
All Implemented Interfaces:
FileUploader, Startable

public class RequestFileUploader
extends java.lang.Object
implements Startable, FileUploader

Request-based FileUploader. The files are uploaded when the object is started. If there are any errors they are logged and retrievable via the getErrors() method. An action handling a multipart form should first check hasErrors() before doing any other processing.

Note that it is assumed that, by default, resource cleanup should be handled by the FileUpload's cleanup functionality, as detailed in the user guide. Custom behaviour can be introduced by overriding the stop() method.

Author:
Gleb Mazursky, Mauro Talevi

Field Summary
protected  java.util.Collection<java.lang.String> errors
           
protected  java.util.List<org.apache.commons.fileupload.FileItem> fileItems
           
 
Constructor Summary
RequestFileUploader(javax.servlet.http.HttpServletRequest request, org.apache.commons.fileupload.FileItemFactory itemFactory)
          Creates RequestFileUploader
 
Method Summary
 java.util.Collection<java.lang.String> getErrors()
          Returns errors generated when parsing the multipart request.
 java.util.List<org.apache.commons.fileupload.FileItem> getFiles()
          Returns the uploaded files
 java.util.List<org.apache.commons.fileupload.FileItem> getFormFields()
          Returns the form fields
 boolean hasErrors()
          Determines if any errors occured when parsing the multipart request
 void start()
          Upload files on request start
 void stop()
          Performs any additional operation on request stop.
protected  void uploadFileItems(javax.servlet.http.HttpServletRequest request, org.apache.commons.fileupload.FileItemFactory itemFactory)
          Parses a multipart request to upload file items and records any errors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

errors

protected java.util.Collection<java.lang.String> errors

fileItems

protected java.util.List<org.apache.commons.fileupload.FileItem> fileItems
Constructor Detail

RequestFileUploader

public RequestFileUploader(javax.servlet.http.HttpServletRequest request,
                           org.apache.commons.fileupload.FileItemFactory itemFactory)
Creates RequestFileUploader

Parameters:
request - the HttpServletRequest
itemFactory - the FileItemFactory
Method Detail

getFiles

public java.util.List<org.apache.commons.fileupload.FileItem> getFiles()
Description copied from interface: FileUploader
Returns the uploaded files

Specified by:
getFiles in interface FileUploader
Returns:
A List of FileItems, one for each uploaded file

getFormFields

public java.util.List<org.apache.commons.fileupload.FileItem> getFormFields()
Description copied from interface: FileUploader
Returns the form fields

Specified by:
getFormFields in interface FileUploader
Returns:
A List of FileItems, one for each form field

getErrors

public java.util.Collection<java.lang.String> getErrors()
Description copied from interface: FileUploader
Returns errors generated when parsing the multipart request.

Specified by:
getErrors in interface FileUploader
Returns:
the error Collection.

hasErrors

public boolean hasErrors()
Description copied from interface: FileUploader
Determines if any errors occured when parsing the multipart request

Specified by:
hasErrors in interface FileUploader
Returns:
true if any errors occured

start

public void start()
Upload files on request start

Specified by:
start in interface Startable

stop

public void stop()
Performs any additional operation on request stop.

Specified by:
stop in interface Startable

uploadFileItems

protected void uploadFileItems(javax.servlet.http.HttpServletRequest request,
                               org.apache.commons.fileupload.FileItemFactory itemFactory)
Parses a multipart request to upload file items and records any errors. Non-multipart requests are ignored.

Parameters:
request - the HttpServletRequest
itemFactory - the FileItemFactory


Copyright © 2008. All Rights Reserved.