org.apache.velocity.tools.generic
@DefaultKey(value="context") @InvalidScope(value={"application","session"}) public class ContextTool extends SafeConfig
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 Context |
context |
protected java.util.Map<java.lang.String,java.lang.Object> |
toolbox |
LOCK_CONFIG_KEY, OLD_LOCK_CONFIG_KEY, SAFE_MODE_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(java.lang.Object refName)
Returns
true if the context contains a value for the specified
reference name (aka context key). |
protected void |
fillKeyset(java.util.Set keys)
Actually do the work of filling in the set of keys
for
getKeys() here so subclasses can add keys too. |
java.lang.Object |
get(java.lang.Object refName)
Retrieves the value for the specified reference name (aka context key).
|
java.util.Set |
getKeys()
Return a
Set of the available reference keys in the current
context. |
Context |
getThis()
Returns the context being analyzed by this tool.
|
java.util.Map<java.lang.String,java.lang.Object> |
getToolbox()
Returns a read-only view of the toolbox
Map
for this context. |
java.util.Set |
getValues()
Return a
Set of the available values in the current
context. |
configure, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
protected Context context
protected java.util.Map<java.lang.String,java.lang.Object> toolbox
protected void configure(ValueParser parser)
configure
in class SafeConfig
public Context getThis()
public java.util.Map<java.lang.String,java.lang.Object> getToolbox()
Returns a read-only view of the toolbox Map
for this context.
null
if such a map is not availablepublic java.util.Set getKeys()
Return a Set
of the available reference keys in the current
context.
protected void fillKeyset(java.util.Set keys)
getKeys()
here so subclasses can add keys too.public java.util.Set getValues()
Return a Set
of the available values in the current
context.
public boolean contains(java.lang.Object refName)
Returns true
if the context contains a value for the specified
reference name (aka context key).
public java.lang.Object get(java.lang.Object refName)
Copyright (c) 2003-2007 Apache Software Foundation