org.apache.velocity.tools

## Class ToolManager

- java.lang.Object
- - org.apache.velocity.tools.ToolManager

    public class ToolManager
    extends Object

Manages tools for non-web applications. This simplifies the process of getting a tool-populated Velocity context for merging with templates. It allows for both direct configuration by passing in a `FactoryConfiguration` as well as configuration via a tools.xml or tools.properties file in either the classpath or the local file system.

Version:
  $Id: ToolManager.java 511959 2007-02-26 19:24:39Z nbubna $
Author:
  Nathan Bubna

### Field Summary

Fields
`protected ToolboxFactory` `factory`
`protected org.slf4j.Logger` `log`
`protected org.apache.velocity.app.VelocityEngine` `velocity`

### Constructor Summary

Constructors
Constructor and Description
`ToolManager()` Constructs an instance already configured to use the default tools and any configuration specified via a "org.apache.velocity.tools" system property.
`ToolManager(boolean includeDefaults)` Constructs an instance that may or not include default tools, and already configured with any configuration specified via a "org.apache.velocity.tools" system property.
`ToolManager(boolean autoConfig, boolean includeDefaults)` Constructs an instance that may or not include default tools, and which may or not be already configured with any configuration specified via a "org.apache.velocity.tools" system property.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `addToolboxes(ToolContext context)` Add toolboxes to contex
`void` `autoConfigure(boolean includeDefaults)` Autoconfiguration using the configuration file potentially found in the `org.apache.velocity.tools` system property.
`void` `configure(FactoryConfiguration config)` Configure the tool manager with this toolbox factory config
`void` `configure(String path)` Configure the tool manager with the provided configuration file
`ToolContext` `createContext()` create new context with configured toolboxes tools
`ToolContext` `createContext(Map<String,Object> toolProps)` create new context with configured toolboxes tools, using the provided tools properties
`protected Toolbox` `createToolbox(String scope)` Create a toolbox for the given scope
`protected FactoryConfiguration` `findConfig(String path)` Find a configuration file
`Toolbox` `getApplicationToolbox()` Get the toolbox for application scoped tools
`org.slf4j.Logger` `getLog()` Get logger
`Toolbox` `getRequestToolbox()` Get the toolbox for request scoped tools
`ToolboxFactory` `getToolboxFactory()` Returns the underlying `ToolboxFactory` being used.
`boolean` `getUserCanOverwriteTools()` Get whether template user can overwrite tools keys
`org.apache.velocity.app.VelocityEngine` `getVelocityEngine()` Get the underlying VelocityEngine being used.
`boolean` `hasApplicationTools()` Check whether this tool manager has application scoped tools
`boolean` `hasRequestTools()` Check whether this tool manager has request scoped tools
`protected boolean` `hasTools(String scope)` Check for the presence of tools in a given scope
`protected void` `initLog()` init logger
`protected void` `prepareContext(ToolContext context)` Prepare context
`void` `setToolboxFactory(ToolboxFactory factory)` Sets the underlying ToolboxFactory being used.
`void` `setUserCanOverwriteTools(boolean overwrite)` Set whether template user can overwrite tools keys
`void` `setVelocityEngine(org.apache.velocity.app.VelocityEngine engine)` Sets the underlying VelocityEngine being used.

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

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

### Field Detail

#### velocity

    protected org.apache.velocity.app.VelocityEngine velocity

#### factory

    protected ToolboxFactory factory

#### log

    protected org.slf4j.Logger log

### Constructor Detail

#### ToolManager

    public ToolManager()

Constructs an instance already configured to use the default tools and any configuration specified via a "org.apache.velocity.tools" system property.

#### ToolManager

    public ToolManager(boolean includeDefaults)

Constructs an instance that may or not include default tools, and already configured with any configuration specified via a "org.apache.velocity.tools" system property.

Parameters:
  `includeDefaults` - whether to include default tools

#### ToolManager

    public ToolManager(boolean autoConfig,
                       boolean includeDefaults)

