org.apache.velocity.tools.view
Class ContextTool

java.lang.Object
  extended by org.apache.velocity.tools.view.ContextTool
Direct Known Subclasses:
ContextTool

@DefaultKey(value="context")
@InvalidScope(value={"application","session"})
public class ContextTool
extends java.lang.Object

View tool for convenient access to ViewContext data and meta-data.

 Template example(s):
  #foreach( $key in $context.keys )
    $key = $context.get($key)
  #end

 Toolbox configuration:
 <tools>
   <toolbox scope="request">
     <tool class="org.apache.velocity.tools.view.ContextTool"/>
   </toolbox>
 </tools>
 

This class is only designed for use as a request-scope VelocityView tool.

Since:
VelocityTools 2.0
Version:
$Id: ContextTool.java 385122 2006-03-11 18:37:42Z nbubna $
Author:
Nathan Bubna

Field Summary
protected  javax.servlet.ServletContext application
           
protected  ViewContext context
           
protected  javax.servlet.http.HttpServletRequest request
           
static java.lang.String SAFE_MODE_KEY
          The key used for specifying whether to hide keys with '.' in them.
private  boolean safeMode
           
protected  javax.servlet.http.HttpSession session
           
protected  java.util.Map<java.lang.String,java.lang.Object> toolbox
           
 
Constructor Summary
ContextTool()
           
 
Method Summary
 void configure(java.util.Map params)
          Initializes this instance for the current request.
 boolean contains(java.lang.Object refName)
          Returns true if the context contains a value for the specified reference name (aka context key).
 java.lang.Object get(java.lang.Object refName)
          Retrieves the value for the specified reference name (aka context key).
 java.util.Set getKeys()
          Return a Set of the available reference keys in the current context.
 ViewContext getThis()
          Returns the context being analyzed by this tool.
 java.util.Map<java.lang.String,java.lang.Object> getToolbox()
          Returns a read-only view of the toolbox Map for this context.
 java.util.Set getValues()
          Return a Set of the available values in the current context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SAFE_MODE_KEY

public static final java.lang.String SAFE_MODE_KEY
The key used for specifying whether to hide keys with '.' in them.

See Also:
Constant Field Values

context

protected ViewContext context

toolbox

protected java.util.Map<java.lang.String,java.lang.Object> toolbox

request

protected javax.servlet.http.HttpServletRequest request

session

protected javax.servlet.http.HttpSession session

application

protected javax.servlet.ServletContext application

safeMode

private boolean safeMode
Constructor Detail

ContextTool

public ContextTool()
Method Detail

configure

public void configure(java.util.Map params)
Initializes this instance for the current request. Also looks for a safe-mode configuration setting. By default, safe-mode is true and thus keys with '.' in them are hidden.


getThis

public ViewContext getThis()
Returns the context being analyzed by this tool.


getToolbox

public java.util.Map<java.lang.String,java.lang.Object> getToolbox()

Returns a read-only view of the toolbox Map for this context.

Returns:
a map of all available tools for this request or null if such a map is not available

getKeys

public java.util.Set getKeys()

Return a Set of the available reference keys in the current context.


getValues

public java.util.Set getValues()

Return a Set of the available values in the current context.


contains

public boolean contains(java.lang.Object refName)

Returns true if the context contains a value for the specified reference name (aka context key).


get

public java.lang.Object get(java.lang.Object refName)
Retrieves the value for the specified reference name (aka context key).



Copyright (c) 2003-2007 Apache Software Foundation