org.apache.fulcrum.parser
Interface ValueParser

All Known Subinterfaces:
CookieParser, ParameterParser
All Known Implementing Classes:
BaseValueParser, DefaultCookieParser, DefaultParameterParser, StringValueParser

public interface ValueParser

ValueParser is a base interface for classes that need to parse name/value Parameters, for example GET/POST data or Cookies (ParameterParser and CookieParser)

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:

Version:
$Id: ValueParser.java 812786 2009-09-09 07:01:49Z tv $
Author:
Ilkka Priha, Jon S. Stevens, Sean Legassick, Jason van Zyl, Jürgen Hoffmann, Thomas Vandahl

Field Summary
static String DEFAULT_CHARACTER_ENCODING
          The default character encoding to use when converting to byte arrays
 
Method Summary
 void add(String name, double value)
          Add a name/value pair into this object.
 void add(String name, int value)
          Add a name/value pair into this object.
 void add(String name, Integer value)
          Add a name/value pair into this object.
 void add(String name, long value)
          Add a name/value pair into this object.
 void add(String name, String value)
          Add a name/value pair into this object.
 void add(String name, String[] value)
          Add an array of Strings for a key.
 void clear()
          Clear all name/value pairs out of this object.
 boolean containsKey(Object key)
          Determine whether a given key has been inserted.
 String convert(String value)
          Trims the string data and applies the conversion specified in the property given by URL_CASE_FOLDING.
 String convertAndTrim(String value)
          Convert a String value according to the url-case-folding property.
 String convertAndTrim(String value, int folding)
          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.
 String get(String name)
          Return a String for the given name.
 BigDecimal getBigDecimal(String name)
          Return a BigDecimal for the given name.
 BigDecimal getBigDecimal(String name, BigDecimal defaultValue)
          Return a BigDecimal for the given name.
 BigDecimal[] getBigDecimals(String name)
          Return an array of BigDecimals for the given name.
 boolean getBoolean(String name)
          Return a boolean for the given name.
 boolean getBoolean(String name, boolean defaultValue)
          Return a boolean for the given name.
 Boolean getBooleanObject(String name)
          Returns a Boolean object for the given name.
 Boolean getBooleanObject(String name, Boolean defaultValue)
          Returns a Boolean object for the given name.
 Boolean[] getBooleanObjects(String name)
          Return an array of Booleans for the given name.
 boolean[] getBooleans(String name)
          Return an array of booleans for the given name.
 byte getByte(String name)
          Return a byte for the given name.
 byte getByte(String name, byte defaultValue)
          Return a byte for the given name.
 Byte getByteObject(String name)
          Return a byte for the given name.
 Byte getByteObject(String name, Byte defaultValue)
          Return a byte for the given name.
 byte[] getBytes(String name)
          Return an array of bytes for the given name.
 String getCharacterEncoding()
          Get the character encoding that will be used by this ValueParser.
 Date getDate(String name)
          Returns a java.util.Date object.
 Date getDate(String name, DateFormat df)
          Returns a java.util.Date object.
 Date getDate(String name, DateFormat df, Date defaultValue)
          Returns a java.util.Date object.
 DateFormat getDateFormat()
          Get the date format that will be used by this ValueParser.
 double getDouble(String name)
          Return a double for the given name.
 double getDouble(String name, double defaultValue)
          Return a double for the given name.
 Double getDoubleObject(String name)
          Return a Double for the given name.
 Double getDoubleObject(String name, Double defaultValue)
          Return a Double for the given name.
 Double[] getDoubleObjects(String name)
          Return an array of doubles for the given name.
 double[] getDoubles(String name)
          Return an array of doubles for the given name.
 float getFloat(String name)
          Return a float for the given name.
 float getFloat(String name, float defaultValue)
          Return a float for the given name.
 Float getFloatObject(String name)
          Return a float for the given name.
 Float getFloatObject(String name, Float defaultValue)
          Return a Float for the given name.
 Float[] getFloatObjects(String name)
          Return an array of floats for the given name.
 float[] getFloats(String name)
          Return an array of floats for the given name.
 int getInt(String name)
          Return an int for the given name.
 int getInt(String name, int defaultValue)
          Return an int for the given name.
 Integer getIntObject(String name)
          Return an Integer for the given name.
 Integer getIntObject(String name, Integer defaultValue)
          Return an Integer for the given name.
 Integer[] getIntObjects(String name)
          Return an array of Integers for the given name.
 int[] getInts(String name)
          Return an array of ints for the given name.
 Object[] getKeys()
          Returns all the available parameter names.
 Locale getLocale()
          Get the locale that will be used by this ValueParser.
 long getLong(String name)
          Return a long for the given name.
 long getLong(String name, long defaultValue)
          Return a long for the given name.
 Long getLongObject(String name)
          Return a Long for the given name.
 Long getLongObject(String name, Long defaultValue)
          Return a Long for the given name.
 Long[] getLongObjects(String name)
          Return an array of Longs for the given name.
 long[] getLongs(String name)
          Return an array of longs for the given name.
 NumberFormat getNumberFormat()
          Get the number format that will be used by this ValueParser.
 Object getObject(String name)
          Return an Object for the given name.
 Object[] getObjects(String name)
          Return an array of Objects for the given name.
 String getString(String name)
          Return a String for the given name.
 String getString(String name, String defaultValue)
          Return a String for the given name.
 String[] getStrings(String name)
          Return an array of Strings for the given name.
 String[] getStrings(String name, String[] defaultValue)
          Return an array of Strings for the given name.
 int getUrlFolding()
          Gets the folding value from the ParserService configuration
 Set keySet()
          Gets the keys.
 Object remove(String name)
          Removes the named parameter from the contained hashtable.
 void setCharacterEncoding(String s)
          Set the character encoding that will be used by this ValueParser.
 void setDateFormat(DateFormat df)
          Set the date format that will be used by this ValueParser.
 void setLocale(Locale l)
          Set the locale that will be used by this ValueParser.
 void setNumberFormat(NumberFormat nf)
          Set the number format that will be used by this ValueParser.
 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.
 void setString(String name, String value)
          Set a parameter to a specific value.
 void setStrings(String name, String[] values)
          Set a parameter to a specific value.
 String toString()
          Simple method that attempts to get a toString() representation of this object.
 

