类 ViewToolContext

java.lang.Object
org.apache.velocity.tools.ToolContext
org.apache.velocity.tools.view.ViewToolContext
所有已实现的接口:
org.apache.velocity.context.Context, ViewContext

public class ViewToolContext extends ToolContext implements ViewContext

ToolContext implementation specific to the servlet environment.

It provides the following special features:

  • puts the request, response, session, and servlet context objects into the Velocity context for direct access, and keeps them read-only
  • supports a read-only toolbox of view tools
  • auto-searches servlet request attributes, session attributes and servlet context attribues for objects

The get(String key) method implements the following search order for objects:

  1. tool in a request scoped toolbox
  2. tool in a session scoped toolbox
  3. tool in a application scoped toolbox
  4. request, response, session, or servlet context
  5. object in the local map of objects (traditional use)
  6. request attributes, session attributes, servlet context attributes

The purpose of this class is to make it easy for web designer to work with Java servlet based web applications. They do not need to be concerned with the concepts of request, session or application attributes and the lifetime of objects in these scopes.

Note that the put() method always puts objects into the local map and does not allow tools or servlet classes to be overridden.

版本:
$Id: ViewContext.java 514727 2007-03-05 16:49:03Z nbubna $
作者:
Geir Magnusson Jr., Gabe Sidler, Nathan Bubna
  • 构造器详细资料

    • ViewToolContext

      public ViewToolContext(org.apache.velocity.app.VelocityEngine velocity, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.ServletContext application)
  • 方法详细资料

    • setToolboxKey

      protected void setToolboxKey(String key)
    • putToolProperties

      protected void putToolProperties()
    • getToolboxes

      protected List<Toolbox> getToolboxes()
      覆盖:
      getToolboxes 在类中 ToolContext
    • addToolboxesUnderKey

      protected void addToolboxesUnderKey(String toolboxKey)
    • get

      public Object get(String key)

      Looks up and returns the object with the specified key.

      See the class documentation for more details.

      指定者:
      get 在接口中 org.apache.velocity.context.Context
      覆盖:
      get 在类中 ToolContext
      参数:
      key - the key of the object requested
      返回:
      the requested object or null if not found
      另请参阅:
    • getUserVar

      protected Object getUserVar(String key)
      Finds "user" set values, either in the local context or in the scoped attributes if none is in the local context.
      参数:
      key - attribute name
      返回:
      found value or null
      另请参阅:
    • getToolVar

      protected Object getToolVar(String key)
      Finds the automatically provided values, either configured tools or servlet API objects (request, response, etc).
      参数:
      key - attribute key
      返回:
      found configured value or null
      另请参阅:
    • getServletApi

      protected Object getServletApi(String key)
      Returns the current matching servlet request, response, session, or servlet context instance, or null if the key matches none of those keys.
      参数:
      key - attribute key
      返回:
      found value or null
    • getAttribute

      public Object getAttribute(String key)

      Searches for the named attribute in request, session (if valid), and application scope(s) in order and returns the value associated or null.

      指定者:
      getAttribute 在接口中 ViewContext
      参数:
      key - attribute key
      返回:
      found value or null
      从以下版本开始:
      VelocityTools 1.1
    • getRequest

      public jakarta.servlet.http.HttpServletRequest getRequest()
      指定者:
      getRequest 在接口中 ViewContext
      返回:
      the current servlet request.
    • getResponse

      public jakarta.servlet.http.HttpServletResponse getResponse()
      指定者:
      getResponse 在接口中 ViewContext
      返回:
      the current servlet response.
    • getSession

      public jakarta.servlet.http.HttpSession getSession()
      返回:
      the current session, if any.
    • getServletContext

      public jakarta.servlet.ServletContext getServletContext()
      指定者:
      getServletContext 在接口中 ViewContext
      返回:
      the servlet context.
    • getVelocityContext

      public org.apache.velocity.context.Context getVelocityContext()
      指定者:
      getVelocityContext 在接口中 ViewContext
      返回:
      a reference to the Velocity context (this object).
    • getVelocityEngine

      public org.apache.velocity.app.VelocityEngine getVelocityEngine()
      指定者:
      getVelocityEngine 在接口中 ViewContext
      返回:
      a reference to the VelocityEngine.
    • containsKey

      public boolean containsKey(String key)
      Indicates whether the specified key is in the context.
      指定者:
      containsKey 在接口中 org.apache.velocity.context.Context
      覆盖:
      containsKey 在类中 ToolContext
      参数:
      key - The key to look for.
      返回:
      Whether the key is in the context.