public class BaseValueParser extends Object implements ValueParser, ParserServiceSupport, org.apache.avalon.framework.logger.LogEnabled
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 behavior 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.
ValueParser.URLCaseFolding
Modifier and Type | Field and Description |
---|---|
protected Hashtable<String,Object> |
parameters
Random access storage for parameter data.
|
protected ParserService |
parserService
The ParserService instance to query for conversion and configuration
|
DEFAULT_CHARACTER_ENCODING
Constructor and Description |
---|
BaseValueParser() |
BaseValueParser(String characterEncoding)
Constructor that takes a character encoding
|
BaseValueParser(String characterEncoding,
Locale locale)
Constructor that takes a character encoding and a locale
|
Modifier and Type | Method and Description |
---|---|
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,
ValueParser.URLCaseFolding fold)
A convert method, which trims the string data and applies the
conversion specified in the parameter given.
|
void |
dispose()
Disposes the parser.
|
void |
enableLogging(org.apache.avalon.framework.logger.Logger logger) |
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
Date object. |
Date |
getDate(String name,
DateFormat df)
Returns a
Date object. |
Date |
getDate(String name,
DateFormat df,
Date defaultValue)
Returns a
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.
|
String[] |
getKeys()
Returns all the available parameter names.
|
Locale |
getLocale()
Get the locale that will be used by this ValueParser.
|
protected org.apache.avalon.framework.logger.Logger |
getLogger()
Provide an Avalon logger to the derived classes
|
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.
|
protected String[] |
getParam(String name)
fetches a key from the parameters map.
|
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.
|
protected Object[] |
getToStringParam(String name)
This method is only used in toString() and can be used by
derived classes to add their local parameters to the toString()
|
ValueParser.URLCaseFolding |
getUrlFolding()
Gets the folding value from the ParserService configuration
|
boolean |
isDisposed()
Checks whether the object is disposed.
|
boolean |
isValid() |
Iterator<String> |
iterator()
Gets an iterator over the set of keys
|
Set<String> |
keySet()
Gets the set of keys
|
protected void |
putParam(String name,
String[] value)
Puts a key into the parameters map.
|
void |
recycle()
Recycles the parser.
|
void |
recycle(String characterEncoding)
Recycles the parser with a character encoding.
|
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 |
setParserService(ParserService parserService)
Set a ParserService instance
|
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.
|
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 textual representation of
this object's name/value pairs.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
protected ParserService parserService
public BaseValueParser()
public BaseValueParser(String characterEncoding)
characterEncoding
- desired character encodingpublic void setParserService(ParserService parserService)
setParserService
in interface ParserServiceSupport
parserService
- The parser service instancepublic void enableLogging(org.apache.avalon.framework.logger.Logger logger)
enableLogging
in interface org.apache.avalon.framework.logger.LogEnabled
logger
- The logger to be usedLogEnabled.enableLogging(org.apache.avalon.framework.logger.Logger)
protected org.apache.avalon.framework.logger.Logger getLogger()
public void recycle()
public void recycle(String characterEncoding)
characterEncoding
- the character encoding.public void dispose()
dispose
in interface ValueParser
public void clear()
clear
in interface ValueParser
public void setCharacterEncoding(String s)
setCharacterEncoding
in interface ValueParser
s
- the character encoding to usepublic String getCharacterEncoding()
getCharacterEncoding
in interface ValueParser
public void setLocale(Locale l)
setLocale
in interface ValueParser
l
- the default locale to be used by the parserpublic Locale getLocale()
getLocale
in interface ValueParser
public void setDateFormat(DateFormat df)
setDateFormat
in interface ValueParser
df
- the date formatpublic DateFormat getDateFormat()
getDateFormat
in interface ValueParser
public void setNumberFormat(NumberFormat nf)
setNumberFormat
in interface ValueParser
nf
- the number format to usepublic NumberFormat getNumberFormat()
getNumberFormat
in interface ValueParser
public void add(String name, double value)
add
in interface ValueParser
name
- A String with the name.value
- A double with the value.public void add(String name, int value)
add
in interface ValueParser
name
- A String with the name.value
- An int with the value.public void add(String name, Integer value)
add
in interface ValueParser
name
- A String with the name.value
- An Integer with the value.public void add(String name, long value)
add
in interface ValueParser
name
- A String with the name.value
- A long with the value.public void add(String name, String value)
add
in interface ValueParser
name
- A String with the name.value
- A long with the value.public void add(String name, String[] value)
add
in interface ValueParser
name
- A String with the name.value
- A String Array.public Object remove(String name)
Map.remove()
.remove
in interface ValueParser
name
- the name of the mapped value to removeString[]
)
or null
if the key was not mapped.public String convert(String value)
convert
in interface ValueParser
value
- A String to be processed.public boolean containsKey(Object key)
containsKey
in interface ValueParser
key
- An Object with the key to search for.public Set<String> keySet()
keySet
in interface ValueParser
Set
of the keys.public String[] getKeys()
getKeys
in interface ValueParser
public boolean getBoolean(String name, boolean defaultValue)
getBoolean
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public boolean getBoolean(String name)
getBoolean
in interface ValueParser
name
- A String with the name.public boolean[] getBooleans(String name)
getBooleans
in interface ValueParser
name
- A String with the name.public Boolean getBooleanObject(String name)
Valid values for true: true, on, 1, yes
Valid values for false: false, off, 0, no
The string is compared without reguard to case.
getBooleanObject
in interface ValueParser
name
- A String with the name.public Boolean getBooleanObject(String name, Boolean defaultValue)
Valid values for true: true, on, 1, yes
Valid values for false: false, off, 0, no
The string is compared without reguard to case.
getBooleanObject
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public Boolean[] getBooleanObjects(String name)
getBooleanObjects
in interface ValueParser
name
- A String with the name.public double getDouble(String name, double defaultValue)
getDouble
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public double getDouble(String name)
getDouble
in interface ValueParser
name
- A String with the name.public double[] getDoubles(String name)
getDoubles
in interface ValueParser
name
- A String with the name.public Double getDoubleObject(String name, Double defaultValue)
getDoubleObject
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public Double getDoubleObject(String name)
getDoubleObject
in interface ValueParser
name
- A String with the name.public Double[] getDoubleObjects(String name)
getDoubleObjects
in interface ValueParser
name
- A String with the name.public float getFloat(String name, float defaultValue)
getFloat
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public float getFloat(String name)
getFloat
in interface ValueParser
name
- A String with the name.public float[] getFloats(String name)
getFloats
in interface ValueParser
name
- A String with the name.public Float getFloatObject(String name, Float defaultValue)
getFloatObject
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public Float getFloatObject(String name)
getFloatObject
in interface ValueParser
name
- A String with the name.public Float[] getFloatObjects(String name)
getFloatObjects
in interface ValueParser
name
- A String with the name.public BigDecimal getBigDecimal(String name, BigDecimal defaultValue)
getBigDecimal
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public BigDecimal getBigDecimal(String name)
getBigDecimal
in interface ValueParser
name
- A String with the name.public BigDecimal[] getBigDecimals(String name)
getBigDecimals
in interface ValueParser
name
- A String with the name.public int getInt(String name, int defaultValue)
getInt
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public int getInt(String name)
getInt
in interface ValueParser
name
- A String with the name.public int[] getInts(String name)
getInts
in interface ValueParser
name
- A String with the name.public Integer getIntObject(String name, Integer defaultValue)
getIntObject
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public Integer getIntObject(String name)
getIntObject
in interface ValueParser
name
- A String with the name.public Integer[] getIntObjects(String name)
getIntObjects
in interface ValueParser
name
- A String with the name.public long getLong(String name, long defaultValue)
getLong
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public long getLong(String name)
getLong
in interface ValueParser
name
- A String with the name.public long[] getLongs(String name)
getLongs
in interface ValueParser
name
- A String with the name.public Long[] getLongObjects(String name)
getLongObjects
in interface ValueParser
name
- A String with the name.public Long getLongObject(String name)
getLongObject
in interface ValueParser
name
- A String with the name.public Long getLongObject(String name, Long defaultValue)
getLongObject
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public byte getByte(String name, byte defaultValue)
getByte
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public byte getByte(String name)
getByte
in interface ValueParser
name
- A String with the name.public byte[] getBytes(String name) throws UnsupportedEncodingException
getBytes
in interface ValueParser
name
- A String with the name.UnsupportedEncodingException
- Generic exceptionpublic Byte getByteObject(String name, Byte defaultValue)
getByteObject
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public Byte getByteObject(String name)
getByteObject
in interface ValueParser
name
- A String with the name.public String getString(String name)
getString
in interface ValueParser
name
- A String with the name.public String get(String name)
$data.Parameters.form_variable_name
get
in interface ValueParser
name
- A String with the name.public String getString(String name, String defaultValue)
getString
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public void setString(String name, String value)
setString
in interface ValueParser
name
- The name of the parameter.value
- The value to set.public String[] getStrings(String name)
getStrings
in interface ValueParser
name
- A String with the name.public String[] getStrings(String name, String[] defaultValue)
getStrings
in interface ValueParser
name
- A String with the name.defaultValue
- The default value.public void setStrings(String name, String[] values)
setStrings
in interface ValueParser
name
- The name of the parameter.values
- The value to set.public Object getObject(String name)
getObject
in interface ValueParser
name
- A String with the name.public Object[] getObjects(String name)
getObjects
in interface ValueParser
name
- A String with the name.public Date getDate(String name, DateFormat df, Date defaultValue)
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.getDate
in interface ValueParser
name
- A String with the name.df
- A DateFormat.defaultValue
- The default value.public Date getDate(String name)
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.getDate
in interface ValueParser
name
- A String with the name.public Date getDate(String name, DateFormat df)
Date
object. String is parsed by supplied
DateFormat. If the name does not exist, return null.getDate
in interface ValueParser
name
- A String with the name.df
- A DateFormat.public void setProperties(Object bean) throws Exception
setProperties
in interface ValueParser
bean
- An Object.Exception
- a generic exception.public String toString()
toString
in interface ValueParser
toString
in class Object
protected Object[] getToStringParam(String name)
name
- A string with the nameprotected void setProperty(Object bean, PropertyDescriptor prop) throws Exception
bean
- An Object.prop
- A PropertyDescriptor.Exception
- a generic exception.protected void putParam(String name, String[] value)
name
- A String with the name.value
- An array of Objects with the values.protected String[] getParam(String name)
name
- A string with the namepublic boolean isDisposed()
public String convertAndTrim(String value)
convertAndTrim
in interface ValueParser
value
- the String to convertpublic String convertAndTrim(String value, ValueParser.URLCaseFolding fold)
convertAndTrim
in interface ValueParser
value
- A String to be processed.fold
- The parameter folding to be applied
(see ParserService
)public ValueParser.URLCaseFolding getUrlFolding()
getUrlFolding
in interface ValueParser
public boolean isValid()
Copyright © 2005–2019 The Apache Software Foundation. All rights reserved.