org.apache.velocity.tools.view
Class ParameterTool

java.lang.Object
  extended by org.apache.velocity.tools.generic.AbstractLockConfig
      extended by org.apache.velocity.tools.generic.LocaleConfig
          extended by org.apache.velocity.tools.generic.ConversionTool
              extended by org.apache.velocity.tools.generic.ValueParser
                  extended by org.apache.velocity.tools.view.ParameterTool
Direct Known Subclasses:
ParameterParser

@DefaultKey(value="params")
@ValidScope(value="request")
public class ParameterTool
extends ValueParser

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.

Version:
$Revision: 545420 $ $Date: 2007-06-07 22:21:52 -0700 (Thu, 07 Jun 2007) $
Author:
Nathan Bubna

Field Summary
private  javax.servlet.ServletRequest request
           
 
Fields inherited from class org.apache.velocity.tools.generic.ConversionTool
DATE_FORMAT_KEY, DEFAULT_DATE_FORMAT, DEFAULT_NUMBER_FORMAT, DEFAULT_STRINGS_DELIMITER, NUMBER_FORMAT_KEY, STRINGS_DELIMITER_FORMAT_KEY
 
Fields inherited from class org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALE, LOCALE_KEY
 
Fields inherited from class org.apache.velocity.tools.generic.AbstractLockConfig
LOCK_CONFIG_KEY
 
Constructor Summary
ParameterTool()
          Constructs a new instance
ParameterTool(javax.servlet.ServletRequest request)
          Constructs a new instance using the specified request.
 
Method Summary
 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().
 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.
 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
exists, get, getBoolean, getBoolean, getBoolean, getBooleans, getDouble, getDouble, getDouble, getDoubles, getInt, getInteger, getInteger, getInts, getLocale, getLocale, getLocales, getNumber, getNumber, getNumbers, getString, getString, getStrings
 
Methods inherited from class org.apache.velocity.tools.generic.ConversionTool
configure, getDateFormat, getNumberFormat, getStringsDelimiter, parseBoolean, parseDate, parseDate, parseDate, parseDate, parseDate, parseLocale, parseNumber, parseNumber, parseNumber, parseNumber, parseStringList, setDateFormat, setNumberFormat, setStringsDelimiter, toBoolean, toBooleans, toBooleans, toCalendar, toCalendars, toCalendars, toDate, toDates, toDates, toDouble, toDoubles, toInteger, toInts, toLocale, toLocales, toLocales, toNumber, toNumbers, toNumbers, toString, toString, toStrings
 
Methods inherited from class org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale
 
Methods inherited from class org.apache.velocity.tools.generic.AbstractLockConfig
configure, isConfigLocked
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

request

private javax.servlet.ServletRequest request
Constructor Detail

ParameterTool

public ParameterTool()
Constructs a new instance


ParameterTool

public ParameterTool(javax.servlet.ServletRequest request)
Constructs a new instance using the specified request.

Parameters:
request - the ServletRequest to be parsed
Method Detail

setRequest

public void setRequest(javax.servlet.ServletRequest request)
Sets the current ServletRequest

Parameters:
request - the ServletRequest to be parsed

getRequest

protected javax.servlet.ServletRequest getRequest()
Returns the current ServletRequest for this instance.

Returns:
the current ServletRequest
Throws:
java.lang.UnsupportedOperationException - if the request is null

getValue

public 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.

Overrides:
getValue in class ValueParser
Parameters:
key - the parameter's key
Returns:
parameter matching the specified key or null if there is no matching parameter

getValues

public java.lang.Object[] getValues(java.lang.String key)
Overrides ValueParser.getValues(String key) to retrieve Strings from the ServletRequest instead of an arbitrary Map.

Overrides:
getValues in class ValueParser
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 null if the parameter does not exist

setSource

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.

Overrides:
setSource in class ValueParser

getSource

protected java.util.Map getSource()
Overrides ValueParser.getSource() to return the result of getRequest().getParameterMap().

Overrides:
getSource in class ValueParser

getAll

public java.util.Map getAll()
Returns the map of all parameters available for the current request.



Copyright (c) 2003-2007 Apache Software Foundation