Package 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 org.apache.velocity.tools.ToolManagerManages 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 aFactoryConfigurationor having one in the ServletContext attributes underServletUtils.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 Modifier and Type Field Description static java.lang.StringCREATE_SESSION_PROPERTYstatic java.lang.StringDEFAULT_TOOLBOX_KEYstatic java.lang.StringPUBLISH_TOOLBOXES_PROPERTYprotected javax.servlet.ServletContextservletContext
-
Constructor Summary
Constructors Constructor 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 Modifier and Type Method Description protected voidaddToolboxes(org.apache.velocity.tools.ToolContext context)voidautoConfigure(boolean includeDefaults)voidconfigure(org.apache.velocity.tools.config.FactoryConfiguration config)org.apache.velocity.tools.ToolContextcreateContext(java.util.Map<java.lang.String,java.lang.Object> toolProps)ViewToolContextcreateContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected org.apache.velocity.tools.config.FactoryConfigurationfindConfig(java.lang.String path)booleangetCreateSession()booleangetPublishToolboxes()protected org.apache.velocity.tools.ToolboxgetSessionToolbox()org.apache.velocity.tools.ToolboxgetSessionToolbox(javax.servlet.http.HttpSession session)java.lang.StringgetToolboxKey()booleanhasSessionTools()voidprepareContext(ViewToolContext context, javax.servlet.http.HttpServletRequest request)voidpublishApplicationTools()PublishScope.APPLICATIONToolbox.voidpublishToolboxes(javax.servlet.http.HttpServletRequest request)Places theScope.REQUESTToolbox(if any) into theHttpServletRequestattributes usingToolbox.KEYas the key, places theScope.SESSIONToolbox (if any) into the attributes of theHttpSession(if any) then ensures that theScope.APPLICATIONToolbox (if any) has been placed in theServletContextattributes.voidpublishToolboxes(javax.servlet.ServletRequest request)Places theScope.REQUESTToolbox(if any) into theServletRequestattributes usingToolbox.KEYas the key.voidsetCreateSession(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.voidsetPublishToolboxes(boolean publish)Sets whether or not the creation of a newViewToolContextshould make the various scopedToolboxinstances available publically via the HttpServletRequest/HttpSession/ServletContext attributes or simply add the Toolbox instances directly to the context.voidsetToolboxKey(java.lang.String key)Sets a new attribute key to be used for publishing eachToolbox.protected voidunpublishApplicationTools()Removes any publishedScope.APPLICATIONToolbox.protected voidupdateGlobalProperties()Checks the internalToolboxFactoryfor 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
-
-
-
-
Field Detail
-
CREATE_SESSION_PROPERTY
public static final java.lang.String CREATE_SESSION_PROPERTY
- See Also:
- Constant Field Values
-
PUBLISH_TOOLBOXES_PROPERTY
public static final java.lang.String PUBLISH_TOOLBOXES_PROPERTY
- See Also:
- Constant Field Values
-
DEFAULT_TOOLBOX_KEY
public static final java.lang.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:
autoConfigurein classorg.apache.velocity.tools.ToolManager
-
setPublishToolboxes
public void setPublishToolboxes(boolean publish)
Sets whether or not the creation of a newViewToolContextshould make the various scopedToolboxinstances 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(java.lang.String key)
Sets a new attribute key to be used for publishing eachToolbox.- Parameters:
key- toolbox key- See Also:
setPublishToolboxes(boolean),publishToolboxes
-
getToolboxKey
public java.lang.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 internalToolboxFactoryfor any changes to the createSession or publishToolboxes settings.
-
publishApplicationTools
public void publishApplicationTools()
PublishScope.APPLICATIONToolbox.
-
unpublishApplicationTools
protected void unpublishApplicationTools()
Removes any publishedScope.APPLICATIONToolbox.
-
configure
public void configure(org.apache.velocity.tools.config.FactoryConfiguration config)
- Overrides:
configurein classorg.apache.velocity.tools.ToolManager
-
findConfig
protected org.apache.velocity.tools.config.FactoryConfiguration findConfig(java.lang.String path)
- Overrides:
findConfigin classorg.apache.velocity.tools.ToolManager
-
addToolboxes
protected void addToolboxes(org.apache.velocity.tools.ToolContext context)
- Overrides:
addToolboxesin classorg.apache.velocity.tools.ToolManager
-
createContext
public org.apache.velocity.tools.ToolContext createContext(java.util.Map<java.lang.String,java.lang.Object> toolProps)
- Overrides:
createContextin classorg.apache.velocity.tools.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 org.apache.velocity.tools.Toolbox getSessionToolbox()
-
getSessionToolbox
public org.apache.velocity.tools.Toolbox getSessionToolbox(javax.servlet.http.HttpSession session)
-
publishToolboxes
public void publishToolboxes(javax.servlet.ServletRequest request)
Places theScope.REQUESTToolbox(if any) into theServletRequestattributes usingToolbox.KEYas the key.- Parameters:
request- servlet request
-
publishToolboxes
public void publishToolboxes(javax.servlet.http.HttpServletRequest request)
Places theScope.REQUESTToolbox(if any) into theHttpServletRequestattributes usingToolbox.KEYas the key, places theScope.SESSIONToolbox (if any) into the attributes of theHttpSession(if any) then ensures that theScope.APPLICATIONToolbox (if any) has been placed in theServletContextattributes.- Parameters:
request- servlet request
-
-