Class ServletToolboxManager

java.lang.Object
org.apache.velocity.tools.view.XMLToolboxManager
org.apache.velocity.tools.view.servlet.ServletToolboxManager
All Implemented Interfaces:
ToolboxManager

@Deprecated public class ServletToolboxManager extends XMLToolboxManager
Deprecated.

A toolbox manager for the servlet environment.

A toolbox manager is responsible for automatically filling the Velocity context with a set of view tools. This class provides the following features:

  • configurable through an XML-based configuration file
  • assembles a set of view tools (the toolbox) on request
  • handles different tool scopes (request, session, application)
  • supports any class with a public constructor without parameters to be used as a view tool
  • supports adding primitive data values to the context(String,Number,Boolean)

Configuration

The toolbox manager is configured through an XML-based configuration file. The configuration file is passed to the XMLToolboxManager.load(java.io.InputStream input) method. The format is shown in the following example:

 <?xml version="1.0"?>

 <toolbox>
   <tool>
      <key>link</key>
      <scope>request</scope>
      <class>org.apache.velocity.tools.view.tools.LinkTool</class>
   </tool>
   <tool>
      <key>date</key>
      <scope>application</scope>
      <class>org.apache.velocity.tools.generic.DateTool</class>
   </tool>
   <data type="number">
      <key>luckynumber</key>
      <value>1.37</value>
   </data>
   <data type="string">
      <key>greeting</key>
      <value>Hello World!</value>
   </data>
   <xhtml>true</xhtml>
 </toolbox>
 

The recommended location for the configuration file is the WEB-INF directory of the web application.