Constructs an instance that may or not include default tools, and which may or not be already configured with any configuration specified via a "org.apache.velocity.tools" system property.

Parameters:
  `autoConfig` - whether to use configuration file specified in the `org.apache.velocity.tools` system property
  `includeDefaults` - whether to include default tools

### Method Detail

#### autoConfigure

    public void autoConfigure(boolean includeDefaults)

Autoconfiguration using the configuration file potentially found in the `org.apache.velocity.tools` system property.

Parameters:
  `includeDefaults` - whether to include default tools

#### configure

    public void configure(FactoryConfiguration config)

Configure the tool manager with this toolbox factory config

Parameters:
  `config` - toolbox factory config

#### configure

    public void configure(String path)

Configure the tool manager with the provided configuration file

Parameters:
  `path` - path to configuration file

#### findConfig

    protected FactoryConfiguration findConfig(String path)

Find a configuration file

Parameters:
  `path` - path to a configuration file
Returns:
  toolbox factory configuration

#### getToolboxFactory

    public ToolboxFactory getToolboxFactory()

Returns the underlying `ToolboxFactory` being used.

Returns:
  underlying toolbox factory

#### setToolboxFactory

    public void setToolboxFactory(ToolboxFactory factory)

Sets the underlying ToolboxFactory being used. If you use this, be sure that your ToolboxFactory is already properly configured.

Parameters:
  `factory` - toolbox factory

#### setVelocityEngine

    public void setVelocityEngine(org.apache.velocity.app.VelocityEngine engine)

Sets the underlying VelocityEngine being used. If you use this, be sure that your VelocityEngine is already properly configured and initialized.

Parameters:
  `engine` - VelocityEngine instance

#### getVelocityEngine

    public org.apache.velocity.app.VelocityEngine getVelocityEngine()

Get the underlying VelocityEngine being used.

Returns:
  VelocityEngine instance

#### setUserCanOverwriteTools

    public void setUserCanOverwriteTools(boolean overwrite)

Set whether template user can overwrite tools keys

Parameters:
  `overwrite` - flag value

#### getUserCanOverwriteTools

    public boolean getUserCanOverwriteTools()

Get whether template user can overwrite tools keys

Returns:
  flag value

#### getLog

    public org.slf4j.Logger getLog()

Get logger

Returns:
  logger

#### initLog

    protected void initLog()

init logger

#### createContext

    public ToolContext createContext()

create new context with configured toolboxes tools

Returns:
  newly created context

#### createContext

    public ToolContext createContext(Map<String,Object> toolProps)

create new context with configured toolboxes tools, using the provided tools properties

Parameters:
  `toolProps` - tools properties
Returns:
  newly created context

#### prepareContext

    protected void prepareContext(ToolContext context)

Prepare context

Parameters:
  `context` - tool context

#### addToolboxes

    protected void addToolboxes(ToolContext context)

Add toolboxes to contex

Parameters:
  `context` - context

#### hasTools

    protected boolean hasTools(String scope)

Check for the presence of tools in a given scope

Parameters:
  `scope` - scope to check
Returns:
  whether this scope contains tools

#### createToolbox

    protected Toolbox createToolbox(String scope)

Create a toolbox for the given scope

Parameters:
  `scope` - scope
Returns:
  newly created toolbox

#### hasRequestTools

    public boolean hasRequestTools()

Check whether this tool manager has request scoped tools

Returns:
  `true` if this tool manager has request scoped tools, `false` otherwise

#### getRequestToolbox

    public Toolbox getRequestToolbox()

Get the toolbox for request scoped tools

Returns:
  toolbox of request scoped tools

#### hasApplicationTools

    public boolean hasApplicationTools()

Check whether this tool manager has application scoped tools

Returns:
  `true` if this tool manager has application scoped tools, `false` otherwise

#### getApplicationToolbox

    public Toolbox getApplicationToolbox()

Get the toolbox for application scoped tools

Returns:
  toolbox of application scoped tools