Package org.apache.velocity.tools
Class ToolManager
- java.lang.Object
-
- org.apache.velocity.tools.ToolManager
-
public class ToolManager extends java.lang.ObjectManages 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 aFactoryConfigurationas 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 Modifier and Type Field Description protected ToolboxFactoryfactoryprotected org.slf4j.Loggerlogprotected org.apache.velocity.app.VelocityEnginevelocity
-
Constructor Summary
Constructors Constructor 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 Modifier and Type Method Description protected voidaddToolboxes(ToolContext context)Add toolboxes to contexvoidautoConfigure(boolean includeDefaults)Autoconfiguration using the configuration file potentially found in theorg.apache.velocity.toolssystem property.voidconfigure(java.lang.String path)Configure the tool manager with the provided configuration filevoidconfigure(FactoryConfiguration config)Configure the tool manager with this toolbox factory configToolContextcreateContext()create new context with configured toolboxes toolsToolContextcreateContext(java.util.Map<java.lang.String,java.lang.Object> toolProps)create new context with configured toolboxes tools, using the provided tools propertiesprotected ToolboxcreateToolbox(java.lang.String scope)Create a toolbox for the given scopeprotected FactoryConfigurationfindConfig(java.lang.String path)Find a configuration fileToolboxgetApplicationToolbox()Get the toolbox for application scoped toolsorg.slf4j.LoggergetLog()Get loggerToolboxgetRequestToolbox()Get the toolbox for request scoped toolsToolboxFactorygetToolboxFactory()Returns the underlyingToolboxFactorybeing used.booleangetUserCanOverwriteTools()Get whether template user can overwrite tools keysorg.apache.velocity.app.VelocityEnginegetVelocityEngine()Get the underlying VelocityEngine being used.booleanhasApplicationTools()Check whether this tool manager has application scoped toolsbooleanhasRequestTools()Check whether this tool manager has request scoped toolsprotected booleanhasTools(java.lang.String scope)Check 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 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 theorg.apache.velocity.toolssystem propertyincludeDefaults- whether to include default tools
-
-
Method Detail
-
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
public void configure(FactoryConfiguration config)
Configure the tool manager with this toolbox factory config- Parameters:
config- toolbox factory config
-
configure
public void configure(java.lang.String path)
Configure the tool manager with the provided configuration file- Parameters:
path- path to configuration file
-
findConfig
protected FactoryConfiguration findConfig(java.lang.String path)
Find a configuration file- Parameters:
path- path to a configuration file- Returns:
- toolbox factory configuration
-
getToolboxFactory
public ToolboxFactory getToolboxFactory()
Returns the underlyingToolboxFactorybeing 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(java.util.Map<java.lang.String,java.lang.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(java.lang.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(java.lang.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:
trueif this tool manager has request scoped tools,falseotherwise
-
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:
trueif this tool manager has application scoped tools,falseotherwise
-
getApplicationToolbox
public Toolbox getApplicationToolbox()
Get the toolbox for application scoped tools- Returns:
- toolbox of application scoped tools
-
-