@DefaultKey(value="context") @InvalidScope(value={"application","session"}) public class ContextTool extends SafeConfig implements Serializable
Tool for convenient access to Context
data and
meta-data.
Template example(s):
#foreach( $key in $context.keys ) $key = $context.get($key) #end Toolbox configuration: <tools> <toolbox scope="request"> <tool class="org.apache.velocity.tools.generic.ContextTool"/> </toolbox> </tools>
This class is only designed for use as a request-scope tool.
Modifier and Type | Field and Description |
---|---|
protected org.apache.velocity.context.Context |
context |
protected Map<String,Object> |
toolbox |
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY
Constructor and Description |
---|
ContextTool() |
Modifier and Type | Method and Description |
---|---|
protected void |
configure(ValueParser parser)
Initializes this instance for the current request.
|
boolean |
contains(Object refName)
Returns
true if the context contains a value for the specified
reference name (aka context key). |
protected void |
fillKeyset(Set keys)
Actually do the work of filling in the set of keys
for
getKeys() here so subclasses can add keys too. |
Object |
get(Object refName)
Retrieves the value for the specified reference name (aka context key).
|
Set |
getKeys()
Return a
Set of the available reference keys in the current
context. |
org.apache.velocity.context.Context |
getThis()
Returns the context being analyzed by this tool.
|
Map<String,Object> |
getToolbox()
Returns a read-only view of the toolbox
Map
for this context. |
Set |
getValues()
Return a
Set of the available values in the current
context. |
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
protected void configure(ValueParser parser)
configure
in class SafeConfig
parser
- configuration valuespublic org.apache.velocity.context.Context getThis()
public Map<String,Object> getToolbox()
Returns a read-only view of the toolbox Map
for this context.
null
if such a map is not availablepublic Set getKeys()
Return a Set
of the available reference keys in the current
context.
protected void fillKeyset(Set keys)
getKeys()
here so subclasses can add keys too.keys
- set to fill with keyspublic Set getValues()
Return a Set
of the available values in the current
context.
public boolean contains(Object refName)
Returns true
if the context contains a value for the specified
reference name (aka context key).
refName
- context keytrue
if key is present in the contextCopyright © 2002–2021 The Apache Software Foundation. All rights reserved.