Version:
$Id: ServletToolboxManager.java 651470 2008-04-25 00:47:52Z nbubna $
Author:
Gabriel Sidler, Nathan Bubna, Geir Magnusson Jr., Henning P. Schmiedehausen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Map
    Deprecated.
     
    private boolean
    Deprecated.
     
    protected static final Log
    Deprecated.
     
    private static HashMap
    Deprecated.
     
    private ArrayList
    Deprecated.
     
    private ServletContext
    Deprecated.
     
    private static RuleSet
    Deprecated.
     
    static final String
    Deprecated.
     
    private ArrayList
    Deprecated.
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    ServletToolboxManager(ServletContext servletContext)
    Deprecated.
    Use getInstance(ServletContext,String) instead to ensure there is exactly one ServletToolboxManager per xml toolbox configuration file.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deprecated.
    Overrides XMLToolboxManager to put data into appTools map
    void
    Deprecated.
    Overrides XMLToolboxManager to separate tools by scope.
    getInstance(ServletContext servletContext, String toolboxFile)
    Deprecated.
    ServletToolboxManager factory method.
    protected Object
    getMutex(HttpSession session)
    Deprecated.
    Returns a mutex (lock object) unique to the specified session to allow for reliable synchronization on the session.
    protected RuleSet
    Deprecated.
    Retrieves the rule set Digester should use to parse and load the toolbox for this manager.
    getToolbox(Object initData)
    Deprecated.
    Overrides XMLToolboxManager to handle the separate scopes.
    void
    setCreateSession(boolean b)
    Deprecated.
    Sets whether or not to create a new session when none exists for the current request and session-scoped tools have been defined for this toolbox.
    void
    Deprecated.
    Sets an application attribute to tell velocimacros and tools (especially the LinkTool) whether they should output XHTML or HTML.
    protected boolean
    Deprecated.
    Ensures that application-scoped tools do not have request path restrictions set for them, as those will not be enforced.

    Methods inherited from class org.apache.velocity.tools.view.XMLToolboxManager

    load, load

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SESSION_TOOLS_KEY

      public static final String SESSION_TOOLS_KEY
      Deprecated.
    • LOG

      protected static final Log LOG
      Deprecated.
    • servletContext

      private ServletContext servletContext
      Deprecated.
    • appTools

      private Map appTools
      Deprecated.
    • sessionToolInfo

      private ArrayList sessionToolInfo
      Deprecated.
    • requestToolInfo

      private ArrayList requestToolInfo
      Deprecated.
    • createSession

      private boolean createSession
      Deprecated.
    • managersMap

      private static HashMap managersMap
      Deprecated.
    • servletRuleSet

      private static RuleSet servletRuleSet
      Deprecated.
  • Constructor Details

    • ServletToolboxManager

      private ServletToolboxManager(ServletContext servletContext)
      Deprecated.
      Use getInstance(ServletContext,String) instead to ensure there is exactly one ServletToolboxManager per xml toolbox configuration file.
  • Method Details

    • getInstance

      public static ServletToolboxManager getInstance(ServletContext servletContext, String toolboxFile)
      Deprecated.
      ServletToolboxManager factory method. This method will ensure there is exactly one ServletToolboxManager per xml toolbox configuration file.
    • setCreateSession

      public void setCreateSession(boolean b)
      Deprecated.

      Sets whether or not to create a new session when none exists for the current request and session-scoped tools have been defined for this toolbox.

      If true, then a call to getToolbox(Object) will create a new session if none currently exists for this request and the toolbox has one or more session-scoped tools designed.

      If false, then a call to getToolbox(Object) will never create a new session for the current request. This effectively means that no session-scoped tools will be added to the ToolboxContext for a request that does not have a session object.

      The default value is true.
    • setXhtml

      public void setXhtml(Boolean value)
      Deprecated.

      Sets an application attribute to tell velocimacros and tools (especially the LinkTool) whether they should output XHTML or HTML.

      Since:
      VelocityTools 1.1
      See Also:
    • getRuleSet

      protected RuleSet getRuleSet()
      Deprecated.

      Retrieves the rule set Digester should use to parse and load the toolbox for this manager.

      The DTD corresponding to the ServletToolboxRuleSet is:

        <?xml version="1.0"?>
        <!ELEMENT toolbox (create-session?,xhtml?,tool*,data*,#PCDATA)>
        <!ELEMENT create-session (#CDATA)>
        <!ELEMENT xhtml          (#CDATA)>
        <!ELEMENT tool           (key,scope?,class,parameter*,#PCDATA)>
        <!ELEMENT data           (key,value)>
            <!ATTLIST data type (string|number|boolean) "string">
        <!ELEMENT key            (#CDATA)>
        <!ELEMENT scope          (#CDATA)>
        <!ELEMENT class          (#CDATA)>
        <!ELEMENT parameter (EMPTY)>
            <!ATTLIST parameter name CDATA #REQUIRED>
            <!ATTLIST parameter value CDATA #REQUIRED>
        <!ELEMENT value          (#CDATA)>
       

      Overrides:
      getRuleSet in class XMLToolboxManager
      Since:
      VelocityTools 1.1
    • validateToolInfo

      protected boolean validateToolInfo(ToolInfo info)
      Deprecated.
      Ensures that application-scoped tools do not have request path restrictions set for them, as those will not be enforced.
      Overrides:
      validateToolInfo in class XMLToolboxManager
      Parameters:
      info - a ToolInfo object
      Returns:
      true if the ToolInfo is valid
      Since:
      VelocityTools 1.3
    • addTool

      public void addTool(ToolInfo info)
      Deprecated.
      Overrides XMLToolboxManager to separate tools by scope. For this to work, we obviously override getToolbox(Object) as well.
      Specified by:
      addTool in interface ToolboxManager
      Overrides:
      addTool in class XMLToolboxManager
    • addData

      public void addData(ToolInfo info)
      Deprecated.
      Overrides XMLToolboxManager to put data into appTools map
      Specified by:
      addData in interface ToolboxManager
      Overrides:
      addData in class XMLToolboxManager
      Parameters:
      info - An object that implements ToolInfo
    • getToolbox

      public Map getToolbox(Object initData)
      Deprecated.
      Overrides XMLToolboxManager to handle the separate scopes. Application scope tools were initialized when the toolbox was loaded. Session scope tools are initialized once per session and stored in a map in the session attributes. Request scope tools are initialized on every request.
      Specified by:
      getToolbox in interface ToolboxManager
      Overrides:
      getToolbox in class XMLToolboxManager
      Parameters:
      initData - the ViewContext for the current servlet request
      Returns:
      the created ToolboxContext
    • getMutex

      protected Object getMutex(HttpSession session)
      Deprecated.
      Returns a mutex (lock object) unique to the specified session to allow for reliable synchronization on the session.