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 Object
    implements org.apache.velocity.context.Context

`Context` implementation that keeps a list of `Toolbox`es 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
`static String` `CATCH_EXCEPTIONS_KEY`
`static String` `CONTEXT_KEY`
`static String` `ENGINE_KEY`
`static String` `LOCALE_KEY`
`static String` `LOG_KEY`
`static String` `PATH_KEY`
`static String` `TOOLKEY_KEY`

### Constructor Summary

Constructors
Constructor and Description
`ToolContext()`
`ToolContext(Map<String,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
`void` `addToolbox(Toolbox toolbox)`
`boolean` `containsKey(String key)`
`protected Object` `findTool(String key)`
`Object` `get(String key)`
`String[]` `getKeys()`
`Map<String,Object>` `getToolbox()` Returns a `Map` of all tools available to this context.
`protected List<Toolbox>` `getToolboxes()`
`Map<String,Class>` `getToolClassMap()` Gets a map of keys to classes for all available tools.
`protected Map<String,Object>` `getToolProperties()`
`boolean` `getUserCanOverwriteTools()` Default is `true`.
`protected Object` `internalGet(String key)`
`Set<String>` `keySet()`
`Object` `put(String key, Object value)`
`void` `putAll(Map context)`
`void` `putToolProperties(Map<String,Object> props)`
`Object` `putToolProperty(String key, Object value)`
`void` `putVelocityEngine(org.apache.velocity.app.VelocityEngine engine)` Puts the specified VelocityEngine in the tool properties, as well as the Log for that engine.
`Object` `remove(String key)`
`void` `setUserCanOverwriteTools(boolean overwrite)` Set whether or not tool references can be overwritten within a template.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### PATH_KEY

    public static final String PATH_KEY

See Also:
  Constant Field Values

#### CONTEXT_KEY

    public static final String CONTEXT_KEY

See Also:
  Constant Field Values

#### ENGINE_KEY

    public static final String ENGINE_KEY

See Also:
  Constant Field Values

#### LOCALE_KEY

    public static final String LOCALE_KEY

See Also:
  Constant Field Values

#### LOG_KEY

    public static final String LOG_KEY

See Also:
  Constant Field Values

#### TOOLKEY_KEY

    public static final String TOOLKEY_KEY

See Also:
  Constant Field Values

#### CATCH_EXCEPTIONS_KEY

    public static final 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(Map<String,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 is `true`. 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 is `true`.

Returns:
  flag value
See Also:
  `setUserCanOverwriteTools(boolean)`

#### addToolbox

    public void addToolbox(Toolbox toolbox)

#### getToolbox

    public Map<String,Object> getToolbox()

Returns a `Map` of 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 Map<String,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 List<Toolbox> getToolboxes()

#### getToolProperties

    protected Map<String,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 set `CATCH_EXCEPTIONS_KEY` to false in the tool properties.

Parameters:
  `engine` - VelocityEngine instance

#### putToolProperty

    public Object putToolProperty(String key,
                                  Object value)

#### putToolProperties

    public void putToolProperties(Map<String,Object> props)

#### put

    public Object put(String key,
                      Object value)

Specified by:
  `put` in interface `org.apache.velocity.context.Context`

#### get

    public Object get(String key)

Specified by:
  `get` in interface `org.apache.velocity.context.Context`

#### internalGet

    protected Object internalGet(String key)

#### findTool

    protected Object findTool(String key)

#### keySet

    public Set<String> keySet()

#### containsKey

    public boolean containsKey(String key)

Specified by:
  `containsKey` in interface `org.apache.velocity.context.Context`

#### getKeys

    public String[] getKeys()

Specified by:
  `getKeys` in interface `org.apache.velocity.context.Context`

#### remove

    public Object remove(String key)

Specified by:
  `remove` in interface `org.apache.velocity.context.Context`

#### putAll

    public void putAll(Map context)