Expresso 5-6

com.jcorporate.expresso.core.misc.upload
Class BaseValueParser

java.lang.Object
  extended bycom.jcorporate.expresso.core.misc.upload.BaseValueParser
All Implemented Interfaces:
ValueParser
Direct Known Subclasses:
DefaultParameterParser

public class BaseValueParser
extends Object
implements ValueParser

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.

Version:
$Id: BaseValueParser.java,v 1.7 2004/11/18 02:03:27 lhamel Exp $
Author:
Ilkka Priha, Jon S. Stevens, Sean Legassick, Jason van Zyl

Field Summary
protected  Hashtable parameters
          Random access storage for parameter data.
 
Fields inherited from interface com.jcorporate.expresso.core.misc.upload.ValueParser
URL_CASE_FOLDING, URL_CASE_FOLDING_LOWER, URL_CASE_FOLDING_NONE, URL_CASE_FOLDING_UPPER
 
Constructor Summary
BaseValueParser()
          Default constructor
BaseValueParser(String newEncoding)
          Constructor that takes a character encoding
 
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 append(String name, String value)
          Add a String parameters.
 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.
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.
 void dispose()
          Disposes the parser.
 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 getBool(String name)
          Return a Boolean for the given name.
 Boolean getBool(String name, boolean defaultValue)
          Return a Boolean 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.
 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[] 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.
 double getDouble(String name)
          Return a double for the given name.
 double getDouble(String name, double defaultValue)
          Return a double 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.
 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 getInteger(String name)
          Return an Integer for the given name.
 Integer getInteger(String name, int defaultValue)
          Return an Integer for the given name.
 Integer getInteger(String name, Integer def)
          Return an Integer for the given name.
 Integer[] getIntegers(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()
           
 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[] 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.
 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.
 Enumeration 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parameters

protected Hashtable parameters
Random access storage for parameter data.

Constructor Detail

BaseValueParser

public BaseValueParser()
Default constructor


BaseValueParser

public BaseValueParser(String newEncoding)
Constructor that takes a character encoding

Method Detail

convertAndTrim

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. 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.

dispose

public void dispose()
Disposes the parser.


clear

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

Specified by:
clear in interface ValueParser

setCharacterEncoding

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

Specified by:
setCharacterEncoding in interface ValueParser

getCharacterEncoding

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

Specified by:
getCharacterEncoding in interface ValueParser

add

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

Specified by:
add in interface ValueParser
Parameters:
name - A String with the name.
value - A double with the value.

add

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

Specified by:
add in interface ValueParser
Parameters:
name - A String with the name.
value - An int with the value.

add

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

Specified by:
add in interface ValueParser
Parameters:
name - A String with the name.
value - An Integer with the value.

add

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

Specified by:
add in interface ValueParser
Parameters:
name - A String with the name.
value - A long with the value.

add

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

Specified by:
add in interface ValueParser
Parameters:
name - A String with the name.
value - A long with the value.

append

public void append(String name,
                   String value)
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 mulitipart POST requests.

Specified by:
append in interface ValueParser
Parameters:
name - A String with the name.
value - A String with the value.

remove

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

Specified by:
remove in interface ValueParser
Returns:
The value that was mapped to the key (a String[]) or null if the key was not mapped.

convert

public 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.

Specified by:
convert in interface ValueParser
Parameters:
value - A String to be processed.
Returns:
A new String converted to lowercase and trimmed.

containsKey

public 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.

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

keys

public Enumeration keys()
Specified by:
keys in interface ValueParser

getKeys

public Object[] getKeys()
Specified by:
getKeys in interface ValueParser

getBoolean

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

Specified by:
getBoolean in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A boolean.

getBoolean

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

Specified by:
getBoolean in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A boolean.

getBool

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

Specified by:
getBool in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A Boolean.

getBool

public Boolean getBool(String name)
Return a Boolean for the given name. If the name does not exist, return false.

Specified by:
getBool in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A Boolean.

getDouble

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

Specified by:
getDouble in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A double.

getDouble

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

Specified by:
getDouble in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A double.

getFloat

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

Specified by:
getFloat in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A float.

getFloat

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

Specified by:
getFloat in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A float.

getBigDecimal

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

Specified by:
getBigDecimal in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A BigDecimal.

getBigDecimal

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

Specified by:
getBigDecimal in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A BigDecimal.

getBigDecimals

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

Specified by:
getBigDecimals in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A BigDecimal[].

getInt

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

Specified by:
getInt in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
An int.

getInt

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

Specified by:
getInt in interface ValueParser
Parameters:
name - A String with the name.
Returns:
An int.

getInteger

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

Specified by:
getInteger in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
An Integer.

getInteger

public Integer getInteger(String name,
                          Integer def)
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.

Specified by:
getInteger in interface ValueParser
Parameters:
name - A String with the name.
Returns:
An Integer.

getInteger

public Integer getInteger(String name)
Return an Integer for the given name. If the name does not exist, return 0.

Specified by:
getInteger in interface ValueParser
Parameters:
name - A String with the name.
Returns:
An Integer.

getInts

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

Specified by:
getInts in interface ValueParser
Parameters:
name - A String with the name.
Returns:
An int[].

getIntegers

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

Specified by:
getIntegers in interface ValueParser
Parameters:
name - A String with the name.
Returns:
An Integer[].

getLong

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

Specified by:
getLong in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A long.

getLong

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

Specified by:
getLong in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A long.

getLongs

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

Specified by:
getLongs in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A long[].

getLongObjects

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

Specified by:
getLongObjects in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A Long[].

getByte

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

Specified by:
getByte in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A byte.

getByte

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

Specified by:
getByte in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A byte.

getBytes

public 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.

Specified by:
getBytes in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A byte[].
Throws:
UnsupportedEncodingException

getString

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

Specified by:
getString in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A String.

get

public 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

Specified by:
get in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A String.

getString

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

Specified by:
getString in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A String.

setString

public 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.

Specified by:
setString in interface ValueParser
Parameters:
name - The name of the parameter.
value - The value to set.

getStrings

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

Specified by:
getStrings in interface ValueParser
Parameters:
name - A String with the name.
Returns:
A String[].

getStrings

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

Specified by:
getStrings in interface ValueParser
Parameters:
name - A String with the name.
defaultValue - The default value.
Returns:
A String[].

setStrings

public 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.

Specified by:
setStrings in interface ValueParser
Parameters:
name - The name of the parameter.
values - The value to set.

getObject

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

Specified by:
getObject in interface ValueParser
Parameters:
name - A String with the name.
Returns:
An Object.

getObjects

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

Specified by:
getObjects in interface ValueParser
Parameters:
name - A String with the name.
Returns:
An Object[].

setProperties

public 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.

Specified by:
setProperties in interface ValueParser
Parameters:
bean - An Object.
Throws:
Exception, - a generic exception.
Exception

toString

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

Specified by:
toString in interface ValueParser
Returns:
A String.

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.