|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.velocity.tools.generic.ValueParser
public class ValueParser
Utility class for easy parsing of String values held in a Map.
Template example(s): $parser.foo -> bar $parser.getNumber('baz') -> 12.6 $parser.getInt('baz') -> 12 $parser.getNumbers('baz') -> [12.6] Toolbox configuration: <tool> <key>parser</key> <class>org.apache.velocity.generic.ValueParser</class> </tool>
This comes in very handy when parsing parameters.
Field Summary | |
---|---|
private java.lang.String |
delimiter
|
private java.util.Map |
source
|
Constructor Summary | |
---|---|
ValueParser()
|
|
ValueParser(java.util.Map source)
|
Method Summary | |
---|---|
boolean |
exists(java.lang.String key)
Convenience method for checking whether a certain parameter exists. |
java.lang.Object |
get(java.lang.String key)
Convenience method for use in Velocity templates. |
java.lang.Boolean |
getBoolean(java.lang.String key)
|
boolean |
getBoolean(java.lang.String key,
boolean alternate)
|
java.lang.Boolean |
getBoolean(java.lang.String key,
java.lang.Boolean alternate)
|
java.lang.Boolean[] |
getBooleans(java.lang.String key)
|
java.lang.Double |
getDouble(java.lang.String key)
|
double |
getDouble(java.lang.String key,
double alternate)
|
java.lang.Double |
getDouble(java.lang.String key,
java.lang.Double alternate)
|
double[] |
getDoubles(java.lang.String key)
|
int |
getInt(java.lang.String key,
int alternate)
|
java.lang.Integer |
getInteger(java.lang.String key)
|
java.lang.Integer |
getInteger(java.lang.String key,
java.lang.Integer alternate)
|
int[] |
getInts(java.lang.String key)
|
java.util.Locale |
getLocale(java.lang.String key)
|
java.util.Locale |
getLocale(java.lang.String key,
java.util.Locale alternate)
|
java.util.Locale[] |
getLocales(java.lang.String key)
|
java.lang.Number |
getNumber(java.lang.String key)
|
java.lang.Number |
getNumber(java.lang.String key,
java.lang.Number alternate)
|
java.lang.Number[] |
getNumbers(java.lang.String key)
|
protected java.util.Map |
getSource()
|
java.lang.String |
getString(java.lang.String key)
|
java.lang.String |
getString(java.lang.String key,
java.lang.String alternate)
|
java.lang.String[] |
getStrings(java.lang.String key)
|
protected java.lang.String |
getStringsDelimiter()
Returns the delimiter used for separating values in a single String value. |
protected java.lang.Boolean |
parseBoolean(java.lang.String value)
Converts a parameter value into a Boolean
Sub-classes can override to allow for customized boolean parsing. |
protected java.util.Locale |
parseLocale(java.lang.String value)
Converts a String value into a Locale. |
protected java.lang.Number |
parseNumber(java.lang.String value)
Converts a parameter value into a Number
This is used as the base for all numeric parsing methods. |
protected java.lang.String[] |
parseStringList(java.lang.String value)
Converts a single String value into an array of Strings by splitting it on the tool's set delimiter. |
protected void |
setSource(java.util.Map source)
|
protected void |
setStringsDelimiter(java.lang.String delimiter)
Sets the delimiter used for separating values in a single String value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.util.Map source
private java.lang.String delimiter
Constructor Detail |
---|
public ValueParser()
public ValueParser(java.util.Map source)
Method Detail |
---|
protected void setSource(java.util.Map source)
protected java.util.Map getSource()
protected final void setStringsDelimiter(java.lang.String delimiter)
parseStringList(java.lang.String)
protected final java.lang.String getStringsDelimiter()
parseStringList(java.lang.String)
public boolean exists(java.lang.String key)
key
- the parameter's key
true
if a parameter exists for the specified
key; otherwise, returns false
.public java.lang.Object get(java.lang.String key)
key
- the parameter's key
null
if there is no matching
parameterpublic java.lang.String getString(java.lang.String key)
key
- the parameter's key
null
if there is no matching
parameterpublic java.lang.String getString(java.lang.String key, java.lang.String alternate)
key
- the desired parameter's keyalternate
- The alternate value
public java.lang.Boolean getBoolean(java.lang.String key)
key
- the desired parameter's key
Boolean
object for the specified key or
null
if no matching parameter is foundpublic boolean getBoolean(java.lang.String key, boolean alternate)
key
- the desired parameter's keyalternate
- The alternate boolean value
public java.lang.Boolean getBoolean(java.lang.String key, java.lang.Boolean alternate)
key
- the desired parameter's keyalternate
- the alternate Boolean
Boolean
for the specified key or the specified
alternate if no matching parameter is foundpublic java.lang.Integer getInteger(java.lang.String key)
key
- the desired parameter's key
Integer
for the specified key or
null
if no matching parameter is foundpublic java.lang.Integer getInteger(java.lang.String key, java.lang.Integer alternate)
key
- the desired parameter's keyalternate
- The alternate Integer
public java.lang.Double getDouble(java.lang.String key)
key
- the desired parameter's key
Double
for the specified key or
null
if no matching parameter is foundpublic java.lang.Double getDouble(java.lang.String key, java.lang.Double alternate)
key
- the desired parameter's keyalternate
- The alternate Double
public java.lang.Number getNumber(java.lang.String key)
key
- the desired parameter's key
Number
for the specified key or
null
if no matching parameter is foundpublic java.util.Locale getLocale(java.lang.String key)
key
- the desired parameter's key
Locale
for the specified key or
null
if no matching parameter is foundpublic java.lang.Number getNumber(java.lang.String key, java.lang.Number alternate)
key
- the desired parameter's keyalternate
- The alternate Number
public int getInt(java.lang.String key, int alternate)
key
- the desired parameter's keyalternate
- The alternate int value
public double getDouble(java.lang.String key, double alternate)
key
- the desired parameter's keyalternate
- The alternate double value
public java.util.Locale getLocale(java.lang.String key, java.util.Locale alternate)
key
- the desired parameter's keyalternate
- The alternate Locale
public java.lang.String[] getStrings(java.lang.String key)
key
- the key for the desired parameter
null
if the no values are associated with the given keypublic java.lang.Boolean[] getBooleans(java.lang.String key)
key
- the key for the desired parameter
public java.lang.Number[] getNumbers(java.lang.String key)
key
- the key for the desired parameter
null
if Numbers are not associated with it.public int[] getInts(java.lang.String key)
key
- the key for the desired parameter
null
if numbers are not associated with it.public double[] getDoubles(java.lang.String key)
key
- the key for the desired parameter
null
if numbers are not associated with it.public java.util.Locale[] getLocales(java.lang.String key)
key
- the key for the desired parameter
null
if Locales are not associated with it.protected java.lang.Number parseNumber(java.lang.String value) throws java.lang.NumberFormatException
Number
This is used as the base for all numeric parsing methods. So,
sub-classes can override to allow for customized number parsing.
(e.g. to handle fractions, compound numbers, etc.)
value
- the string to be parsed
Number
java.lang.NumberFormatException
protected java.lang.Boolean parseBoolean(java.lang.String value)
Boolean
Sub-classes can override to allow for customized boolean parsing.
(e.g. to handle "Yes/No" or "T/F")
value
- the string to be parsed
Boolean
protected java.lang.String[] parseStringList(java.lang.String value)
protected java.util.Locale parseLocale(java.lang.String value)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |