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.html,v 1.8.2.1 2004/05/17 17:09:45 nbubna Exp $
Author:
Geir Magnusson Jr., Gabe Sidler
See Also:
Serialized Form

Field Summary
private  javax.servlet.ServletContext application
          A local reference to the servlet context.
private  javax.servlet.http.HttpServletRequest request
          A local reference to the current servlet request.
private  javax.servlet.http.HttpServletResponse response
          A local reference to the current servlet response.
private  javax.servlet.http.HttpSession session
          A local reference to the servlet session.
private  ToolboxContext toolboxContext
          The toolbox.
 
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)
          Default constructor.
 
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).
 java.lang.Object internalGet(java.lang.String key)
          Looks up and returns the object with the specified key.
 void setToolbox(ToolboxContext box)
          Sets the toolbox of view tools.
 
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

request

private javax.servlet.http.HttpServletRequest request
A local reference to the current servlet request.


response

private javax.servlet.http.HttpServletResponse response
A local reference to the current servlet response.


session

private javax.servlet.http.HttpSession session
A local reference to the servlet session.


application

private javax.servlet.ServletContext application
A local reference to the servlet context.


toolboxContext

private ToolboxContext toolboxContext
The toolbox.

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)
Default constructor.

Method Detail

setToolbox

public void setToolbox(ToolboxContext 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


Copyright (c) 2003 Apache Software Foundation