|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.ConversionTool
org.apache.velocity.tools.generic.ValueParser
@DefaultKey(value="parser") public class ValueParser
Utility class for easy parsing of String values held in a Map.
This comes in very handy when parsing parameters.
When subkeys are allowed, getValue("foo") will also search for all keys of the form "foo.bar" and return a ValueParser of the type "bar" -> value for all found values.
TODO: someone doing java configuration ought to be able to put a source Map in the tool properties, allowing this to be used like other tools
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Field Summary | |
|---|---|
static String |
ALLOWSUBKEYS_KEY
The key used for specifying whether to support subkeys |
static String |
READONLY_KEY
The key used for specifying whether to be read-only |
| Fields inherited from class org.apache.velocity.tools.generic.ConversionTool |
|---|
DATE_FORMAT_KEY, DEFAULT_DATE_FORMAT, DEFAULT_NUMBER_FORMAT, DEFAULT_STRINGS_DELIMITER, DEFAULT_STRINGS_TRIM, NUMBER_FORMAT_KEY, STRINGS_DELIMITER_FORMAT_KEY, STRINGS_TRIM_KEY |
| Fields inherited from class org.apache.velocity.tools.generic.LocaleConfig |
|---|
DEFAULT_LOCALE |
| Fields inherited from class org.apache.velocity.tools.generic.SafeConfig |
|---|
LOCK_CONFIG_KEY, OLD_LOCK_CONFIG_KEY, SAFE_MODE_KEY |
| Constructor Summary | |
|---|---|
ValueParser()
|
|
ValueParser(Map<String,Object> source)
|
|
| Method Summary | |
|---|---|
void |
clear()
|
protected void |
configure(ValueParser values)
Does the actual configuration. |
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
|
Set<Map.Entry<String,Object>> |
entrySet()
|
boolean |
exists(String key)
Convenience method for checking whether a certain parameter exists. |
Object |
get(Object key)
|
Object |
get(String key)
Convenience method for use in Velocity templates. |
protected boolean |
getAllowSubkeys()
Are subkeys allowed ? |
Boolean |
getBoolean(String key)
|
boolean |
getBoolean(String key,
boolean alternate)
|
Boolean |
getBoolean(String key,
Boolean alternate)
|
Boolean[] |
getBooleans(String key)
|
Double |
getDouble(String key)
|
double |
getDouble(String key,
double alternate)
|
Double |
getDouble(String key,
Double alternate)
|
double[] |
getDoubles(String key)
|
int |
getInt(String key,
int alternate)
|
Integer |
getInteger(String key)
|
Integer |
getInteger(String key,
Integer alternate)
|
int[] |
getInts(String key)
|
Locale |
getLocale(String key)
|
Locale |
getLocale(String key,
Locale alternate)
|
Locale[] |
getLocales(String key)
|
Number |
getNumber(String key)
|
Number |
getNumber(String key,
Number alternate)
|
Number[] |
getNumbers(String key)
|
protected boolean |
getReadOnly()
Is the Map read-only? |
protected Map<String,Object> |
getSource()
|
String |
getString(String key)
|
String |
getString(String key,
String alternate)
|
String[] |
getStrings(String key)
|
protected ValueParser |
getSubkey(String subkey)
subkey getter that returns a map |
Object |
getValue(String key)
Returns the value mapped to the specified key in the Map returned by getSource(). |
Object |
getValue(String key,
Object alternate)
|
Object[] |
getValues(String key)
|
boolean |
hasSubkeys()
Determines whether there are subkeys available in the source map. |
boolean |
isEmpty()
|
Set<String> |
keySet()
|
Object |
put(String key,
Object value)
|
void |
putAll(Map<? extends String,? extends Object> m)
|
Object |
remove(Object key)
|
protected void |
setAllowSubkeys(boolean allow)
allow or disallow subkeys |
protected void |
setReadOnly(boolean ro)
Set or unset read-only behaviour |
protected void |
setSource(Map<String,Object> source)
|
int |
size()
|
String |
toString()
|
Collection |
values()
|
| Methods inherited from class org.apache.velocity.tools.generic.ConversionTool |
|---|
getDateFormat, getNumberFormat, getStringsDelimiter, getStringsTrim, parseBoolean, parseDate, parseDate, parseDate, parseDate, parseDate, parseLocale, parseNumber, parseNumber, parseNumber, parseNumber, parseStringList, setDateFormat, setNumberFormat, setStringsDelimiter, setStringsTrim, toBoolean, toBooleans, toBooleans, toCalendar, toCalendars, toCalendars, toDate, toDates, toDates, toDouble, toDoubles, toInteger, toIntegers, toInts, toLocale, toLocales, toLocales, toNumber, toNumbers, toNumbers, toString, toStrings |
| Methods inherited from class org.apache.velocity.tools.generic.LocaleConfig |
|---|
getLocale, setLocale |
| Methods inherited from class org.apache.velocity.tools.generic.SafeConfig |
|---|
configure, isConfigLocked, isSafeMode, setLockConfig, setSafeMode |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
equals, hashCode |
| Field Detail |
|---|
public static final String ALLOWSUBKEYS_KEY
public static final String READONLY_KEY
| Constructor Detail |
|---|
public ValueParser()
public ValueParser(Map<String,Object> source)
| Method Detail |
|---|
protected void setSource(Map<String,Object> source)
protected Map<String,Object> getSource()
protected boolean getAllowSubkeys()
protected void setAllowSubkeys(boolean allow)
allow - protected boolean getReadOnly()
protected void setReadOnly(boolean ro)
ro - protected void configure(ValueParser values)
configure in class ConversionToolpublic boolean exists(String key)
key - the parameter's key
true if a parameter exists for the specified
key; otherwise, returns false.public Object get(String key)
key - the parameter's key
null if there is no matching
parameterpublic Object getValue(String key)
Map returned by getSource(). If there is
no source, then this will always return null.
public Object getValue(String key,
Object alternate)
key - the desired parameter's keyalternate - The alternate value
public Object[] getValues(String key)
public String getString(String key)
key - the parameter's key
null if there is no matching
parameter
public String getString(String key,
String alternate)
key - the desired parameter's keyalternate - The alternate value
public Boolean getBoolean(String key)
key - the desired parameter's key
Boolean object for the specified key or
null if no matching parameter is found
public boolean getBoolean(String key,
boolean alternate)
key - the desired parameter's keyalternate - The alternate boolean value
public Boolean getBoolean(String key,
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 Integer getInteger(String key)
key - the desired parameter's key
Integer for the specified key or
null if no matching parameter is found
public Integer getInteger(String key,
Integer alternate)
key - the desired parameter's keyalternate - The alternate Integer
public Double getDouble(String key)
key - the desired parameter's key
Double for the specified key or
null if no matching parameter is found
public Double getDouble(String key,
Double alternate)
key - the desired parameter's keyalternate - The alternate Double
public Number getNumber(String key)
key - the desired parameter's key
Number for the specified key or
null if no matching parameter is foundpublic Locale getLocale(String key)
key - the desired parameter's key
Locale for the specified key or
null if no matching parameter is found
public Number getNumber(String key,
Number alternate)
key - the desired parameter's keyalternate - The alternate Number
public int getInt(String key,
int alternate)
key - the desired parameter's keyalternate - The alternate int value
public double getDouble(String key,
double alternate)
key - the desired parameter's keyalternate - The alternate double value
public Locale getLocale(String key,
Locale alternate)
key - the desired parameter's keyalternate - The alternate Locale
public String[] getStrings(String key)
key - the key for the desired parameter
null
if the no values are associated with the given keypublic Boolean[] getBooleans(String key)
key - the key for the desired parameter
public Number[] getNumbers(String key)
key - the key for the desired parameter
null if Numbers are not associated with it.public int[] getInts(String key)
key - the key for the desired parameter
null if numbers are not associated with it.public double[] getDoubles(String key)
key - the key for the desired parameter
null if numbers are not associated with it.public Locale[] getLocales(String key)
key - the key for the desired parameter
null if Locales are not associated with it.public boolean hasSubkeys()
protected ValueParser getSubkey(String subkey)
subkey - subkey to search for
public int size()
size in interface Map<String,Object>public boolean isEmpty()
isEmpty in interface Map<String,Object>public boolean containsKey(Object key)
containsKey in interface Map<String,Object>public boolean containsValue(Object value)
containsValue in interface Map<String,Object>public Object get(Object key)
get in interface Map<String,Object>
public Object put(String key,
Object value)
put in interface Map<String,Object>public Object remove(Object key)
remove in interface Map<String,Object>public void putAll(Map<? extends String,? extends Object> m)
putAll in interface Map<String,Object>public void clear()
clear in interface Map<String,Object>public Set<String> keySet()
keySet in interface Map<String,Object>public Collection values()
values in interface Map<String,Object>public Set<Map.Entry<String,Object>> entrySet()
entrySet in interface Map<String,Object>public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||