org.apache.tapestry.multipart
Class DefaultMultipartDecoder

java.lang.Object
  extended by org.apache.tapestry.multipart.DefaultMultipartDecoder
All Implemented Interfaces:
IMultipartDecoder

public class DefaultMultipartDecoder
extends Object
implements IMultipartDecoder

Decodes the data in a multipart/form-data HTTP request, handling file uploads and multi-valued parameters. After decoding, the class is used to access the parameter values.

This implementation is a thin wrapper around the Apache Jakarta FileUpload.

Supports single valued parameters, multi-valued parameters and individual file uploads. That is, for file uploads, each upload must be a unique parameter (that is all the Upload component needs).

Since:
2.0.1
Version:
$Id: DefaultMultipartDecoder.java 243791 2004-02-19 17:38:13Z hlship $
Author:
Joe Panico

Field Summary
static String PART_MAP_ATTRIBUTE_NAME
          Request attribute key used to store the part map for this request.
 
Constructor Summary
DefaultMultipartDecoder()
           
 
Method Summary
 void cleanup(HttpServletRequest request)
          Invokes IPart.cleanup() on each part.
 void decode(HttpServletRequest request)
          Decodes the request, storing the part map (keyed on query parameter name, value is IPart into the request as an attribute.
 int getMaxSize()
           
 String getRepositoryPath()
           
static DefaultMultipartDecoder getSharedInstance()
           
 String getString(HttpServletRequest request, String name)
          Returns the single value (or first value) for the parameter with the specified name.
 String[] getStrings(HttpServletRequest request, String name)
          Returns an array of values (possibly a single element array).
 int getThresholdSize()
           
 IUploadFile getUploadFile(HttpServletRequest request, String name)
          Returns the uploaded file with the specified parameter name, or null if no such parameter was in the request.
static boolean isMultipartRequest(HttpServletRequest request)
           
 void setMaxSize(int maxSize)
           
 void setRepositoryPath(String repositoryPath)
           
 void setThresholdSize(int thresholdSize)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PART_MAP_ATTRIBUTE_NAME

public static final String PART_MAP_ATTRIBUTE_NAME
Request attribute key used to store the part map for this request. The part map is created in decode(HttpServletRequest). By storing the part map in the request instead of an instance variable, DefaultMultipartDecoder becomes threadsafe (no client-specific state in instance variables).

See Also:
Constant Field Values
Constructor Detail

DefaultMultipartDecoder

public DefaultMultipartDecoder()
Method Detail

getSharedInstance

public static DefaultMultipartDecoder getSharedInstance()

setMaxSize

public void setMaxSize(int maxSize)

getMaxSize

public int getMaxSize()

setThresholdSize

public void setThresholdSize(int thresholdSize)

getThresholdSize

public int getThresholdSize()

setRepositoryPath

public void setRepositoryPath(String repositoryPath)

getRepositoryPath

public String getRepositoryPath()

isMultipartRequest

public static boolean isMultipartRequest(HttpServletRequest request)

cleanup

public void cleanup(HttpServletRequest request)
Invokes IPart.cleanup() on each part.

Specified by:
cleanup in interface IMultipartDecoder

decode

public void decode(HttpServletRequest request)
Decodes the request, storing the part map (keyed on query parameter name, value is IPart into the request as an attribute.

Specified by:
decode in interface IMultipartDecoder
Throws:
ApplicationRuntimeException - if decode fails, for instance the request exceeds getMaxSize()

getString

public String getString(HttpServletRequest request,
                        String name)
Description copied from interface: IMultipartDecoder
Returns the single value (or first value) for the parameter with the specified name. Returns null if no such parameter was in the request.

Specified by:
getString in interface IMultipartDecoder

getStrings

public String[] getStrings(HttpServletRequest request,
                           String name)
Description copied from interface: IMultipartDecoder
Returns an array of values (possibly a single element array). Returns null if no such parameter was in the request.

Specified by:
getStrings in interface IMultipartDecoder

getUploadFile

public IUploadFile getUploadFile(HttpServletRequest request,
                                 String name)
Description copied from interface: IMultipartDecoder
Returns the uploaded file with the specified parameter name, or null if no such parameter was in the request.

Specified by:
getUploadFile in interface IMultipartDecoder