Package org.apache.velocity.tools.view
Class ParameterTool
- java.lang.Object
-
- org.apache.velocity.tools.generic.SafeConfig
-
- org.apache.velocity.tools.generic.LocaleConfig
-
- org.apache.velocity.tools.generic.ConversionTool
-
- org.apache.velocity.tools.generic.ValueParser
-
- org.apache.velocity.tools.view.ParameterTool
-
- Direct Known Subclasses:
ParameterParser
@DefaultKey("params") @ValidScope("request") public class ParameterTool extends ValueParser
Utility class for easy parsing of
ServletRequestparameters.Template example(s): $params.foo -> bar $params.getNumber('baz') -> 12.6 $params.getInt('baz') -> 12 $params.getNumbers('baz') -> [12.6] Toolbox configuration: <tools> <toolbox scope="request"> <tool class="org.apache.velocity.tools.view.ParameterTool"/> </toolbox> </tools>When used as a view tool, this should only be used in the request scope. This class is, however, quite useful in your application's controller, filter, or action code as well as in templates.
- Since:
- VelocityTools 2.0
- Version:
- $Revision$ $Date$
- Author:
- Nathan Bubna
-
-
Field Summary
-
Fields inherited from class org.apache.velocity.tools.generic.ValueParser
ALLOWSUBKEYS_KEY, READONLY_KEY
-
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
Constructors Constructor Description ParameterTool()Constructs a new instanceParameterTool(javax.servlet.ServletRequest request)Constructs a new instance using the specified request.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidconfigure(ValueParser values)Does the actual configuration.MapgetAll()Returns the map of all parameters available for the current request.protected javax.servlet.ServletRequestgetRequest()Returns the currentServletRequestfor this instance.protected MapgetSource()Overrides ValueParser.getSource() to return the result of getRequest().getParameterMap() and expand singleton arrays within it first.ObjectgetValue(String key)Overrides ValueParser.getValue(String key) to retrieve the value from the ServletRequest instead of an arbitrary Map.Object[]getValues(String key)Overrides ValueParser.getValues(String key) to retrieve Strings from the ServletRequest instead of an arbitrary Map.voidsetRequest(javax.servlet.ServletRequest request)Sets the currentServletRequestprotected voidsetSource(Map source)Overrides ValueParser.setSource(Map source) to throw an UnsupportedOperationException, because this class uses a servlet request as its source, not a Map.-
Methods inherited from class org.apache.velocity.tools.generic.ValueParser
clear, containsKey, containsValue, entrySet, exists, get, get, getAllowSubkeys, getBoolean, getBoolean, getBoolean, getBooleans, getDouble, getDouble, getDouble, getDoubles, getInt, getInteger, getInteger, getInts, getLocale, getLocale, getLocales, getNumber, getNumber, getNumbers, getReadOnly, getString, getString, getStrings, getSubkey, getValue, hasSubkeys, isEmpty, keySet, put, putAll, remove, setAllowSubkeys, setReadOnly, size, toString, 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
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
configure
protected void configure(ValueParser values)
Description copied from class:ValueParserDoes 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 classValueParser
-
setRequest
public void setRequest(javax.servlet.ServletRequest request)
Sets the currentServletRequest- Parameters:
request- theServletRequestto be parsed
-
getRequest
protected javax.servlet.ServletRequest getRequest()
Returns the currentServletRequestfor this instance.- Returns:
- the current
ServletRequest - Throws:
UnsupportedOperationException- if the request is null
-
getValue
public Object getValue(String key)
Overrides ValueParser.getValue(String key) to retrieve the value from the ServletRequest instead of an arbitrary Map.- Overrides:
getValuein classValueParser- Parameters:
key- the parameter's key- Returns:
- parameter matching the specified key or
nullif there is no matching parameter
-
getValues
public Object[] getValues(String key)
Overrides ValueParser.getValues(String key) to retrieve Strings from the ServletRequest instead of an arbitrary Map.- Overrides:
getValuesin classValueParser- Parameters:
key- the key for the desired parameter- Returns:
- an array of String objects containing all of the values
the given request parameter has, or
nullif the parameter does not exist
-
setSource
protected void setSource(Map source)
Overrides ValueParser.setSource(Map source) to throw an UnsupportedOperationException, because this class uses a servlet request as its source, not a Map.- Overrides:
setSourcein classValueParser
-
getSource
protected Map getSource()
Overrides ValueParser.getSource() to return the result of getRequest().getParameterMap() and expand singleton arrays within it first.- Overrides:
getSourcein classValueParser
-
getAll
public Map getAll()
Returns the map of all parameters available for the current request.
-
-