Package org.apache.velocity.tools
Class ToolContext
- java.lang.Object
-
- org.apache.velocity.tools.ToolContext
-
- All Implemented Interfaces:
org.apache.velocity.context.Context
public class ToolContext extends java.lang.Object implements org.apache.velocity.context.ContextContextimplementation that keeps a list ofToolboxes and returns them as requested, using its internal context Map as the dynamic properties passed to the requested tools when they are first created.- Version:
- $Id: ToolContext.java 511959 2007-02-26 19:24:39Z nbubna $
- Author:
- Nathan Bubna
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCATCH_EXCEPTIONS_KEYstatic java.lang.StringCONTEXT_KEYstatic java.lang.StringENGINE_KEYstatic java.lang.StringLOCALE_KEYstatic java.lang.StringLOG_KEYstatic java.lang.StringPATH_KEYstatic java.lang.StringTOOLKEY_KEY
-
Constructor Summary
Constructors Constructor Description ToolContext()ToolContext(java.util.Map<java.lang.String,java.lang.Object> toolProps)Creates an instance starting with the specified tool properties.ToolContext(org.apache.velocity.app.VelocityEngine engine)Creates an instance that automatically has the specified VelocityEngine and related tool properties set.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddToolbox(Toolbox toolbox)booleancontainsKey(java.lang.String key)protected java.lang.ObjectfindTool(java.lang.String key)java.lang.Objectget(java.lang.String key)java.lang.String[]getKeys()java.util.Map<java.lang.String,java.lang.Object>getToolbox()Returns aMapof all tools available to this context.protected java.util.List<Toolbox>getToolboxes()java.util.Map<java.lang.String,java.lang.Class>getToolClassMap()Gets a map of keys to classes for all available tools.protected java.util.Map<java.lang.String,java.lang.Object>getToolProperties()booleangetUserCanOverwriteTools()Default istrue.protected java.lang.ObjectinternalGet(java.lang.String key)java.util.Set<java.lang.String>keySet()java.lang.Objectput(java.lang.String key, java.lang.Object value)voidputAll(java.util.Map context)voidputToolProperties(java.util.Map<java.lang.String,java.lang.Object> props)java.lang.ObjectputToolProperty(java.lang.String key, java.lang.Object value)voidputVelocityEngine(org.apache.velocity.app.VelocityEngine engine)Puts the specified VelocityEngine in the tool properties, as well as the Log for that engine.java.lang.Objectremove(java.lang.String key)voidsetUserCanOverwriteTools(boolean overwrite)Set whether or not tool references can be overwritten within a template.
-
-
-
Field Detail
-
PATH_KEY
public static final java.lang.String PATH_KEY
- See Also:
- Constant Field Values
-
CONTEXT_KEY
public static final java.lang.String CONTEXT_KEY
- See Also:
- Constant Field Values
-
ENGINE_KEY
public static final java.lang.String ENGINE_KEY
- See Also:
- Constant Field Values
-
LOCALE_KEY
public static final java.lang.String LOCALE_KEY
- See Also:
- Constant Field Values
-
LOG_KEY
public static final java.lang.String LOG_KEY
- See Also:
- Constant Field Values
-
TOOLKEY_KEY
public static final java.lang.String TOOLKEY_KEY
- See Also:
- Constant Field Values
-
CATCH_EXCEPTIONS_KEY
public static final java.lang.String CATCH_EXCEPTIONS_KEY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ToolContext
public ToolContext()
-
ToolContext
public ToolContext(org.apache.velocity.app.VelocityEngine engine)
Creates an instance that automatically has the specified VelocityEngine and related tool properties set.- Parameters:
engine- VelocityEngine instance
-
ToolContext
public ToolContext(java.util.Map<java.lang.String,java.lang.Object> toolProps)
Creates an instance starting with the specified tool properties.- Parameters:
toolProps- tools properties
-
-
Method Detail
-
setUserCanOverwriteTools
public void setUserCanOverwriteTools(boolean overwrite)
Set whether or not tool references can be overwritten within a template. The default value istrue. Set this to false if you want to ensure that your tool references are never replaced within the course of a template.- Parameters:
overwrite- flag value
-
getUserCanOverwriteTools
public boolean getUserCanOverwriteTools()
Default istrue.- Returns:
- flag value
- See Also:
setUserCanOverwriteTools(boolean)
-
addToolbox
public void addToolbox(Toolbox toolbox)
-
getToolbox
public java.util.Map<java.lang.String,java.lang.Object> getToolbox()
Returns aMapof all tools available to this context. NOTE: this is not a cheap operation as it will request and initialize an instance of every available tool.- Returns:
- aggregated toolbox of all available tools
-
getToolClassMap
public java.util.Map<java.lang.String,java.lang.Class> getToolClassMap()
Gets a map of keys to classes for all available tools. This does not include any data nor any local context values.- Returns:
- aggregated map of all available tools classes
-
getToolboxes
protected java.util.List<Toolbox> getToolboxes()
-
getToolProperties
protected java.util.Map<java.lang.String,java.lang.Object> getToolProperties()
-
putVelocityEngine
public void putVelocityEngine(org.apache.velocity.app.VelocityEngine engine)
Puts the specified VelocityEngine in the tool properties, as well as the Log for that engine. Last, if the specified engine has a MethodExceptionEventHandler configured, then this will automatically setCATCH_EXCEPTIONS_KEYto false in the tool properties.- Parameters:
engine- VelocityEngine instance
-
putToolProperty
public java.lang.Object putToolProperty(java.lang.String key, java.lang.Object value)
-
putToolProperties
public void putToolProperties(java.util.Map<java.lang.String,java.lang.Object> props)
-
put
public java.lang.Object put(java.lang.String key, java.lang.Object value)- Specified by:
putin interfaceorg.apache.velocity.context.Context
-
get
public java.lang.Object get(java.lang.String key)
- Specified by:
getin interfaceorg.apache.velocity.context.Context
-
internalGet
protected java.lang.Object internalGet(java.lang.String key)
-
findTool
protected java.lang.Object findTool(java.lang.String key)
-
keySet
public java.util.Set<java.lang.String> keySet()
-
containsKey
public boolean containsKey(java.lang.String key)
- Specified by:
containsKeyin interfaceorg.apache.velocity.context.Context
-
getKeys
public java.lang.String[] getKeys()
- Specified by:
getKeysin interfaceorg.apache.velocity.context.Context
-
remove
public java.lang.Object remove(java.lang.String key)
- Specified by:
removein interfaceorg.apache.velocity.context.Context
-
putAll
public void putAll(java.util.Map context)
-
-