Class ContextTool
- java.lang.Object
-
- org.apache.velocity.tools.generic.SafeConfig
-
- org.apache.velocity.tools.generic.ContextTool
-
- All Implemented Interfaces:
java.io.Serializable
@DefaultKey("context") @InvalidScope({"application","session"}) public class ContextTool extends SafeConfig implements java.io.Serializable
Tool for convenient access to
Contextdata 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
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.velocity.context.Contextcontextprotected java.util.Map<java.lang.String,java.lang.Object>toolbox-
Fields inherited from class org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY
-
-
Constructor Summary
Constructors Constructor Description ContextTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidconfigure(ValueParser parser)Initializes this instance for the current request.booleancontains(java.lang.Object refName)Returnstrueif the context contains a value for the specified reference name (aka context key).protected voidfillKeyset(java.util.Set keys)Actually do the work of filling in the set of keys forgetKeys()here so subclasses can add keys too.java.lang.Objectget(java.lang.Object refName)Retrieves the value for the specified reference name (aka context key).java.util.SetgetKeys()Return aSetof the available reference keys in the current context.org.apache.velocity.context.ContextgetThis()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 toolboxMapfor this context.java.util.SetgetValues()Return aSetof the available values in the current context.-
Methods inherited from class org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
-
-
-
Method Detail
-
configure
protected void configure(ValueParser parser)
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:
configurein classSafeConfig- Parameters:
parser- configuration values
-
getThis
public org.apache.velocity.context.Context getThis()
Returns the context being analyzed by this tool.- Returns:
- analyzed context
-
getToolbox
public java.util.Map<java.lang.String,java.lang.Object> getToolbox()
Returns a read-only view of the toolbox
Mapfor this context.- Returns:
- a map of all available tools for this request
or
nullif such a map is not available
-
getKeys
public java.util.Set getKeys()
Return a
Setof the available reference keys in the current context.- Returns:
- keys set
-
fillKeyset
protected void fillKeyset(java.util.Set keys)
Actually do the work of filling in the set of keys forgetKeys()here so subclasses can add keys too.- Parameters:
keys- set to fill with keys
-
getValues
public java.util.Set getValues()
Return a
Setof the available values in the current context.- Returns:
- values set
-
contains
public boolean contains(java.lang.Object refName)
Returns
trueif the context contains a value for the specified reference name (aka context key).- Parameters:
refName- context key- Returns:
trueif key is present in the context
-
get
public java.lang.Object get(java.lang.Object refName)
Retrieves the value for the specified reference name (aka context key).- Parameters:
refName- context key- Returns:
- found value, or null
-
-