Field Detail

DEFAULT_CHARACTER_ENCODING

static final String DEFAULT_CHARACTER_ENCODING
The default character encoding to use when converting to byte arrays

See Also:
Constant Field Values
Method Detail

clear

void clear()
Clear all name/value pairs out of this object.


setCharacterEncoding

void setCharacterEncoding(String s)
Set the character encoding that will be used by this ValueParser.


getCharacterEncoding

String getCharacterEncoding()
Get the character encoding that will be used by this ValueParser.


setLocale

void setLocale(Locale l)
Set the locale that will be used by this ValueParser.


getLocale

Locale getLocale()
Get the locale that will be used by this ValueParser.


setDateFormat

void setDateFormat(DateFormat df)
Set the date format that will be used by this ValueParser.


getDateFormat

DateFormat getDateFormat()
Get the date format that will be used by this ValueParser.


setNumberFormat

void setNumberFormat(NumberFormat nf)
Set the number format that will be used by this ValueParser.


getNumberFormat

NumberFormat getNumberFormat()
Get the number format that will be used by this ValueParser.


convert

String convert(String value)
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.
Returns:
A new String converted to lowercase and trimmed.

add

void add(String name,
         double value)
Add a name/value pair into this object.

Parameters:
name - A String with the name.
value - A double with the value.

add

void add(String name,
         int value)
Add a name/value pair into this object.

Parameters:
name - A String with the name.
value - An int with the value.

add

void add(String name,
         Integer value)
Add a name/value pair into this object.

Parameters:
name - A String with the name.
value - An Integer with the value.

add

void add(String name,
         long value)
Add a name/value pair into this object.

Parameters:
name - A String with the name.
value - A long with the value.

add

void add(String name,
         String value)
Add a name/value pair into this object.

Parameters:
name - A String with the name.
value - A long with the value.

add

void add(String name,
         String[] value)
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.
value - A String Array.

remove

Object remove(String name)
Removes the named parameter from the contained hashtable. Wraps to the contained Hashtable.remove().

Returns:
The value that was mapped to the key (a String[]) or null if the key was not mapped.

containsKey

boolean containsKey(Object key)
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.
Returns:
True if the object is found.

keySet

Set keySet()
Gets the keys.

Returns:
A Set of the keys.

getKeys

Object[] getKeys()
Returns all the available parameter names.

Returns:
A object array with the keys.

getBoolean

boolean getBoolean(String name,
                   boolean defaultValue)
Return a boolean for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A boolean.

getBoolean

boolean getBoolean(String name)
Return a boolean for the given name. If the name does not exist, return false.

Parameters:
name - A String with the name.
Returns:
A boolean.

getBooleanObject

Boolean getBooleanObject(String name)
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.
Returns:
A Boolean.

getBooleanObject

Boolean getBooleanObject(String name,
                         Boolean defaultValue)
Returns a Boolean object for the given name. If the parameter does not exist or can not be parsed as a boolean, the defaultValue 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.
Returns:
A Boolean.

getBooleans

boolean[] getBooleans(String name)
Return an array of booleans for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A boolean[].

getBooleanObjects

Boolean[] getBooleanObjects(String name)
Return an array of Booleans for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A Boolean[].

getDouble

double getDouble(String name,
                 double defaultValue)
Return a double for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A double.

getDouble

double getDouble(String name)
Return a double for the given name. If the name does not exist, return 0.0.

Parameters:
name - A String with the name.
Returns:
A double.

getDoubles

double[] getDoubles(String name)
Return an array of doubles for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A double[].

getDoubleObject

Double getDoubleObject(String name,
                       Double defaultValue)
Return a Double for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A double.

getDoubleObject

Double getDoubleObject(String name)
Return a Double for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A double.

getDoubleObjects

Double[] getDoubleObjects(String name)
Return an array of doubles for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A double[].

getFloat

float getFloat(String name,
               float defaultValue)
Return a float for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A float.

getFloat

