Class ToolManager


  • public class ToolManager
    extends java.lang.Object
    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

      Fields 
      Modifier and Type Field Description
      protected ToolboxFactory factory  
      protected org.slf4j.Logger log  
      protected org.apache.velocity.app.VelocityEngine velocity  
    • 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.
    • Field Detail

      • velocity

        protected org.apache.velocity.app.VelocityEngine velocity
      • 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 the org.apache.velocity.tools system property
        includeDefaults - whether to include default tools
    • Method Detail

      • autoConfigure

        public void autoConfigure​(boolean includeDefaults)
        Autoconfiguration using the configuration file potentially found in the org.apache.velocity.tools system 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 underlying ToolboxFactory being 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:
        true if this tool manager has request scoped tools, false otherwise
      • 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:
        true if this tool manager has application scoped tools, false otherwise
      • getApplicationToolbox

        public Toolbox getApplicationToolbox()
        Get the toolbox for application scoped tools
        Returns:
        toolbox of application scoped tools