org.codehaus.plexus.summit.parameters
Class BaseRequestParameterParser

java.lang.Object
  extended byorg.codehaus.plexus.logging.AbstractLogEnabled
      extended byorg.codehaus.plexus.summit.parameters.BaseRequestParameterParser
All Implemented Interfaces:
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable, org.codehaus.plexus.logging.LogEnabled, RequestParameterParser
Direct Known Subclasses:
SummitRequestParameterParser

public class BaseRequestParameterParser
extends org.codehaus.plexus.logging.AbstractLogEnabled
implements RequestParameterParser, org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable

Default implementation of a RequestParameterParser. This implementation uses the standard servlet method of parsing query info and post data to assemble a parameter map. In addition, any file uploads are processed and are made available via the returned RequestParameters object.

This component is thread-safe.

Author:
Ilkka Priha, Jon S. Stevens, Sean Legassick, Pete Kazmier

Field Summary
private  java.lang.String defaultEncoding
           
private  org.apache.commons.fileupload.DiskFileUpload fileUpload
          A file upload object used to parse uploaded files
private  int maxMemorySize
           
private  int maxUploadSize
           
private  java.lang.String tempDirectory
           
 
Fields inherited from class org.codehaus.plexus.logging.AbstractLogEnabled
 
Fields inherited from interface org.codehaus.plexus.summit.parameters.RequestParameterParser
ROLE
 
Constructor Summary
BaseRequestParameterParser()
           
 
Method Summary
protected  void addFileItem(java.util.Map parameterMap, java.lang.String name, org.apache.commons.fileupload.FileItem item)
          Add a FileItem to the specified parameter map ensuring that the value is stored as an array of FileItems even if there is only a single parameter.
protected  void addParameter(java.util.Map parameterMap, java.lang.String name, java.lang.String value)
          Add a parameter to the specified parameter map ensuring that the value is stored as an array of Strings even if there is only a single parameter.
protected  void doParse(javax.servlet.http.HttpServletRequest request, java.util.Map parameterMap)
          Invoked as part of the parse template method to provide a hook for additional parsing of parameters.
private  java.lang.String getFormField(org.apache.commons.fileupload.FileItem item, java.lang.String encoding)
          Get the value of a form field that is part of a FileItem using the specified encoding.
 void initialize()
           
 RequestParameters parse(javax.servlet.http.HttpServletRequest request)
          Parses the query info for the parameters associated with this request as well as any uploaded files sent with the HTTP request.
private  void processFileUploadItems(javax.servlet.http.HttpServletRequest request, java.util.Map parameterMap, java.lang.String encoding)
          Process the specified HTTP request for uploaded files sent via a mime multipart request.
private  void processQueryInfo(javax.servlet.http.HttpServletRequest request, java.util.Map parameterMap)
          Process the specified HTTP request for name/value pairs encoded within the query info.
 
Methods inherited from class org.codehaus.plexus.logging.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileUpload

private org.apache.commons.fileupload.DiskFileUpload fileUpload
A file upload object used to parse uploaded files


maxUploadSize

private int maxUploadSize

maxMemorySize

private int maxMemorySize

tempDirectory

private java.lang.String tempDirectory

defaultEncoding

private java.lang.String defaultEncoding
Constructor Detail

BaseRequestParameterParser

public BaseRequestParameterParser()
Method Detail

initialize

public void initialize()
                throws org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
Specified by:
initialize in interface org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
Throws:
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException

parse

public RequestParameters parse(javax.servlet.http.HttpServletRequest request)
Parses the query info for the parameters associated with this request as well as any uploaded files sent with the HTTP request. Note: This parser does not inspect the path info for name/value pairs as the Turbine does. If you want the path info parsed for parameters, use the SummitRequestParameterParser instead.

Implementation note: This method is a template method and provides a hook that implementors may use for additional parsing of the request. This method does the following:

Specified by:
parse in interface RequestParameterParser
Parameters:
request - The HTTP request to parse for parameters.
Returns:
RequestParameters The requested parameters wrapped in a RequestParameters object for easy access to the parameters.
See Also:
RequestParameterParser.parse(javax.servlet.http.HttpServletRequest)

doParse

protected void doParse(javax.servlet.http.HttpServletRequest request,
                       java.util.Map parameterMap)
Invoked as part of the parse template method to provide a hook for additional parsing of parameters. The HTTP request is passed as an argument as well as a map which is acting as a collector argument. The map contains name/value pairs where each name is a String representing the parameter name, and the value is an array of either Strings or FileItems representing the value of the parameter. Note: the value must be an array even if there is only a single value.

Parameters:
request - The HTTP request to parse for parameters.
parameterMap - A map of the collected parameters which should be used to store additional parameters in the format described above. A helper method has been provided to ensure the values are stored as arrays (see addParameter).

processFileUploadItems

private void processFileUploadItems(javax.servlet.http.HttpServletRequest request,
                                    java.util.Map parameterMap,
                                    java.lang.String encoding)
Process the specified HTTP request for uploaded files sent via a mime multipart request. Each file is parsed and stored in the specified parameter map as an array of FileItems. Form fields part of the multipart request are also decoded and stored in the parameter map as arrays of Strings.

Parameters:
request - The HTTP request to be parsed.
parameterMap - The parameter map which is populated with the uploaded files and/or form fields.
encoding - The encoding to use when decoding a form field parameter.

processQueryInfo

private void processQueryInfo(javax.servlet.http.HttpServletRequest request,
                              java.util.Map parameterMap)
Process the specified HTTP request for name/value pairs encoded within the query info. Each parsed pair is stored in the supplied parameter map.

Parameters:
request - The HTTP request to be parsed.
parameterMap - The parameter map which is populated with the parsed name/value pairs.

addFileItem

protected void addFileItem(java.util.Map parameterMap,
                           java.lang.String name,
                           org.apache.commons.fileupload.FileItem item)
Add a FileItem to the specified parameter map ensuring that the value is stored as an array of FileItems even if there is only a single parameter.

Parameters:
parameterMap - The map which the parameter should be added.
name - The name of the parameter.
item - The file item associated with the parameter.

addParameter

protected void addParameter(java.util.Map parameterMap,
                            java.lang.String name,
                            java.lang.String value)
Add a parameter to the specified parameter map ensuring that the value is stored as an array of Strings even if there is only a single parameter.

Parameters:
parameterMap - The map which the parameter should be added.
name - The name of the parameter.
value - The value of the parameter.

getFormField

private java.lang.String getFormField(org.apache.commons.fileupload.FileItem item,
                                      java.lang.String encoding)
Get the value of a form field that is part of a FileItem using the specified encoding.

Parameters:
item - The file item which contains a form value instead of a file upload.
encoding - The encoding to use when getting the form value.
Returns:
String The form value encoded in the specified encoding.