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 FormatConfig
DEFAULT_FORMAT, FORMAT_KEYFields inherited from class LocaleConfig
DEFAULT_LOCALEFields inherited from class 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 FormatConfig
getFormat, setFormatMethods inherited from class LocaleConfig
getLocale, setLocale, toLocaleMethods inherited from class SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeModeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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
-
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
-
getString
-
getBoolean
-
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
-
getInteger
-
getLong
-
getLong
-
getDouble
-
getDouble
-
getNumber
-
getLocale
-
getNumber
-
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
-
getStrings
-
getBooleans
-
getNumbers
-
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
-
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
-
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
-
isEmpty
-
containsKey
- Specified by:
containsKeyin interfaceMap<String,Object>
-
containsValue
- Specified by:
containsValuein interfaceMap<String,Object>
-
get
-
put
-
remove
-
putAll
-
clear
-
keySet
-
values
-
entrySet
-
toString
-