Expresso 5-6

com.jcorporate.expresso.core.misc.upload
Class Uploader

java.lang.Object
  extended bycom.jcorporate.expresso.core.misc.upload.Uploader
All Implemented Interfaces:
org.apache.struts.upload.MultipartRequestHandler

public class Uploader
extends Object
implements org.apache.struts.upload.MultipartRequestHandler

Files will be stored in temporary disk storage

This implementation of Uploader handles multiple files per single html widget, sent using multipar/mixed encoding type, as specified by RFC 1867. Use org.apache.turbine.util.ParameterParser#getFileItems(String) to acquire an array of org.apache.turbine.util.upload.FileItems associated with given html widget.

Author:
Rafal Krzewski

Field Summary
static int MAX_HEADER_SIZE
          A maximum lenght of a single header line that will be parsed. (1024 bytes).
 
Fields inherited from interface org.apache.struts.upload.MultipartRequestHandler
ATTRIBUTE_MAX_LENGTH_EXCEEDED
 
Constructor Summary
Uploader()
           
 
Method Summary
protected  FileItem createItem(String path, int requestSize, boolean storeAsFile)
           Creates a new instance of a FileItem.
 void finish()
          This method is called on when a successful form post has been made.
 Hashtable getAllElements()
          This method returns all elements of a multipart request.
protected  String getFieldName()
           Retrieves field name from 'Content-disposition' header.
 Hashtable getFileElements()
          This method is called on to retrieve all the FormFile input elements of the request.
protected  String getFileName()
           Retrieves file name from 'Content-disposition' header.
protected  String getHeader(String name)
           Returns a header with specified name.
 org.apache.struts.action.ActionMapping getMapping()
          Get the ActionMapping instance for this request
 org.apache.struts.action.ActionServlet getServlet()
          Get the ActionServlet instance
 Hashtable getTextElements()
          This method is called on to retrieve all the text input elements of the request.
 void handleRequest(HttpServletRequest request)
          After constructed, this is the first method called on by ActionServlet.
protected  void parseHeaders(String headerPart)
           Parses the header-part and stores as key - value pairs.
 void parseRequest(HttpServletRequest req, ParameterParser params, String path)
          Processes an RFC 1867 compliant multipart/form-data stream.
 void rollback()
          This method is called on when there's some sort of problem and the form post needs to be rolled back.
 void setMapping(org.apache.struts.action.ActionMapping mapping)
          Convienience method to set a reference to a working ActionMapping instance.
 void setServlet(org.apache.struts.action.ActionServlet servlet)
          Convienience method to set a reference to a working ActionServlet instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_HEADER_SIZE

public static final int MAX_HEADER_SIZE
A maximum lenght of a single header line that will be parsed. (1024 bytes).

See Also:
Constant Field Values
Constructor Detail

Uploader

public Uploader()
Method Detail

parseRequest

public void parseRequest(HttpServletRequest req,
                         ParameterParser params,
                         String path)
                  throws ControllerException
Processes an RFC 1867 compliant multipart/form-data stream.

Parameters:
req - The servlet request to be parsed.
params - The ParameterParser instance to insert form fields into.
path - The location where the files should be stored.
Throws:
ControllerException - If there are problems reading/parsing the request or storing files.

getFieldName

protected String getFieldName()

Retrieves field name from 'Content-disposition' header.

Returns:
A String with the field name for the current encapsulation.

getFileName

protected String getFileName()

Retrieves file name from 'Content-disposition' header.

Returns:
A String with the file name for the current encapsulation.

createItem

protected FileItem createItem(String path,
                              int requestSize,
                              boolean storeAsFile)

Creates a new instance of a FileItem.

Parameters:
path - The path for the FileItem.
requestSize - The size of the request.
Returns:
A newly created FileItem.

parseHeaders

protected void parseHeaders(String headerPart)

Parses the header-part and stores as key - value pairs.

If there are multiple headers of the same names, the name will map to a comma-separated list containing the values.

Parameters:
headerPart - The header-part of the current encapsulation.

getHeader

protected String getHeader(String name)

Returns a header with specified name.

Parameters:
name - The name of the header to fetch.
Returns:
The value of specified header, or a comma-separated list if there were multiple headers of that name.

setServlet

public void setServlet(org.apache.struts.action.ActionServlet servlet)
Convienience method to set a reference to a working ActionServlet instance.

Specified by:
setServlet in interface org.apache.struts.upload.MultipartRequestHandler

setMapping

public void setMapping(org.apache.struts.action.ActionMapping mapping)
Convienience method to set a reference to a working ActionMapping instance.

Specified by:
setMapping in interface org.apache.struts.upload.MultipartRequestHandler

getServlet

public org.apache.struts.action.ActionServlet getServlet()
Get the ActionServlet instance

Specified by:
getServlet in interface org.apache.struts.upload.MultipartRequestHandler

getMapping

public org.apache.struts.action.ActionMapping getMapping()
Get the ActionMapping instance for this request

Specified by:
getMapping in interface org.apache.struts.upload.MultipartRequestHandler

handleRequest

public void handleRequest(HttpServletRequest request)
                   throws ServletException
After constructed, this is the first method called on by ActionServlet. Use this method for all your data-parsing of the ServletInputStream in the request

Specified by:
handleRequest in interface org.apache.struts.upload.MultipartRequestHandler
Throws:
ServletException - thrown if something goes wrong

getTextElements

public Hashtable getTextElements()
This method is called on to retrieve all the text input elements of the request.

Specified by:
getTextElements in interface org.apache.struts.upload.MultipartRequestHandler
Returns:
A Hashtable where the keys and values are the names and values of the request input parameters

getFileElements

public Hashtable getFileElements()
This method is called on to retrieve all the FormFile input elements of the request.

Specified by:
getFileElements in interface org.apache.struts.upload.MultipartRequestHandler
Returns:
A Hashtable where the keys are the input names of the files and the values are FormFile objects
See Also:
FormFile

getAllElements

public Hashtable getAllElements()
This method returns all elements of a multipart request.

Specified by:
getAllElements in interface org.apache.struts.upload.MultipartRequestHandler
Returns:
A Hashtable where the keys are input names and values are either Strings or FormFiles

rollback

public void rollback()
This method is called on when there's some sort of problem and the form post needs to be rolled back. Providers should remove any FormFiles used to hold information by setting them to null and also physically delete them if the implementation calls for writing directly to disk. NOTE: Currently implemented but not automatically supported, ActionForm implementors must call rollback() manually for rolling back file uploads.

Specified by:
rollback in interface org.apache.struts.upload.MultipartRequestHandler

finish

public void finish()
This method is called on when a successful form post has been made. Some implementations will use this to destroy temporary files or write to a database or something of that nature

Specified by:
finish in interface org.apache.struts.upload.MultipartRequestHandler

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.