org.apache.velocity.tools.view.context
Class ChainedContext

java.lang.Object
  extended byorg.apache.velocity.context.InternalContextBase
      extended byorg.apache.velocity.context.AbstractContext
          extended byorg.apache.velocity.VelocityContext
              extended byorg.apache.velocity.tools.view.context.ChainedContext
All Implemented Interfaces:
java.lang.Cloneable, org.apache.velocity.context.Context, org.apache.velocity.context.InternalEventContext, org.apache.velocity.context.InternalHousekeepingContext, java.io.Serializable, ViewContext

public class ChainedContext
extends org.apache.velocity.VelocityContext
implements ViewContext

Velocity context implementation specific to the Servlet environment.

It provides the following special features:

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

  1. toolbox
  2. servlet request, servlet response, servlet session, servlet context
  3. local hashtable of objects (traditional use)
  4. servlet request attribues, servlet session attribute, 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 hashtable.

Version:
$Id: ChainedContext.java 154102 2005-02-17 00:40:31Z nbubna $
Author:
Geir Magnusson Jr., Gabe Sidler
See Also:
Serialized Form

Field Summary
private  javax.servlet.ServletContext application
           
private  javax.servlet.http.HttpServletRequest request
           
private  javax.servlet.http.HttpServletResponse response
           
private  javax.servlet.http.HttpSession session
           
private  java.util.Map toolbox
           
private  org.apache.velocity.app.VelocityEngine velocity
           
 
Fields inherited from class org.apache.velocity.VelocityContext
 
Fields inherited from class org.apache.velocity.context.AbstractContext
 
Fields inherited from interface org.apache.velocity.tools.view.context.ViewContext
APPLICATION, REQUEST, RESPONSE, SESSION, XHTML
 
Constructor Summary
ChainedContext(org.apache.velocity.context.Context ctx, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application)
          Deprecated.  
ChainedContext(org.apache.velocity.context.Context ctx, org.apache.velocity.app.VelocityEngine velocity, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application)
           
ChainedContext(org.apache.velocity.app.VelocityEngine velocity, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application)
           
 
Method Summary
 java.lang.Object getAttribute(java.lang.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.
 javax.servlet.http.HttpServletRequest getRequest()
          Returns the current servlet request.
 javax.servlet.http.HttpServletResponse getResponse()
          Returns the current servlet response.
 javax.servlet.ServletContext getServletContext()
          Returns the servlet context.
 org.apache.velocity.context.Context getVelocityContext()
          Returns a reference to the Velocity context (this object).
 org.apache.velocity.app.VelocityEngine getVelocityEngine()
          Returns a reference to the VelocityEngine.
 java.lang.Object internalGet(java.lang.String key)
          Looks up and returns the object with the specified key.
 void setToolbox(java.util.Map box)
          Sets the toolbox of view tools.
 void setToolbox(ToolboxContext box)
          Deprecated. Use setToolbox(Map) instead.
 
Methods inherited from class org.apache.velocity.VelocityContext
clone, internalContainsKey, internalGetKeys, internalPut, internalRemove
 
Methods inherited from class org.apache.velocity.context.AbstractContext
attachEventCartridge, containsKey, get, getChainedContext, getCurrentResource, getCurrentTemplateName, getEventCartridge, getKeys, getTemplateNameStack, icacheGet, icachePut, popCurrentTemplateName, pushCurrentTemplateName, put, remove, setCurrentResource
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toolbox

private java.util.Map toolbox

request

private javax.servlet.http.HttpServletRequest request

response

private javax.servlet.http.HttpServletResponse response

session

private javax.servlet.http.HttpSession session

application

private javax.servlet.ServletContext application

velocity

private org.apache.velocity.app.VelocityEngine velocity
Constructor Detail

ChainedContext

public ChainedContext(org.apache.velocity.context.Context ctx,
                      javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response,
                      javax.servlet.ServletContext application)
Deprecated.  


ChainedContext

public ChainedContext(org.apache.velocity.app.VelocityEngine velocity,
                      javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response,
                      javax.servlet.ServletContext application)

ChainedContext

public ChainedContext(org.apache.velocity.context.Context ctx,
                      org.apache.velocity.app.VelocityEngine velocity,
                      javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response,
                      javax.servlet.ServletContext application)
Method Detail

setToolbox

public void setToolbox(ToolboxContext box)
Deprecated. Use setToolbox(Map) instead.


setToolbox

public void setToolbox(java.util.Map box)

Sets the toolbox of view tools.

Parameters:
box - toolbox of view tools

internalGet

public java.lang.Object internalGet(java.lang.String key)

Looks up and returns the object with the specified key.

See the class documentation for more details.

Parameters:
key - the key of the object requested
Returns:
the requested object or null if not found

getAttribute

public java.lang.Object getAttribute(java.lang.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.

Specified by:
getAttribute in interface ViewContext
Since:
VelocityTools 1.1

getRequest

public javax.servlet.http.HttpServletRequest getRequest()

Returns the current servlet request.

Specified by:
getRequest in interface ViewContext

getResponse

public javax.servlet.http.HttpServletResponse getResponse()

Returns the current servlet response.

Specified by:
getResponse in interface ViewContext

getServletContext

public javax.servlet.ServletContext getServletContext()

Returns the servlet context.

Specified by:
getServletContext in interface ViewContext

getVelocityContext

public org.apache.velocity.context.Context getVelocityContext()

Returns a reference to the Velocity context (this object).

Specified by:
getVelocityContext in interface ViewContext

getVelocityEngine

public org.apache.velocity.app.VelocityEngine getVelocityEngine()

Returns a reference to the VelocityEngine.

Specified by:
getVelocityEngine in interface ViewContext


Copyright (c) 2003 Apache Software Foundation