Package org.apache.velocity.tools
Class ToolboxFactory
- java.lang.Object
-
- org.apache.velocity.tools.ToolboxFactory
-
public class ToolboxFactory extends java.lang.Object
This class is the central point of action for VelocityTools. It manages the configured and scoped
ToolInfo
andData
and is meant to stick around for the life of the application.It works like this:
- Build up your
FactoryConfiguration
(s) - Create a
ToolboxFactory
instance - Pass the configuration to
configure(org.apache.velocity.tools.config.FactoryConfiguration)
- When appropriate for each scope, use
createToolbox(java.lang.String)
to create theToolbox
for that scope and put that toolbox somewhere appropriate to that scope. - When you want a tool, get that
Toolbox
and ask it for the tool you want (e.g.toolbox.get("math")
).
Of course, most users will not have to do any of this as much of it is handled for them by some combination of
ToolManager
orVelocityView
and aToolContext
orViewToolContext
.NOTE: While you are free to pass in new configuration info at any time, that data will only affect
Toolbox
es created subsequently. Any previously created toolboxes will have to be re-created and replaced to reflect the changes to the configuration.- Version:
- $Id: ToolboxFactory.java 511959 2007-02-26 19:24:39Z nbubna $
- Author:
- Nathan Bubna
- Build up your
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.Object>
data
static java.lang.String
DEFAULT_SCOPE
private java.util.Map<java.lang.String,java.lang.Object>
globalProperties
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>
scopedProperties
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,ToolInfo>>
scopedToolInfo
-
Constructor Summary
Constructors Constructor Description ToolboxFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addToolInfo(java.lang.String scope, ToolInfo tool)
void
configure(FactoryConfiguration config)
Toolbox
createToolbox(java.lang.String scope)
java.util.Map<java.lang.String,java.lang.Object>
getData()
java.lang.Object
getGlobalProperty(java.lang.String name)
protected java.util.Map<java.lang.String,ToolInfo>
getToolInfo(java.lang.String scope)
boolean
hasTools(java.lang.String scope)
protected java.lang.Object
putData(java.lang.String key, java.lang.Object value)
protected void
putGlobalProperties(java.util.Map<java.lang.String,java.lang.Object> props)
protected void
putProperties(java.lang.String scope, java.util.Map<java.lang.String,java.lang.Object> props)
-
-
-
Field Detail
-
DEFAULT_SCOPE
public static final java.lang.String DEFAULT_SCOPE
- See Also:
- Constant Field Values
-
scopedToolInfo
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,ToolInfo>> scopedToolInfo
-
scopedProperties
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>> scopedProperties
-
data
private java.util.Map<java.lang.String,java.lang.Object> data
-
globalProperties
private java.util.Map<java.lang.String,java.lang.Object> globalProperties
-
-
Method Detail
-
configure
public void configure(FactoryConfiguration config)
-
putData
protected java.lang.Object putData(java.lang.String key, java.lang.Object value)
-
addToolInfo
protected void addToolInfo(java.lang.String scope, ToolInfo tool)
-
getToolInfo
protected java.util.Map<java.lang.String,ToolInfo> getToolInfo(java.lang.String scope)
-
putGlobalProperties
protected void putGlobalProperties(java.util.Map<java.lang.String,java.lang.Object> props)
-
putProperties
protected void putProperties(java.lang.String scope, java.util.Map<java.lang.String,java.lang.Object> props)
-
getGlobalProperty
public java.lang.Object getGlobalProperty(java.lang.String name)
-
getData
public java.util.Map<java.lang.String,java.lang.Object> getData()
-
hasTools
public boolean hasTools(java.lang.String scope)
-
createToolbox
public Toolbox createToolbox(java.lang.String scope)
-
-