类 ToolManager

java.lang.Object
org.apache.velocity.tools.ToolManager

public class ToolManager extends 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.
版本:
$Id: ToolManager.java 511959 2007-02-26 19:24:39Z nbubna $
作者:
Nathan Bubna
  • 字段详细资料

    • velocity

      protected org.apache.velocity.app.VelocityEngine velocity
    • factory

      protected ToolboxFactory factory
    • log

      protected org.slf4j.Logger log
  • 构造器详细资料

    • 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.
      参数:
      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.
      参数:
      autoConfig - whether to use configuration file specified in the org.apache.velocity.tools system property
      includeDefaults - whether to include default tools
  • 方法详细资料

    • autoConfigure

      public void autoConfigure(boolean includeDefaults)
      Autoconfiguration using the configuration file potentially found in the org.apache.velocity.tools system property.
      参数:
      includeDefaults - whether to include default tools
    • configure

      public void configure(FactoryConfiguration config)
      Configure the tool manager with this toolbox factory config
      参数:
      config - toolbox factory config
    • configure

      public void configure(String path)
      Configure the tool manager with the provided configuration file
      参数:
      path - path to configuration file
    • findConfig

      protected FactoryConfiguration findConfig(String path)
      Find a configuration file
      参数:
      path - path to a configuration file
      返回:
      toolbox factory configuration
    • getToolboxFactory

      public ToolboxFactory getToolboxFactory()
      Returns the underlying ToolboxFactory being used.
      返回:
      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.
      参数:
      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.
      参数:
      engine - VelocityEngine instance
    • getVelocityEngine

      public org.apache.velocity.app.VelocityEngine getVelocityEngine()
      Get the underlying VelocityEngine being used.
      返回:
      VelocityEngine instance
    • setUserCanOverwriteTools

      public void setUserCanOverwriteTools(boolean overwrite)
      Set whether template user can overwrite tools keys
      参数:
      overwrite - flag value
    • getUserCanOverwriteTools

      public boolean getUserCanOverwriteTools()
      Get whether template user can overwrite tools keys
      返回:
      flag value
    • getLog

      public org.slf4j.Logger getLog()
      Get logger
      返回:
      logger
    • initLog

      protected void initLog()
      init logger
    • createContext

      public ToolContext createContext()
      create new context with configured toolboxes tools
      返回:
      newly created context
    • createContext

      public ToolContext createContext(Map<String,Object> toolProps)
      create new context with configured toolboxes tools, using the provided tools properties
      参数:
      toolProps - tools properties
      返回:
      newly created context
    • prepareContext

      protected void prepareContext(ToolContext context)
      Prepare context
      参数:
      context - tool context
    • addToolboxes

      protected void addToolboxes(ToolContext context)
      Add toolboxes to contex
      参数:
      context - context
    • hasTools

      protected boolean hasTools(String scope)
      Check for the presence of tools in a given scope
      参数:
      scope - scope to check
      返回:
      whether this scope contains tools
    • createToolbox

      protected Toolbox createToolbox(String scope)
      Create a toolbox for the given scope
      参数:
      scope - scope
      返回:
      newly created toolbox
    • hasRequestTools

      public boolean hasRequestTools()
      Check whether this tool manager has request scoped tools
      返回:
      true if this tool manager has request scoped tools, false otherwise
    • getRequestToolbox

      public Toolbox getRequestToolbox()
      Get the toolbox for request scoped tools
      返回:
      toolbox of request scoped tools
    • hasApplicationTools

      public boolean hasApplicationTools()
      Check whether this tool manager has application scoped tools
      返回:
      true if this tool manager has application scoped tools, false otherwise
    • getApplicationToolbox

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