Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.jcorporate.expresso.core.misc.upload
Class BaseValueParser  view BaseValueParser download BaseValueParser.java

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

public class BaseValueParser
extends java.lang.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 $

Field Summary
private  java.lang.String characterEncoding
          The character encoding to use when converting to byte arrays
protected  java.util.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(java.lang.String newEncoding)
          Constructor that takes a character encoding
 
Method Summary
 void add(java.lang.String name, double value)
          Add a name/value pair into this object.
 void add(java.lang.String name, int value)
          Add a name/value pair into this object.
 void add(java.lang.String name, java.lang.Integer value)
          Add a name/value pair into this object.
 void add(java.lang.String name, long value)
          Add a name/value pair into this object.
 void add(java.lang.String name, java.lang.String value)
          Add a name/value pair into this object.
 void append(java.lang.String name, java.lang.String value)
          Add a String parameters.
 void clear()
          Clear all name/value pairs out of this object.
 boolean containsKey(java.lang.Object key)
          Determine whether a given key has been inserted.
 java.lang.String convert(java.lang.String value)
          Trims the string data and applies the conversion specified in the property given by URL_CASE_FOLDING.
static java.lang.String convertAndTrim(java.lang.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.
 java.lang.String get(java.lang.String name)
          Return a String for the given name.
 java.math.BigDecimal getBigDecimal(java.lang.String name)
          Return a BigDecimal for the given name.
 java.math.BigDecimal getBigDecimal(java.lang.String name, java.math.BigDecimal defaultValue)
          Return a BigDecimal for the given name.
 java.math.BigDecimal[] getBigDecimals(java.lang.String name)
          Return an array of BigDecimals for the given name.
 java.lang.Boolean getBool(java.lang.String name)
          Return a Boolean for the given name.
 java.lang.Boolean getBool(java.lang.String name, boolean defaultValue)
          Return a Boolean for the given name.
 boolean getBoolean(java.lang.String name)
          Return a boolean for the given name.
 boolean getBoolean(java.lang.String name, boolean defaultValue)
          Return a boolean for the given name.
 byte getByte(java.lang.String name)
          Return a byte for the given name.
 byte getByte(java.lang.String name, byte defaultValue)
          Return a byte for the given name.
 byte[] getBytes(java.lang.String name)
          Return an array of bytes for the given name.
 java.lang.String getCharacterEncoding()
          Get the character encoding that will be used by this ValueParser.
 double getDouble(java.lang.String name)
          Return a double for the given name.
 double getDouble(java.lang.String name, double defaultValue)
          Return a double for the given name.
 float getFloat(java.lang.String name)
          Return a float for the given name.
 float getFloat(java.lang.String name, float defaultValue)
          Return a float for the given name.
 int getInt(java.lang.String name)
          Return an int for the given name.
 int getInt(java.lang.String name, int defaultValue)
          Return an int for the given name.
 java.lang.Integer getInteger(java.lang.String name)
          Return an Integer for the given name.
 java.lang.Integer getInteger(java.lang.String name, int defaultValue)
          Return an Integer for the given name.
 java.lang.Integer getInteger(java.lang.String name, java.lang.Integer def)
          Return an Integer for the given name.
 java.lang.Integer[] getIntegers(java.lang.String name)
          Return an array of Integers for the given name.
 int[] getInts(java.lang.String name)
          Return an array of ints for the given name.
 java.lang.Object[] getKeys()
           
 long getLong(java.lang.String name)
          Return a long for the given name.
 long getLong(java.lang.String name, long defaultValue)
          Return a long for the given name.
 java.lang.Long[] getLongObjects(java.lang.String name)
          Return an array of Longs for the given name.
 long[] getLongs(java.lang.String name)
          Return an array of longs for the given name.
 java.lang.Object getObject(java.lang.String name)
          Return an Object for the given name.
 java.lang.Object[] getObjects(java.lang.String name)
          Return an array of Objects for the given name.
 java.lang.String getString(java.lang.String name)
          Return a String for the given name.
 java.lang.String getString(java.lang.String name, java.lang.String defaultValue)
          Return a String for the given name.
 java.lang.String[] getStrings(java.lang.String name)
          Return an array of Strings for the given name.
 java.lang.String[] getStrings(java.lang.String name, java.lang.String[] defaultValue)
          Return an array of Strings for the given name.
 java.util.Enumeration keys()
           
 java.lang.Object remove(java.lang.String name)
          Removes the named parameter from the contained hashtable.
 void setCharacterEncoding(java.lang.String s)
          Set the character encoding that will be used by this ValueParser.
 void setProperties(java.lang.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.
private  void setProperty(java.lang.Object bean, java.beans.PropertyDescriptor prop)
          Set the property 'prop' in the bean to the value of the corresponding parameters.
 void setString(java.lang.String name, java.lang.String value)
          Set a parameter to a specific value.
 void setStrings(java.lang.String name, java.lang.String[] values)
          Set a parameter to a specific value.
 java.lang.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 java.util.Hashtable parameters
Random access storage for parameter data.


characterEncoding

private java.lang.String characterEncoding
The character encoding to use when converting to byte arrays

Constructor Detail

BaseValueParser

public BaseValueParser()
Default constructor


BaseValueParser

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

Method Detail

convertAndTrim

public static java.lang.String convertAndTrim(java.lang.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.


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(java.lang.String s)
Set the character encoding that will be used by this ValueParser.

Specified by:
setCharacterEncoding in interface ValueParser

getCharacterEncoding

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

Specified by:
getCharacterEncoding in interface ValueParser

add

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

Specified by:
add in interface ValueParser

add

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

Specified by:
add in interface ValueParser

add

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

Specified by:
add in interface ValueParser

add

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

Specified by:
add in interface ValueParser

add

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

Specified by:
add in interface ValueParser

append

public void append(java.lang.String name,
                   java.lang.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

remove

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

Specified by:
remove in interface ValueParser

convert

public java.lang.String convert(java.lang.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

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

keys

public java.util.Enumeration keys()
Specified by:
keys in interface ValueParser

getKeys

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

getBoolean

public boolean getBoolean(java.lang.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

getBoolean

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

Specified by:
getBoolean in interface ValueParser

getBool

public java.lang.Boolean getBool(java.lang.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

getBool

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

Specified by:
getBool in interface ValueParser

getDouble

public double getDouble(java.lang.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

getDouble

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

Specified by:
getDouble in interface ValueParser

getFloat

public float getFloat(java.lang.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

getFloat

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

Specified by:
getFloat in interface ValueParser

getBigDecimal

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

Specified by:
getBigDecimal in interface ValueParser

getBigDecimal

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

Specified by:
getBigDecimal in interface ValueParser

getBigDecimals

public java.math.BigDecimal[] getBigDecimals(java.lang.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

getInt

public int getInt(java.lang.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

getInt

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

Specified by:
getInt in interface ValueParser

getInteger

public java.lang.Integer getInteger(java.lang.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

getInteger

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

getInteger

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

Specified by:
getInteger in interface ValueParser

getInts

public int[] getInts(java.lang.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

getIntegers

public java.lang.Integer[] getIntegers(java.lang.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

getLong

public long getLong(java.lang.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

getLong

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

Specified by:
getLong in interface ValueParser

getLongs

public long[] getLongs(java.lang.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

getLongObjects

public java.lang.Long[] getLongObjects(java.lang.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

getByte

public byte getByte(java.lang.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

getByte

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

Specified by:
getByte in interface ValueParser

getBytes

public byte[] getBytes(java.lang.String name)
                throws java.io.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

getString

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

Specified by:
getString in interface ValueParser

get

public java.lang.String get(java.lang.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

getString

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

Specified by:
getString in interface ValueParser

setString

public void setString(java.lang.String name,
                      java.lang.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

getStrings

public java.lang.String[] getStrings(java.lang.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

getStrings

public java.lang.String[] getStrings(java.lang.String name,
                                     java.lang.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

setStrings

public void setStrings(java.lang.String name,
                       java.lang.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

getObject

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

Specified by:
getObject in interface ValueParser

getObjects

public java.lang.Object[] getObjects(java.lang.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

setProperties

public void setProperties(java.lang.Object bean)
                   throws java.lang.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

toString

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

setProperty

private void setProperty(java.lang.Object bean,
                         java.beans.PropertyDescriptor prop)
                  throws java.lang.Exception
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.