|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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
@DefaultKey(value="params") @ValidScope(value="request") public class ParameterTool
Utility class for easy parsing of ServletRequest
parameters.
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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Field Summary | |
---|---|
private javax.servlet.ServletRequest |
request
|
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 | |
---|---|
ParameterTool()
Constructs a new instance |
|
ParameterTool(javax.servlet.ServletRequest request)
Constructs a new instance using the specified request. |
Method Summary | |
---|---|
protected void |
configure(ValueParser values)
Does the actual configuration. |
private java.util.Map<java.lang.String,java.lang.Object> |
expandSingletonArrays(java.util.Map<java.lang.String,java.lang.Object> original)
|
java.util.Map |
getAll()
Returns the map of all parameters available for the current request. |
protected javax.servlet.ServletRequest |
getRequest()
Returns the current ServletRequest for this instance. |
protected java.util.Map |
getSource()
Overrides ValueParser.getSource() to return the result of getRequest().getParameterMap() and expand singleton arrays within it first. |
java.lang.Object |
getValue(java.lang.String key)
Overrides ValueParser.getValue(String key) to retrieve the value from the ServletRequest instead of an arbitrary Map. |
java.lang.Object[] |
getValues(java.lang.String key)
Overrides ValueParser.getValues(String key) to retrieve Strings from the ServletRequest instead of an arbitrary Map. |
private boolean |
isSingletonArray(java.lang.Object value)
|
void |
setRequest(javax.servlet.ServletRequest request)
Sets the current ServletRequest |
protected void |
setSource(java.util.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 |
---|
equals, hashCode |
Field Detail |
---|
private javax.servlet.ServletRequest request
Constructor Detail |
---|
public ParameterTool()
public ParameterTool(javax.servlet.ServletRequest request)
request
- the ServletRequest
to be parsedMethod Detail |
---|
protected void configure(ValueParser values)
ValueParser
configure
in class ValueParser
public void setRequest(javax.servlet.ServletRequest request)
ServletRequest
request
- the ServletRequest
to be parsedprotected javax.servlet.ServletRequest getRequest()
ServletRequest
for this instance.
ServletRequest
java.lang.UnsupportedOperationException
- if the request is nullpublic java.lang.Object getValue(java.lang.String key)
getValue
in class ValueParser
key
- the parameter's key
null
if there is no matching
parameterpublic java.lang.Object[] getValues(java.lang.String key)
getValues
in class ValueParser
key
- the key for the desired parameter
null
if the parameter does not existprotected void setSource(java.util.Map source)
setSource
in class ValueParser
protected java.util.Map getSource()
getSource
in class ValueParser
public java.util.Map getAll()
private boolean isSingletonArray(java.lang.Object value)
private java.util.Map<java.lang.String,java.lang.Object> expandSingletonArrays(java.util.Map<java.lang.String,java.lang.Object> original)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |