org.apache.turbine.util.parser
Class DefaultParameterParser

java.lang.Object
  extended byorg.apache.turbine.util.pool.RecyclableSupport
      extended byorg.apache.turbine.util.parser.BaseValueParser
          extended byorg.apache.turbine.util.parser.DefaultParameterParser
All Implemented Interfaces:
ParameterParser, Recyclable, ValueParser

public class DefaultParameterParser
extends BaseValueParser
implements ParameterParser, Recyclable

DefaultParameterParser is a utility object to handle parsing and retrieving the data passed via the GET/POST/PATH_INFO arguments.

NOTE: The name= portion of a name=value pair may be converted to lowercase or uppercase when the object is initialized and when new data is added. This behaviour is determined by the url.case.folding property in TurbineResources.properties. Adding a name/value pair may overwrite existing name=value pairs if the names match:

 ParameterParser pp = data.getParameters();
 pp.add("ERROR",1);
 pp.add("eRrOr",2);
 int result = pp.getInt("ERROR");
 
In the above example, result is 2.

Version:
$Id: DefaultParameterParser.java 534527 2007-05-02 16:10:59Z tv $
Author:
Ilkka Priha, Jon S. Stevens, Sean Legassick, Henning P. Schmiedehausen

Field Summary
 
Fields inherited from interface org.apache.turbine.util.parser.ValueParser
URL_CASE_FOLDING, URL_CASE_FOLDING_LOWER, URL_CASE_FOLDING_NONE, URL_CASE_FOLDING_UPPER
 
Constructor Summary
DefaultParameterParser()
          Create a new empty instance of ParameterParser.
DefaultParameterParser(java.lang.String characterEncoding)
          Create a new empty instance of ParameterParser.
 
Method Summary
 void add(java.lang.String name, org.apache.commons.fileupload.FileItem item)
          Add a FileItem object as a parameters.
 void append(java.lang.String name, org.apache.commons.fileupload.FileItem item)
          Deprecated. Use add(String name, FileItem item)
 boolean containsKey(java.lang.Object key)
          Determine whether a given key has been inserted.
 void dispose()
          Disposes the parser.
 org.apache.commons.fileupload.FileItem getFileItem(java.lang.String name)
          Return a FileItem object for the given name.
protected  org.apache.commons.fileupload.FileItem[] getFileItemParam(java.lang.String name)
          fetches a key from the parameters map.
 org.apache.commons.fileupload.FileItem[] getFileItems(java.lang.String name)
          Return an array of FileItem objects for the given name.
 javax.servlet.http.HttpServletRequest getRequest()
          Gets the parsed servlet request.
protected  java.lang.Object[] getToStringParam(java.lang.String name)
          This method is only used in toString() and can be used by derived classes to add their local parameters to the toString()
 byte[] getUploadData()
          Gets the uploadData byte[]
 java.util.Set keySet()
          Gets the set of keys (FileItems and regular parameters)
protected  void putFileItemParam(java.lang.String name, org.apache.commons.fileupload.FileItem[] value)
          Puts a key into the parameters map.
 void setRequest(javax.servlet.http.HttpServletRequest request)
          Sets the servlet request to the parser.
 void setUploadData(byte[] uploadData)
          Sets the uploadData byte[]
 
Methods inherited from class org.apache.turbine.util.parser.BaseValueParser
add, add, add, add, add, add, append, clear, containsDateSelectorKeys, containsTimeSelectorKeys, convert, convertAndTrim, get, getBigDecimal, getBigDecimal, getBigDecimals, getBool, getBool, getBoolean, getBoolean, getBooleanObject, getBooleanObject, getBooleanObjects, getBooleans, getByte, getByte, getByteObject, getByteObject, getBytes, getCharacterEncoding, getDate, getDate, getDate, getDateFormat, getDouble, getDouble, getDoubleObject, getDoubleObject, getDoubleObjects, getDoubles, getFloat, getFloat, getFloatObject, getFloatObject, getFloatObjects, getFloats, getInt, getInt, getInteger, getInteger, getInteger, getIntegers, getIntObject, getIntObject, getIntObjects, getInts, getKeys, getLocale, getLong, getLong, getLongObject, getLongObject, getLongObjects, getLongs, getNumberFormat, getNumberKey, getObject, getObjects, getParam, getString, getString, getStringKey, getStrings, getStrings, keys, putParam, recycle, remove, setCharacterEncoding, setDateFormat, setLocale, setNumberFormat, setProperties, setProperty, setString, setStrings, toString
 
Methods inherited from class org.apache.turbine.util.pool.RecyclableSupport
doDispose, isDisposed, Recyclable, recycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.util.parser.ValueParser
add, add, add, add, add, add, append, clear, containsDateSelectorKeys, convert, get, getBigDecimal, getBigDecimal, getBigDecimals, getBool, getBool, getBoolean, getBoolean, getBooleanObject, getBooleanObject, getBooleanObjects, getBooleans, getByte, getByte, getByteObject, getByteObject, getBytes, getCharacterEncoding, getDate, getDate, getDate, getDateFormat, getDouble, getDouble, getDoubleObject, getDoubleObject, getDoubleObjects, getDoubles, getFloat, getFloat, getFloatObject, getFloatObject, getFloatObjects, getFloats, getInt, getInt, getInteger, getInteger, getInteger, getIntegers, getIntObject, getIntObject, getIntObjects, getInts, getKeys, getLocale, getLong, getLong, getLongObject, getLongObject, getLongObjects, getLongs, getNumberFormat, getNumberKey, getObject, getObjects, getString, getString, getStringKey, getStrings, getStrings, keys, remove, setCharacterEncoding, setDateFormat, setLocale, setNumberFormat, setProperties, setString, setStrings, toString
 