float getFloat(String name)
Return a float for the given name. If the name does not exist, return 0.0.

Parameters:
name - A String with the name.
Returns:
A float.

getFloats

float[] getFloats(String name)
Return an array of floats for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A float[].

getFloatObject

Float getFloatObject(String name,
                     Float defaultValue)
Return a Float for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A Float.

getFloatObject

Float getFloatObject(String name)
Return a float for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A Float.

getFloatObjects

Float[] getFloatObjects(String name)
Return an array of floats for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A float[].

getBigDecimal

BigDecimal getBigDecimal(String name,
                         BigDecimal defaultValue)
Return a BigDecimal for the given name. If the name does not exist, return 0.0.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A BigDecimal.

getBigDecimal

BigDecimal getBigDecimal(String name)
Return a BigDecimal for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A BigDecimal.

getBigDecimals

BigDecimal[] getBigDecimals(String name)
Return an array of BigDecimals for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A BigDecimal[].

getInt

int getInt(String name,
           int defaultValue)
Return an int for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
An int.

getInt

int getInt(String name)
Return an int for the given name. If the name does not exist, return 0.

Parameters:
name - A String with the name.
Returns:
An int.

getIntObject

Integer getIntObject(String name,
                     Integer defaultValue)
Return an Integer for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
An Integer.

getIntObject

Integer getIntObject(String name)
Return an Integer for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
An Integer.

getInts

int[] getInts(String name)
Return an array of ints for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
An int[].

getIntObjects

Integer[] getIntObjects(String name)
Return an array of Integers for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
An Integer[].

getLong

long getLong(String name,
             long defaultValue)
Return a long for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A long.

getLong

long getLong(String name)
Return a long for the given name. If the name does not exist, return 0.

Parameters:
name - A String with the name.
Returns:
A long.

getLongObject

Long getLongObject(String name,
                   Long defaultValue)
Return a Long for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A Long.

getLongObject

Long getLongObject(String name)
Return a Long for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A Long.

getLongs

long[] getLongs(String name)
Return an array of longs for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A long[].

getLongObjects

Long[] getLongObjects(String name)
Return an array of Longs for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A Long[].

getByte

byte getByte(String name,
             byte defaultValue)
Return a byte for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A byte.

getByte

byte getByte(String name)
Return a byte for the given name. If the name does not exist, return 0.

Parameters:
name - A String with the name.
Returns:
A byte.

getBytes

byte[] getBytes(String name)
                throws UnsupportedEncodingException
Return an array of bytes for the given name. If the name does not exist, return null. The array is returned according to the HttpRequest's character encoding.

Parameters:
name - A String with the name.
Returns:
A byte[].
Throws:
UnsupportedEncodingException

getByteObject

Byte getByteObject(String name,
                   Byte defaultValue)
Return a byte for the given name. If the name does not exist, return defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A byte.

getByteObject

Byte getByteObject(String name)
Return a byte for the given name. If the name does not exist, return 0.

Parameters:
name - A String with the name.
Returns:
A byte.

getString

String getString(String name)
Return a String for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A String.

get

String get(String name)
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.
Returns:
A String.

getString

String getString(String name,
                 String defaultValue)
Return a String for the given name. If the name does not exist, return the defaultValue.

Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A String.

setString

void setString(String name,
               String value)
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.
value - The value to set.

getStrings

String[] getStrings(String name)
Return an array of Strings for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
A String[].

getStrings

String[] getStrings(String name,
                    String[] defaultValue)
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.
defaultValue - The default value.
Returns:
A String[].

setStrings

void setStrings(String name,
                String[] values)
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.
values - The value to set.

getObject

Object getObject(String name)
Return an Object for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
An Object.

getObjects

Object[] getObjects(String name)
Return an array of Objects for the given name. If the name does not exist, return null.

Parameters:
name - A String with the name.
Returns:
An Object[].

getDate

Date getDate(String name,
             DateFormat df,
             Date defaultValue)
Returns a java.util.Date object. String is parsed by supplied DateFormat. If the name does not exist, return the defaultValue.

Parameters:
name - A String with the name.
df - A DateFormat.
defaultValue - The default value.
Returns:
A Date.

getDate

Date getDate(String name)
Returns a java.util.Date object. If there are DateSelector 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.
Returns:
A Date.

getDate

Date getDate(String name,
             DateFormat df)
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.
df - A DateFormat.
Returns:
A Date.

setProperties

void setProperties(Object bean)
                   throws Exception
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.
Throws:
Exception - a generic exception.

toString

String toString()
Simple method that attempts to get a toString() representation of this object. It doesn't do well with String[]'s though.

Overrides:
toString in class Object
Returns:
A String.

convertAndTrim

String convertAndTrim(String value)
Convert a String value according to the url-case-folding property.

Parameters:
value - the String to convert
Returns:
a new String.

convertAndTrim

String convertAndTrim(String value,
                      int folding)
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.
Returns:
A new String converted and trimmed.

getUrlFolding

int getUrlFolding()
Gets the folding value from the ParserService configuration

Returns:
The current Folding Value


Copyright © 2005-2009 The Apache Software Foundation. All Rights Reserved.