org.apache.tapestry.multipart
Class DefaultMultipartDecoder

java.lang.Object
  |
  +--org.apache.tapestry.multipart.DefaultMultipartDecoder
All Implemented Interfaces:
IMultipartDecoder

public class DefaultMultipartDecoder
extends java.lang.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 Uploadcomponent needs).

Since:
2.0.1
Author:
Joe Panico

Field Summary
static java.lang.String PART_MAP_ATTRIBUTE_NAME
          Request attribute key used to store the part map for this request.
static java.lang.String STRING_NAMES_ATTRIBUTE_NAME
           
 
Constructor Summary
DefaultMultipartDecoder()
           
 
Method Summary
 void cleanup(javax.servlet.http.HttpServletRequest request)
          Invokes IPart.cleanup()on each part.
 void decode(javax.servlet.http.HttpServletRequest request)
          Decodes the request, storing the part map (keyed on query parameter name, value is IPartinto the request as an attribute.
 int getMaxSize()
           
 java.lang.String getRepositoryPath()
           
static DefaultMultipartDecoder getSharedInstance()
           
 java.lang.String getString(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Returns the single value (or first value) for the parameter with the specified name.
 java.lang.String[] getStringParameterNames(javax.servlet.http.HttpServletRequest request)
          Returns the names of all parameters whose type is string (not file upload).
 java.lang.String[] getStrings(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Returns an array of values (possibly a single element array).
 int getThresholdSize()
           
 IUploadFile getUploadFile(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Returns the uploaded file with the specified parameter name, or null if no such parameter was in the request.
static boolean isMultipartRequest(javax.servlet.http.HttpServletRequest request)
           
 void setMaxSize(int maxSize)
           
 void setRepositoryPath(java.lang.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 java.lang.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

STRING_NAMES_ATTRIBUTE_NAME

public static final java.lang.String STRING_NAMES_ATTRIBUTE_NAME
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(java.lang.String repositoryPath)

getRepositoryPath

public java.lang.String getRepositoryPath()

isMultipartRequest

public static boolean isMultipartRequest(javax.servlet.http.HttpServletRequest request)

cleanup

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

Specified by:
cleanup in interface IMultipartDecoder

decode

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

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

getString

public java.lang.String getString(javax.servlet.http.HttpServletRequest request,
                                  java.lang.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 java.lang.String[] getStrings(javax.servlet.http.HttpServletRequest request,
                                     java.lang.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

getStringParameterNames

public java.lang.String[] getStringParameterNames(javax.servlet.http.HttpServletRequest request)
Description copied from interface: IMultipartDecoder
Returns the names of all parameters whose type is string (not file upload).

Specified by:
getStringParameterNames in interface IMultipartDecoder
Since:
3.1

getUploadFile

public IUploadFile getUploadFile(javax.servlet.http.HttpServletRequest request,
                                 java.lang.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