| java.lang.Object org.apache.turbine.util.pool.RecyclableSupport org.apache.turbine.util.parser.BaseValueParser
All known Subclasses: org.apache.turbine.util.parser.DefaultCookieParser, org.apache.turbine.util.parser.DefaultParameterParser,
BaseValueParser | public class BaseValueParser extends RecyclableSupport implements ValueParser(Code) | | BaseValueParser is a base class for classes that need to parse
name/value Parameters, for example GET/POST data or Cookies
(DefaultParameterParser and DefaultCookieParser).
It can also be used standalone, for an example see DataStreamParser.
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:
ValueParser vp = new BaseValueParser();
vp.add("ERROR",1);
vp.add("eRrOr",2);
int result = vp.getInt("ERROR");
In the above example, result is 2.
author: Ilkka Priha author: Jon S. Stevens author: Sean Legassick author: Jason van Zyl author: Scott Eade author: Henning P. Schmiedehausen author: Quinton McCombs version: $Id: BaseValueParser.java 534527 2007-05-02 16:10:59Z tv $ |
Method Summary | |
public void | add(String name, double value) Add a name/value pair into this object. | public void | add(String name, int value) Add a name/value pair into this object. | public void | add(String name, Integer value) Add a name/value pair into this object. | public void | add(String name, long value) Add a name/value pair into this object. | public void | add(String name, String value) Add a name/value pair into this object. | public void | add(String name, String[] value) Add an array of Strings for a key. | public void | append(String name, String value) Add a String parameters. | public void | clear() Clear all name/value pairs out of this object. | public boolean | containsDateSelectorKeys(String key) Check for existence of key_day, key_month and key_year
parameters (as returned by DateSelector generated HTML).
Parameters: key - A String with the selector name. | public boolean | containsKey(Object key) Determine whether a given key has been inserted. | public boolean | containsTimeSelectorKeys(String key) Check for existence of key_hour, key_minute and key_second
parameters (as returned by TimeSelector generated HTML).
Parameters: key - A String with the selector name. | public String | convert(String value) Trims the string data and applies the conversion specified in
the property given by URL_CASE_FOLDING. | public static String | convertAndTrim(String value) A static version of the convert method, which
trims the string data and applies the conversion specified in
the property given by URL_CASE_FOLDING. | public void | dispose() Disposes the parser. | public String | get(String name) Return a String for the given name. | public BigDecimal | getBigDecimal(String name, BigDecimal defaultValue) Return a BigDecimal for the given name. | public BigDecimal | getBigDecimal(String name) Return a BigDecimal for the given name. | public BigDecimal[] | getBigDecimals(String name) Return an array of BigDecimals for the given name. | public Boolean | getBool(String name, boolean defaultValue) Return a Boolean for the given name. | public Boolean | getBool(String name) Return a Boolean for the given name. | public boolean | getBoolean(String name, boolean defaultValue) Return a boolean for the given name. | public boolean | getBoolean(String name) Return a boolean for the given name. | public Boolean | getBooleanObject(String name) Returns a Boolean object for the given name. | public Boolean | getBooleanObject(String name, Boolean defaultValue) Returns a Boolean object for the given name. | public byte | getByte(String name, byte defaultValue) Return a byte for the given name. | public byte | getByte(String name) Return a byte for the given name. | public Byte | getByteObject(String name, Byte defaultValue) Return a byte for the given name. | public Byte | getByteObject(String name) Return a byte for the given name. | public byte[] | getBytes(String name) Return an array of bytes for the given name. | public String | getCharacterEncoding() Get the character encoding that will be used by this ValueParser. | public Date | getDate(String name, DateFormat df, Date defaultValue) Returns a
java.util.Date object. | public Date | getDate(String name) Returns a
java.util.Date object. | public Date | getDate(String name, DateFormat df) Returns a
java.util.Date object. | public double | getDouble(String name, double defaultValue) Return a double for the given name. | public double | getDouble(String name) Return a double for the given name. | public Double | getDoubleObject(String name, Double defaultValue) Return a Double for the given name. | public Double | getDoubleObject(String name) Return a Double for the given name. | public Double[] | getDoubleObjects(String name) Return an array of doubles for the given name. | public double[] | getDoubles(String name) Return an array of doubles for the given name. | public float | getFloat(String name, float defaultValue) Return a float for the given name. | public float | getFloat(String name) Return a float for the given name. | public Float | getFloatObject(String name, Float defaultValue) Return a Float for the given name. | public Float | getFloatObject(String name) Return a float for the given name. | public Float[] | getFloatObjects(String name) Return an array of floats for the given name. | public float[] | getFloats(String name) Return an array of floats for the given name. | public int | getInt(String name, int defaultValue) Return an int for the given name. | public int | getInt(String name) Return an int for the given name. | public Integer | getIntObject(String name, Integer defaultValue) Return an Integer for the given name. | public Integer | getIntObject(String name) Return an Integer for the given name. | public Integer[] | getIntObjects(String name) Return an array of Integers for the given name. | public Integer | getInteger(String name, int defaultValue) Return an Integer for the given name. | public Integer | getInteger(String name, Integer def) Return an Integer for the given name. | public Integer | getInteger(String name) Return an Integer for the given name. | public Integer[] | getIntegers(String name) Return an array of Integers for the given name. | public int[] | getInts(String name) Return an array of ints for the given name. | public Object[] | getKeys() Returns all the available parameter names. | public long | getLong(String name, long defaultValue) Return a long for the given name. | public long | getLong(String name) Return a long for the given name. | public Long | getLongObject(String name) Return a Long for the given name. | public Long | getLongObject(String name, Long defaultValue) Return a Long for the given name. | public Long[] | getLongObjects(String name) Return an array of Longs for the given name. | public long[] | getLongs(String name) Return an array of longs for the given name. | public NumberKey | getNumberKey(String name) Return an NumberKey for the given name. | public Object | getObject(String name) Return an Object for the given name. | public Object[] | getObjects(String name) Return an array of Objects for the given name. | protected String[] | getParam(String name) fetches a key from the parameters map. | public String | getString(String name) Return a String for the given name. | public String | getString(String name, String defaultValue) Return a String for the given name. | public StringKey | getStringKey(String name) Return an StringKey for the given name. | public String[] | getStrings(String name) Return an array of Strings for the given name. | public String[] | getStrings(String name, String[] defaultValue) Return an array of Strings for the given name. | protected Object[] | getToStringParam(String name) | public Set | keySet() | public Enumeration | keys() Get an enumerator for the parameter keys. | protected void | putParam(String name, String[] value) Puts a key into the parameters map. | public void | recycle(String characterEncoding) Recycles the parser with a character encoding. | public Object | remove(String name) Removes the named parameter from the contained hashtable. | public void | setCharacterEncoding(String s) Set the character encoding that will be used by this ValueParser. | public void | setProperties(Object bean) Uses bean introspection to set writable properties of bean from
the parameters, where a (case-insensitive) name match between
the bean property and the parameter is looked for. | protected void | setProperty(Object bean, PropertyDescriptor prop) Set the property 'prop' in the bean to the value of the
corresponding parameters. | public void | setString(String name, String value) Set a parameter to a specific value. | public void | setStrings(String name, String[] values) Set a parameter to a specific value. | public String | toString() Simple method that attempts to get a textual representation of
this object's name/value pairs. |
BaseValueParser | public BaseValueParser()(Code) | | Default constructor
|
BaseValueParser | public BaseValueParser(String characterEncoding)(Code) | | Constructor that takes a character encoding
|
add | public void add(String name, double value)(Code) | | Add a name/value pair into this object.
Parameters: name - A String with the name. Parameters: value - A double with the value. |
add | public void add(String name, int value)(Code) | | Add a name/value pair into this object.
Parameters: name - A String with the name. Parameters: value - An int with the value. |
add | public void add(String name, Integer value)(Code) | | Add a name/value pair into this object.
Parameters: name - A String with the name. Parameters: value - An Integer with the value. |
add | public void add(String name, long value)(Code) | | Add a name/value pair into this object.
Parameters: name - A String with the name. Parameters: value - A long with the value. |
add | public void add(String name, String value)(Code) | | Add a name/value pair into this object.
Parameters: name - A String with the name. Parameters: value - A long with the value. |
add | public void add(String name, String[] value)(Code) | | Add an array of Strings for a key. This
is simply adding all the elements in the
array one by one.
Parameters: name - A String with the name. Parameters: value - A String Array. |
append | public void append(String name, String value)(Code) | | Add a String parameters. If there are any Strings already
associated with the name, append to the array. This is used
for handling parameters from multipart POST requests.
Parameters: name - A String with the name. Parameters: value - A String with the value. |
clear | public void clear()(Code) | | Clear all name/value pairs out of this object.
|
containsDateSelectorKeys | public boolean containsDateSelectorKeys(String key)(Code) | | Check for existence of key_day, key_month and key_year
parameters (as returned by DateSelector generated HTML).
Parameters: key - A String with the selector name. True if keys are found. |
containsKey | public boolean containsKey(Object key)(Code) | | Determine whether a given key has been inserted. All keys are
stored in lowercase strings, so override method to account for
this.
Parameters: key - An Object with the key to search for. True if the object is found. |
containsTimeSelectorKeys | public boolean containsTimeSelectorKeys(String key)(Code) | | Check for existence of key_hour, key_minute and key_second
parameters (as returned by TimeSelector generated HTML).
Parameters: key - A String with the selector name. True if keys are found. |
convert | public String convert(String value)(Code) | | Trims the string data and applies the conversion specified in
the property given by URL_CASE_FOLDING. It returns a new
string so that it does not destroy the value data.
Parameters: value - A String to be processed. A new String converted to lowercase and trimmed. |
convertAndTrim | public static String convertAndTrim(String value)(Code) | | A static version of the convert method, which
trims the string data and applies the conversion specified in
the property given by URL_CASE_FOLDING. It returns a new
string so that it does not destroy the value data.
Parameters: value - A String to be processed. A new String converted to lowercase and trimmed. |
dispose | public void dispose()(Code) | | Disposes the parser.
|
get | public String get(String name)(Code) | | Return a String for the given name. If the name does not
exist, return null. It is the same as the getString() method
however has been added for simplicity when working with
template tools such as Velocity which allow you to do
something like this:
$data.Parameters.form_variable_name
Parameters: name - A String with the name. A String. |
getBigDecimal | public BigDecimal getBigDecimal(String name, BigDecimal defaultValue)(Code) | | Return a BigDecimal for the given name. If the name does not
exist, return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A BigDecimal. |
getBigDecimal | public BigDecimal getBigDecimal(String name)(Code) | | Return a BigDecimal for the given name. If the name does not
exist, return 0.0.
Parameters: name - A String with the name. A BigDecimal. |
getBigDecimals | public BigDecimal[] getBigDecimals(String name)(Code) | | Return an array of BigDecimals for the given name. If the name
does not exist, return null.
Parameters: name - A String with the name. A BigDecimal[]. |
getBool | public Boolean getBool(String name, boolean defaultValue)(Code) | | Return a Boolean for the given name. If the name does not
exist, return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A Boolean.BaseValueParser.getBooleanObject |
getBoolean | public boolean getBoolean(String name, boolean defaultValue)(Code) | | Return a boolean for the given name. If the name does not
exist, return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A boolean. |
getBoolean | public boolean getBoolean(String name)(Code) | | Return a boolean for the given name. If the name does not
exist, return false.
Parameters: name - A String with the name. A boolean. |
getBooleanObject | public Boolean getBooleanObject(String name)(Code) | | Returns a Boolean object for the given name. If the parameter
does not exist or can not be parsed as a boolean, null is returned.
Valid values for true: true, on, 1, yes
Valid values for false: false, off, 0, no
The string is compared without reguard to case.
Parameters: name - A String with the name. A Boolean. |
getBooleanObject | public Boolean getBooleanObject(String name, Boolean defaultValue)(Code) | | Returns a Boolean object for the given name. If the parameter
does not exist or can not be parsed as a boolean, null is returned.
Valid values for true: true, on, 1, yes
Valid values for false: false, off, 0, no
The string is compared without reguard to case.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A Boolean. |
getByte | public byte getByte(String name, byte defaultValue)(Code) | | Return a byte for the given name. If the name does not exist,
return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A byte. |
getByte | public byte getByte(String name)(Code) | | Return a byte for the given name. If the name does not exist,
return 0.
Parameters: name - A String with the name. A byte. |
getByteObject | public Byte getByteObject(String name, Byte defaultValue)(Code) | | Return a byte for the given name. If the name does not exist,
return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A byte. |
getByteObject | public Byte getByteObject(String name)(Code) | | Return a byte for the given name. If the name does not exist,
return 0.
Parameters: name - A String with the name. A byte. |
getCharacterEncoding | public String getCharacterEncoding()(Code) | | Get the character encoding that will be used by this ValueParser.
|
getDate | public Date getDate(String name, DateFormat df, Date defaultValue)(Code) | | Returns a
java.util.Date object. String is parsed by supplied
DateFormat. If the name does not exist or the value could not be
parsed into a date return the defaultValue.
Parameters: name - A String with the name. Parameters: df - A DateFormat. Parameters: defaultValue - The default value. A Date. |
getDate | public Date getDate(String name)(Code) | | Returns a
java.util.Date object. If there are DateSelector or
TimeSelector style parameters then these are used. If not and there
is a parameter 'name' then this is parsed by DateFormat. If the
name does not exist, return null.
Parameters: name - A String with the name. A Date. |
getDate | public Date getDate(String name, DateFormat df)(Code) | | Returns a
java.util.Date object. String is parsed by supplied
DateFormat. If the name does not exist, return null.
Parameters: name - A String with the name. Parameters: df - A DateFormat. A Date. |
getDouble | public double getDouble(String name, double defaultValue)(Code) | | Return a double for the given name. If the name does not
exist, return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A double. |
getDouble | public double getDouble(String name)(Code) | | Return a double for the given name. If the name does not
exist, return 0.0.
Parameters: name - A String with the name. A double. |
getDoubleObject | public Double getDoubleObject(String name, Double defaultValue)(Code) | | Return a Double for the given name. If the name does not
exist, return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A double. |
getDoubleObject | public Double getDoubleObject(String name)(Code) | | Return a Double for the given name. If the name does not
exist, return null.
Parameters: name - A String with the name. A double. |
getDoubleObjects | public Double[] getDoubleObjects(String name)(Code) | | Return an array of doubles for the given name. If the name does
not exist, return null.
Parameters: name - A String with the name. A double[]. |
getDoubles | public double[] getDoubles(String name)(Code) | | Return an array of doubles for the given name. If the name does
not exist, return null.
Parameters: name - A String with the name. A double[]. |
getFloat | public float getFloat(String name, float defaultValue)(Code) | | Return a float for the given name. If the name does not
exist, return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A float. |
getFloat | public float getFloat(String name)(Code) | | Return a float for the given name. If the name does not
exist, return 0.0.
Parameters: name - A String with the name. A float. |
getFloatObject | public Float getFloatObject(String name, Float defaultValue)(Code) | | Return a Float for the given name. If the name does not
exist, return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A Float. |
getFloatObject | public Float getFloatObject(String name)(Code) | | Return a float for the given name. If the name does not
exist, return null.
Parameters: name - A String with the name. A Float. |
getFloatObjects | public Float[] getFloatObjects(String name)(Code) | | Return an array of floats for the given name. If the name does
not exist, return null.
Parameters: name - A String with the name. A float[]. |
getFloats | public float[] getFloats(String name)(Code) | | Return an array of floats for the given name. If the name does
not exist, return null.
Parameters: name - A String with the name. A float[]. |
getInt | public int getInt(String name, int defaultValue)(Code) | | Return an int for the given name. If the name does not exist,
return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. An int. |
getInt | public int getInt(String name)(Code) | | Return an int for the given name. If the name does not exist,
return 0.
Parameters: name - A String with the name. An int. |
getIntObject | public Integer getIntObject(String name, Integer defaultValue)(Code) | | Return an Integer for the given name. If the name does not exist,
return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. An Integer. |
getIntObject | public Integer getIntObject(String name)(Code) | | Return an Integer for the given name. If the name does not exist,
return null.
Parameters: name - A String with the name. An Integer. |
getIntObjects | public Integer[] getIntObjects(String name)(Code) | | Return an array of Integers for the given name. If the name
does not exist, return null.
Parameters: name - A String with the name. An Integer[]. |
getInteger | public Integer getInteger(String name, int defaultValue)(Code) | | Return an Integer for the given name. If the name does not
exist, return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. An Integer.BaseValueParser.getIntObject |
getInteger | public Integer getInteger(String name, Integer def)(Code) | | Return an Integer for the given name. If the name does not
exist, return defaultValue. You cannot pass in a null here for
the default value.
Parameters: name - A String with the name. Parameters: def - The default value. An Integer.BaseValueParser.getIntObject |
getInts | public int[] getInts(String name)(Code) | | Return an array of ints for the given name. If the name does
not exist, return null.
Parameters: name - A String with the name. An int[]. |
getKeys | public Object[] getKeys()(Code) | | Returns all the available parameter names.
A object array with the keys. |
getLong | public long getLong(String name, long defaultValue)(Code) | | Return a long for the given name. If the name does not exist,
return defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A long. |
getLong | public long getLong(String name)(Code) | | Return a long for the given name. If the name does not exist,
return 0.
Parameters: name - A String with the name. A long. |
getLongObject | public Long getLongObject(String name)(Code) | | Return a Long for the given name. If the name does
not exist, return null.
Parameters: name - A String with the name. A Long. |
getLongObject | public Long getLongObject(String name, Long defaultValue)(Code) | | Return a Long for the given name. If the name does
not exist, return the default value.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A Long. |
getLongObjects | public Long[] getLongObjects(String name)(Code) | | Return an array of Longs for the given name. If the name does
not exist, return null.
Parameters: name - A String with the name. A Long[]. |
getLongs | public long[] getLongs(String name)(Code) | | Return an array of longs for the given name. If the name does
not exist, return null.
Parameters: name - A String with the name. A long[]. |
getNumberKey | public NumberKey getNumberKey(String name)(Code) | | Return an NumberKey for the given name. If the name does not
exist, return null.
Parameters: name - A String with the name. A NumberKey, or null if unparsable. |
getObject | public Object getObject(String name)(Code) | | Return an Object for the given name. If the name does not
exist, return null.
Parameters: name - A String with the name. An Object. |
getObjects | public Object[] getObjects(String name)(Code) | | Return an array of Objects for the given name. If the name
does not exist, return null.
Parameters: name - A String with the name. An Object[]. |
getParam | protected String[] getParam(String name)(Code) | | fetches a key from the parameters map. Makes sure that the name is
always mapped correctly.
Parameters: name - A string with the name the value object array or null if not set |
getString | public String getString(String name)(Code) | | Return a String for the given name. If the name does not
exist, return null.
Parameters: name - A String with the name. A String or null if the key is unknown. |
getString | public String getString(String name, String defaultValue)(Code) | | Return a String for the given name. If the name does not
exist, return the defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A String. |
getStringKey | public StringKey getStringKey(String name)(Code) | | Return an StringKey for the given name. If the name does not
exist, return null.
Parameters: name - A String with the name. A StringKey, or null if unparsable. |
getStrings | public String[] getStrings(String name)(Code) | | Return an array of Strings for the given name. If the name
does not exist, return null.
Parameters: name - A String with the name. A String[]. |
getStrings | public String[] getStrings(String name, String[] defaultValue)(Code) | | Return an array of Strings for the given name. If the name
does not exist, return the defaultValue.
Parameters: name - A String with the name. Parameters: defaultValue - The default value. A String[]. |
getToStringParam | protected Object[] getToStringParam(String name)(Code) | | This method is only used in toString() and can be used by
derived classes to add their local parameters to the toString()
Parameters: name - A string with the name the value object array or null if not set |
keySet | public Set keySet()(Code) | | Gets the set of keys
A Set of the keys. |
putParam | protected void putParam(String name, String[] value)(Code) | | 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. Parameters: value - An array of Objects with the values. |
recycle | public void recycle(String characterEncoding)(Code) | | Recycles the parser with a character encoding.
Parameters: characterEncoding - the character encoding. |
remove | public Object remove(String name)(Code) | | Removes the named parameter from the contained hashtable. Wraps to the
contained Map.remove() .
The value that was mapped to the key (a String[] )or null if the key was not mapped. |
setCharacterEncoding | public void setCharacterEncoding(String s)(Code) | | Set the character encoding that will be used by this ValueParser.
|
setProperties | public void setProperties(Object bean) throws Exception(Code) | | Uses bean introspection to set writable properties of bean from
the parameters, where a (case-insensitive) name match between
the bean property and the parameter is looked for.
Parameters: bean - An Object. exception: Exception - a generic exception. |
setProperty | protected void setProperty(Object bean, PropertyDescriptor prop) throws Exception(Code) | | Set the property 'prop' in the bean to the value of the
corresponding parameters. Supports all types supported by
getXXX methods plus a few more that come for free because
primitives have to be wrapped before being passed to invoke
anyway.
Parameters: bean - An Object. Parameters: prop - A PropertyDescriptor. exception: Exception - a generic exception. |
setString | public void setString(String name, String value)(Code) | | Set a parameter to a specific value.
This is useful if you want your action to override the values
of the parameters for the screen to use.
Parameters: name - The name of the parameter. Parameters: value - The value to set. |
setStrings | public void setStrings(String name, String[] values)(Code) | | Set a parameter to a specific value.
This is useful if you want your action to override the values
of the parameters for the screen to use.
Parameters: name - The name of the parameter. Parameters: values - The value to set. |
toString | public String toString()(Code) | | Simple method that attempts to get a textual representation of
this object's name/value pairs. String[] handling is currently
a bit rough.
A textual representation of the parsed name/value pairs. |
|
|