Class ToolManager
java.lang.Object
org.apache.velocity.tools.ToolManager
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
FieldsModifier and TypeFieldDescriptionprotected ToolboxFactoryprotected org.slf4j.Loggerprotected org.apache.velocity.app.VelocityEngine -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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
Modifier and TypeMethodDescriptionprotected voidaddToolboxes(ToolContext context) Add toolboxes to contexvoidautoConfigure(boolean includeDefaults) Autoconfiguration using the configuration file potentially found in theorg.apache.velocity.toolssystem property.voidConfigure the tool manager with the provided configuration filevoidconfigure(FactoryConfiguration config) Configure the tool manager with this toolbox factory configcreate new context with configured toolboxes toolscreateContext(Map<String, Object> toolProps) create new context with configured toolboxes tools, using the provided tools propertiesprotected ToolboxcreateToolbox(String scope) Create a toolbox for the given scopeprotected FactoryConfigurationfindConfig(String path) Find a configuration fileGet the toolbox for application scoped toolsorg.slf4j.LoggergetLog()Get loggerGet the toolbox for request scoped toolsReturns the underlyingToolboxFactorybeing used.booleanGet whether template user can overwrite tools keysorg.apache.velocity.app.VelocityEngineGet the underlying VelocityEngine being used.booleanCheck whether this tool manager has application scoped toolsbooleanCheck whether this tool manager has request scoped toolsprotected booleanCheck for the presence of tools in a given scopeprotected voidinitLog()init loggerprotected voidprepareContext(ToolContext context) Prepare contextvoidsetToolboxFactory(ToolboxFactory factory) Sets the underlying ToolboxFactory being used.voidsetUserCanOverwriteTools(boolean overwrite) Set whether template user can overwrite tools keysvoidsetVelocityEngine(org.apache.velocity.app.VelocityEngine engine) Sets the underlying VelocityEngine being used.
-
Field Details
-
velocity
protected org.apache.velocity.app.VelocityEngine velocity -
factory
-
log
protected org.slf4j.Logger log
-
-
Constructor Details
-
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 theorg.apache.velocity.toolssystem propertyincludeDefaults- whether to include default tools
-
-
Method Details
-
autoConfigure
public void autoConfigure(boolean includeDefaults) Autoconfiguration using the configuration file potentially found in theorg.apache.velocity.toolssystem property.- Parameters:
includeDefaults- whether to include default tools
-
configure
Configure the tool manager with this toolbox factory config- Parameters:
config- toolbox factory config
-
configure
Configure the tool manager with the provided configuration file- Parameters:
path- path to configuration file
-
findConfig
Find a configuration file- Parameters:
path- path to a configuration file- Returns:
- toolbox factory configuration
-
getToolboxFactory
Returns the underlyingToolboxFactorybeing used.- Returns:
- underlying toolbox factory
-
setToolboxFactory
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
create new context with configured toolboxes tools- Returns:
- newly created context
-
createContext
create new context with configured toolboxes tools, using the provided tools properties- Parameters:
toolProps- tools properties- Returns:
- newly created context
-
prepareContext
Prepare context- Parameters:
context- tool context
-
addToolboxes
Add toolboxes to contex- Parameters:
context- context
-
hasTools
Check for the presence of tools in a given scope- Parameters:
scope- scope to check- Returns:
- whether this scope contains tools
-
createToolbox
-
hasRequestTools
public boolean hasRequestTools()Check whether this tool manager has request scoped tools- Returns:
trueif this tool manager has request scoped tools,falseotherwise
-
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:
trueif this tool manager has application scoped tools,falseotherwise
-
getApplicationToolbox
Get the toolbox for application scoped tools- Returns:
- toolbox of application scoped tools
-