org.apache.velocity.tools.view

## Class ViewToolManager

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

Direct Known Subclasses:
  VelocityView

    public class ViewToolManager
    extends ToolManager

Manages tools for 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` or having one in the ServletContext attributes under `ServletUtils.CONFIGURATION_KEY`, 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
`static String` `CREATE_SESSION_PROPERTY`
`static String` `DEFAULT_TOOLBOX_KEY`
`static String` `PUBLISH_TOOLBOXES_PROPERTY`
`protected javax.servlet.ServletContext` `servletContext`

### Fields inherited from class org.apache.velocity.tools.ToolManager

`factory, log, velocity`

### Constructor Summary

Constructors
Constructor and Description
`ViewToolManager(javax.servlet.ServletContext app)` Constructs an instance already configured to use any configuration specified via a "org.apache.velocity.tools" system property.
`ViewToolManager(javax.servlet.ServletContext app, boolean includeDefaults)`
`ViewToolManager(javax.servlet.ServletContext app, boolean autoConfig, boolean includeDefaults)`

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `addToolboxes(ToolContext context)`
`void` `autoConfigure(boolean includeDefaults)`
`void` `configure(FactoryConfiguration config)`
`ViewToolContext` `createContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)`
`ToolContext` `createContext(Map<String,Object> toolProps)`
`protected FactoryConfiguration` `findConfig(String path)`
`boolean` `getCreateSession()`
`boolean` `getPublishToolboxes()`
`protected Toolbox` `getSessionToolbox()`
`Toolbox` `getSessionToolbox(javax.servlet.http.HttpSession session)`
`String` `getToolboxKey()`
`boolean` `hasSessionTools()`
`void` `prepareContext(ViewToolContext context, javax.servlet.http.HttpServletRequest request)`
`void` `publishApplicationTools()` Publish `Scope.APPLICATION` Toolbox.
`void` `publishToolboxes(javax.servlet.http.HttpServletRequest request)` Places the `Scope.REQUEST` `Toolbox` (if any) into the `HttpServletRequest` attributes using `Toolbox.KEY` as the key, places the `Scope.SESSION` Toolbox (if any) into the attributes of the `HttpSession` (if any) then ensures that the `Scope.APPLICATION` Toolbox (if any) has been placed in the `ServletContext` attributes.
`void` `publishToolboxes(javax.servlet.ServletRequest request)` Places the `Scope.REQUEST` `Toolbox` (if any) into the `ServletRequest` attributes using `Toolbox.KEY` as the key.
`void` `setCreateSession(boolean create)` Sets whether or not a new HttpSession should be created when there are session scoped tools to be stored in the session, but no session has been created yet.
`void` `setPublishToolboxes(boolean publish)` Sets whether or not the creation of a new `ViewToolContext` should make the various scoped `Toolbox` instances available publically via the HttpServletRequest/HttpSession/ServletContext attributes or simply add the Toolbox instances directly to the context.
`void` `setToolboxKey(String key)` Sets a new attribute key to be used for publishing each `Toolbox`.
`protected void` `unpublishApplicationTools()` Removes any published `Scope.APPLICATION` Toolbox.
`protected void` `updateGlobalProperties()` Checks the internal `ToolboxFactory` for any changes to the createSession or publishToolboxes settings.

### Methods inherited from class org.apache.velocity.tools.ToolManager

`configure, createContext, createToolbox, getApplicationToolbox, getLog, getRequestToolbox, getToolboxFactory, getUserCanOverwriteTools, getVelocityEngine, hasApplicationTools, hasRequestTools, hasTools, initLog, prepareContext, setToolboxFactory, setUserCanOverwriteTools, setVelocityEngine`

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

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

### Field Detail

#### CREATE_SESSION_PROPERTY

    public static final String CREATE_SESSION_PROPERTY

See Also:
  Constant Field Values

#### PUBLISH_TOOLBOXES_PROPERTY

    public static final String PUBLISH_TOOLBOXES_PROPERTY

See Also:
  Constant Field Values

#### DEFAULT_TOOLBOX_KEY

    public static final String DEFAULT_TOOLBOX_KEY

#### servletContext

    protected javax.servlet.ServletContext servletContext

### Constructor Detail

#### ViewToolManager

    public ViewToolManager(javax.servlet.ServletContext app)

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

Parameters:
  `app` - servlet context

#### ViewToolManager

    public ViewToolManager(javax.servlet.ServletContext app,
                           boolean includeDefaults)

#### ViewToolManager

    public ViewToolManager(javax.servlet.ServletContext app,
                           boolean autoConfig,
                           boolean includeDefaults)

### Method Detail

#### autoConfigure

    public void autoConfigure(boolean includeDefaults)

Overrides:
  `autoConfigure` in class `ToolManager`

#### setPublishToolboxes

    public void setPublishToolboxes(boolean publish)

Sets whether or not the creation of a new `ViewToolContext` should make the various scoped `Toolbox` instances available publically via the HttpServletRequest/HttpSession/ServletContext attributes or simply add the Toolbox instances directly to the context. It is important to note that if this is set to false, session-scoped tools will NOT be stored in the session, but instead be recreated for each request.

Parameters:
  `publish` - whether to publish the available toolboxes
See Also:
  `publishToolboxes`, `setToolboxKey(java.lang.String)`

#### getPublishToolboxes

    public boolean getPublishToolboxes()

#### setToolboxKey

    public void setToolboxKey(String key)

Sets a new attribute key to be used for publishing each `Toolbox`.

Parameters:
  `key` - toolbox key
See Also:
  `setPublishToolboxes(boolean)`, `publishToolboxes`

#### getToolboxKey

    public String getToolboxKey()

#### setCreateSession

    public void setCreateSession(boolean create)

Sets whether or not a new HttpSession should be created when there are session scoped tools to be stored in the session, but no session has been created yet.

Parameters:
  `create` - whether to create a new session if needed
See Also:
  `publishToolboxes`

#### getCreateSession

    public boolean getCreateSession()

#### updateGlobalProperties

    protected void updateGlobalProperties()

Checks the internal `ToolboxFactory` for any changes to the createSession or publishToolboxes settings.

#### publishApplicationTools

    public void publishApplicationTools()

Publish `Scope.APPLICATION` Toolbox.

#### unpublishApplicationTools

    protected void unpublishApplicationTools()

Removes any published `Scope.APPLICATION` Toolbox.

#### configure

    public void configure(FactoryConfiguration config)

Overrides:
  `configure` in class `ToolManager`

#### findConfig

    protected FactoryConfiguration findConfig(String path)

Overrides:
  `findConfig` in class `ToolManager`

#### addToolboxes

    protected void addToolboxes(ToolContext context)

Overrides:
  `addToolboxes` in class `ToolManager`

#### createContext

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

Overrides:
  `createContext` in class `ToolManager`

#### createContext

    public ViewToolContext createContext(javax.servlet.http.HttpServletRequest request,
                                         javax.servlet.http.HttpServletResponse response)

#### prepareContext

    public void prepareContext(ViewToolContext context,
                               javax.servlet.http.HttpServletRequest request)

#### hasSessionTools

    public boolean hasSessionTools()

#### getSessionToolbox

    protected Toolbox getSessionToolbox()

#### getSessionToolbox

    public Toolbox getSessionToolbox(javax.servlet.http.HttpSession session)

#### publishToolboxes

    public void publishToolboxes(javax.servlet.ServletRequest request)

Places the `Scope.REQUEST` `Toolbox` (if any) into the `ServletRequest` attributes using `Toolbox.KEY` as the key.

Parameters:
  `request` - servlet request

#### publishToolboxes

    public void publishToolboxes(javax.servlet.http.HttpServletRequest request)

Places the `Scope.REQUEST` `Toolbox` (if any) into the `HttpServletRequest` attributes using `Toolbox.KEY` as the key, places the `Scope.SESSION` Toolbox (if any) into the attributes of the `HttpSession` (if any) then ensures that the `Scope.APPLICATION` Toolbox (if any) has been placed in the `ServletContext` attributes.

Parameters:
  `request` - servlet request