Class ContextTool
java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.ContextTool
- Direct Known Subclasses:
ViewContextTool
@DefaultKey("context")
@InvalidScope({"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.
- Since:
- VelocityTools 2.0
- Version:
- $Id: ContextTool.java 385122 2006-03-11 18:37:42Z nbubna $
- Author:
- Nathan Bubna
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.velocity.context.Context
Fields inherited from class org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, OLD_LOCK_CONFIG_KEY, SAFE_MODE_KEY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
configure
(ValueParser parser) Initializes this instance for the current request.boolean
Returnstrue
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 forgetKeys()
here so subclasses can add keys too.Retrieves the value for the specified reference name (aka context key).getKeys()
Return aSet
of the available reference keys in the current context.org.apache.velocity.context.Context
getThis()
Returns the context being analyzed by this tool.Returns a read-only view of the toolboxMap
for this context.Return aSet
of the available values in the current context.Methods inherited from class org.apache.velocity.tools.generic.SafeConfig
configure, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
Field Details
-
context
protected org.apache.velocity.context.Context context -
toolbox
-
-
Constructor Details
-
ContextTool
public ContextTool()
-
-
Method Details
-
configure
Initializes this instance for the current request. Also looks for a safe-mode configuration setting. By default, safeMode is true and thus keys with '.' in them are hidden.- Overrides:
configure
in classSafeConfig
-
getThis
public org.apache.velocity.context.Context getThis()Returns the context being analyzed by this tool. -
getToolbox
Returns a read-only view of the toolbox
Map
for this context.- Returns:
- a map of all available tools for this request
or
null
if such a map is not available
-
getKeys
Return a
Set
of the available reference keys in the current context. -
fillKeyset
Actually do the work of filling in the set of keys forgetKeys()
here so subclasses can add keys too. -
getValues
Return a
Set
of the available values in the current context. -
contains
Returns
true
if the context contains a value for the specified reference name (aka context key). -
get
Retrieves the value for the specified reference name (aka context key).
-