Class ValueParser
java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.FormatConfig
org.apache.velocity.tools.generic.ValueParser
@DefaultKey("parser")
@InvalidScope("session")
@SkipSetters
public class ValueParser
extends FormatConfig
implements Map<String,Object>
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- Since:
- VelocityTools 1.2
- Version:
- $Revision$ $Date$
- Author:
- Nathan Bubna
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe key used for specifying whether to support subkeysstatic final Stringstatic final StringThe key used for specifying whether to be read-onlystatic final StringFields inherited from class org.apache.velocity.tools.generic.FormatConfig
DEFAULT_FORMAT, FORMAT_KEYFields inherited from class org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALEFields inherited from class org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()protected voidconfigure(ValueParser values) Does the actual configuration.booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()booleanConvenience method for checking whether a certain parameter exists.Convenience method for use in Velocity templates.protected booleanAre subkeys allowed ?getBoolean(String key) booleangetBoolean(String key, boolean alternate) getBoolean(String key, Boolean alternate) Boolean[]getBooleans(String key) doubledouble[]getDoubles(String key) intgetInteger(String key) getInteger(String key, Integer alternate) int[]Locale[]getLocales(String key) Number[]getNumbers(String key) protected booleanIs the Map read-only?getSource(boolean create) String[]getStrings(String key) subkey getter that returns a map subkey#2 -> value for every "subkey.subkey2" found entryreturns the set of all possible first-level subkeys, including complete keys without dots (or returns keySet() if allowSubKeys is false)Returns the value mapped to the specified key in theMapreturned bygetSource().Object[]Returns an array of values.booleanDetermines whether there are subkeys available in the source map.booleanisEmpty()keySet()protected String[]parseStringList(String value) voidprotected voidsetAllowSubkeys(boolean allow) allow or disallow subkeysprotected voidsetReadOnly(boolean ro) Set or unset read-only behaviourprotected voidprotected final voidsetStringsDelimiter(String stringsDelimiter) Sets the delimiter used for separating values in a single String value.intsize()toString()values()Methods inherited from class org.apache.velocity.tools.generic.FormatConfig
getFormat, setFormatMethods inherited from class org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale, toLocaleMethods inherited from class org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeModeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
STRINGS_DELIMITER_FORMAT_KEY
- See Also:
-
DEFAULT_STRINGS_DELIMITER
- See Also:
-
ALLOWSUBKEYS_KEY
The key used for specifying whether to support subkeys- See Also:
-
READONLY_KEY
The key used for specifying whether to be read-only- See Also:
-
-
Constructor Details
-
ValueParser
public ValueParser() -
ValueParser
-
-
Method Details
-
setSource
-
getSource
-
getSource
-
getAllowSubkeys
protected boolean getAllowSubkeys()Are subkeys allowed ?- Returns:
- yes/no
-
setAllowSubkeys
protected void setAllowSubkeys(boolean allow) allow or disallow subkeys- Parameters:
allow- flag value
-
getReadOnly
protected boolean getReadOnly()Is the Map read-only?- Returns:
- yes/no
-
setReadOnly
protected void setReadOnly(boolean ro) Set or unset read-only behaviour- Parameters:
ro- flag value
-
setStringsDelimiter
Sets the delimiter used for separating values in a single String value. The default string delimiter is a comma.- Parameters:
stringsDelimiter- strings delimiter- See Also:
-
configure
Does the actual configuration. This is protected, so subclasses may share the same ValueParser and call configure at any time, while preventing templates from doing so when configure(Map) is locked.- Overrides:
configurein classFormatConfig- Parameters:
values- configuration values
-
exists
Convenience method for checking whether a certain parameter exists.- Parameters:
key- the parameter's key- Returns:
trueif a parameter exists for the specified key; otherwise, returnsfalse.
-
get
Convenience method for use in Velocity templates. This allows for easy "dot" access to parameters. e.g. $params.foo instead of $params.getString('foo')- Parameters:
key- the parameter's key- Returns:
- parameter matching the specified key or
nullif there is no matching parameter
-
getValue
Returns the value mapped to the specified key in theMapreturned bygetSource(). If there is no source, then this will always returnnull.- Parameters:
key- property key- Returns:
- property value, or null
-
getValue
- Parameters:
key- the desired parameter's keyalternate- The alternate value- Returns:
- parameter matching the specified key or the specified alternate Object if there is no matching parameter
-
parseStringList
-
getValues
Returns an array of values. If the internal value is a string, it is split using the configured delimitor (',' by default).
If the internal value is not an array or is a string without any delimiter, a singletin array is returned.
- Parameters:
key- the desired parameter's key- Returns:
- array of values, or null of the key has not been found. specified alternate Object if there is no matching parameter
-
getString
- Parameters:
key- the parameter's key- Returns:
- parameter matching the specified key or
nullif there is no matching parameter
-
getString
- Parameters:
key- the desired parameter's keyalternate- The alternate value- Returns:
- parameter matching the specified key or the specified alternate String if there is no matching parameter
-
getBoolean
- Parameters:
key- the desired parameter's key- Returns:
- a
Booleanobject for the specified key ornullif no matching parameter is found
-
getBoolean
- Parameters:
key- the desired parameter's keyalternate- The alternate boolean value- Returns:
- boolean value for the specified key or the alternate boolean is no value is found
-
getBoolean
-
getInteger
- Parameters:
key- the desired parameter's key- Returns:
- a
Integerfor the specified key ornullif no matching parameter is found
-
getInteger
- Parameters:
key- the desired parameter's keyalternate- The alternate Integer- Returns:
- an Integer for the specified key or the specified alternate if no matching parameter is found
-
getLong
- Parameters:
key- the desired parameter's key- Returns:
- a
Longfor the specified key ornullif no matching parameter is found
-
getLong
- Parameters:
key- the desired parameter's keyalternate- The alternate Long- Returns:
- a Long for the specified key or the specified alternate if no matching parameter is found
-
getDouble
- Parameters:
key- the desired parameter's key- Returns:
- a
Doublefor the specified key ornullif no matching parameter is found
-
getDouble
- Parameters:
key- the desired parameter's keyalternate- The alternate Double- Returns:
- an Double for the specified key or the specified alternate if no matching parameter is found
-
getNumber
- Parameters:
key- the desired parameter's key- Returns:
- a
Numberfor the specified key ornullif no matching parameter is found
-
getLocale
- Parameters:
key- the desired parameter's key- Returns:
- a
Localefor the specified key ornullif no matching parameter is found
-
getNumber
- Parameters:
key- the desired parameter's keyalternate- The alternate Number- Returns:
- a Number for the specified key or the specified alternate if no matching parameter is found
-
getInt
- Parameters:
key- the desired parameter's keyalternate- The alternate int value- Returns:
- the int value for the specified key or the specified alternate value if no matching parameter is found
-
getDouble
- Parameters:
key- the desired parameter's keyalternate- The alternate double value- Returns:
- the double value for the specified key or the specified alternate value if no matching parameter is found
-
getLocale
- Parameters:
key- the desired parameter's keyalternate- The alternate Locale- Returns:
- a Locale for the specified key or the specified alternate if no matching parameter is found
-
getStrings
- Parameters:
key- the key for the desired parameter- Returns:
- an array of String objects containing all of the values
associated with the given key, or
nullif the no values are associated with the given key
-
getBooleans
- Parameters:
key- the key for the desired parameter- Returns:
- an array of Boolean objects associated with the given key.
-
getNumbers
- Parameters:
key- the key for the desired parameter- Returns:
- an array of Number objects associated with the given key,
or
nullif Numbers are not associated with it.
-
getInts
- Parameters:
key- the key for the desired parameter- Returns:
- an array of int values associated with the given key,
or
nullif numbers are not associated with it.
-
getDoubles
- Parameters:
key- the key for the desired parameter- Returns:
- an array of double values associated with the given key,
or
nullif numbers are not associated with it.
-
getLocales
- Parameters:
key- the key for the desired parameter- Returns:
- an array of Locale objects associated with the given key,
or
nullif Locales are not associated with it.
-
hasSubkeys
public boolean hasSubkeys()Determines whether there are subkeys available in the source map.- Returns:
trueif there are subkeys (key names containing a dot)
-
getSubkeys
returns the set of all possible first-level subkeys, including complete keys without dots (or returns keySet() if allowSubKeys is false)- Returns:
- the set of all possible first-level subkeys
-
getSubkey
subkey getter that returns a map subkey#2 -> value for every "subkey.subkey2" found entry- Parameters:
subkey- subkey to search for- Returns:
- the map of found values
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<String,Object>
-
containsValue
- Specified by:
containsValuein interfaceMap<String,Object>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
toString
-