Methods inherited from interface org.apache.turbine.util.pool.Recyclable
isDisposed, recycle
 

Constructor Detail

DefaultParameterParser

public DefaultParameterParser()
Create a new empty instance of ParameterParser. Uses the default character encoding (US-ASCII).

To add name/value pairs to this set of parameters, use the add() methods.


DefaultParameterParser

public DefaultParameterParser(java.lang.String characterEncoding)
Create a new empty instance of ParameterParser. Takes a character encoding name to use when converting strings to bytes.

To add name/value pairs to this set of parameters, use the add() methods.

Parameters:
characterEncoding - The character encoding of strings.
Method Detail

dispose

public void dispose()
Disposes the parser.

Specified by:
dispose in interface Recyclable
Overrides:
dispose in class BaseValueParser

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Gets the parsed servlet request.

Specified by:
getRequest in interface ParameterParser
Returns:
the parsed servlet request or null.

setRequest

public void setRequest(javax.servlet.http.HttpServletRequest request)
Sets the servlet request to the parser. This requires a valid HttpServletRequest object. It will attempt to parse out the GET/POST/PATH_INFO data and store the data into a Map. There are convenience methods for retrieving the data as a number of different datatypes. The PATH_INFO data must be a URLEncoded() string.

To add name/value pairs to this set of parameters, use the add() methods.

Specified by:
setRequest in interface ParameterParser
Parameters:
request - An HttpServletRequest.

setUploadData

public void setUploadData(byte[] uploadData)
Sets the uploadData byte[]

Specified by:
setUploadData in interface ParameterParser
Parameters:
uploadData - A byte[] with data.

getUploadData

public byte[] getUploadData()
Gets the uploadData byte[]

Specified by:
getUploadData in interface ParameterParser
Returns:
uploadData A byte[] with data.

append

public void append(java.lang.String name,
                   org.apache.commons.fileupload.FileItem item)
Deprecated. Use add(String name, FileItem item)

Add a FileItem object as a parameters. If there are any FileItems already associated with the name, append to the array. The reason for this is that RFC 1867 allows multiple files to be associated with single HTML input element.

Specified by:
append in interface ParameterParser
Parameters:
name - A String with the name.
item - A FileItem with the value.

add

public void add(java.lang.String name,
                org.apache.commons.fileupload.FileItem item)
Add a FileItem object as a parameters. If there are any FileItems already associated with the name, append to the array. The reason for this is that RFC 1867 allows multiple files to be associated with single HTML input element.

Specified by:
add in interface ParameterParser
Parameters:
name - A String with the name.
item - A FileItem with the value.

keySet

public java.util.Set keySet()
Gets the set of keys (FileItems and regular parameters)

Specified by:
keySet in interface ValueParser
Overrides:
keySet in class BaseValueParser
Returns:
A Set of the keys.

containsKey

public boolean containsKey(java.lang.Object key)
Determine whether a given key has been inserted. All keys are stored in lowercase strings, so override method to account for this.

Specified by:
containsKey in interface ValueParser
Overrides:
containsKey in class BaseValueParser
Parameters:
key - An Object with the key to search for.
Returns:
True if the object is found.

getFileItem

public org.apache.commons.fileupload.FileItem getFileItem(java.lang.String name)
Return a FileItem object for the given name. If the name does not exist or the object stored is not a FileItem, return null.

Specified by:
getFileItem in interface ParameterParser
Parameters:
name - A String with the name.
Returns:
A FileItem.

getFileItems

public org.apache.commons.fileupload.FileItem[] getFileItems(java.lang.String name)
Return an array of FileItem objects for the given name. If the name does not exist, return null.

Specified by:
getFileItems in interface ParameterParser
Parameters:
name - A String with the name.
Returns:
An Array of FileItems or null.

putFileItemParam

protected void putFileItemParam(java.lang.String name,
                                org.apache.commons.fileupload.FileItem[] value)
Puts a key into the parameters map. Makes sure that the name is always mapped correctly. This method also enforces the usage of arrays for the parameters.

Parameters:
name - A String with the name.
value - An array of Objects with the values.

getFileItemParam

protected org.apache.commons.fileupload.FileItem[] getFileItemParam(java.lang.String name)
fetches a key from the parameters map. Makes sure that the name is always mapped correctly.

Parameters:
name - A string with the name
Returns:
the value object array or null if not set

getToStringParam

protected java.lang.Object[] getToStringParam(java.lang.String name)
This method is only used in toString() and can be used by derived classes to add their local parameters to the toString()

Overrides:
getToStringParam in class BaseValueParser
Parameters:
name - A string with the name
Returns:
the value object array or null if not set


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.