com.google.clearsilver.jsilver.data
Interface DataContext

All Known Implementing Classes:
DefaultDataContext

public interface DataContext

Manages the global Data object and local variable mappings during rendering.


Method Summary
 void createLocalVariableByPath(String name, String path)
          Creates a local variable that references a (possibly non-existent) Data node.
 void createLocalVariableByValue(String name, String value)
          Creates and sets a local variable in the current scope equal to the given value.
 void createLocalVariableByValue(String name, String value, boolean isFirst, boolean isLast)
          Creates and sets a local variable in the current scope equal to the given value.
 void createLocalVariableByValue(String name, String value, EscapeMode mode)
          Creates and sets a local variable in the current scope equal to the given value.
 Data findVariable(String name, boolean create)
          Searches the variable map stack for the specified variable name.
 EscapeMode findVariableEscapeMode(String name)
          Searches the variable map stack for the specified variable name, and returns its EscapeMode.
 Data getRootData()
          Returns the main Data object this RenderingContext was defined with.
 void popVariableScope()
          Removes the most recent Data object added to the local variable map stack.
 void pushVariableScope()
          Creates a new Data object to hold local references, pushes it onto the variable map stack.
 

Method Detail

getRootData

Data getRootData()
Returns the main Data object this RenderingContext was defined with.


pushVariableScope

void pushVariableScope()
Creates a new Data object to hold local references, pushes it onto the variable map stack. This is used to hold macro parameters after a call command, and local variables defined for 'each' and 'with'.


popVariableScope

void popVariableScope()
Removes the most recent Data object added to the local variable map stack.


createLocalVariableByValue

void createLocalVariableByValue(String name,
                                String value)
Creates and sets a local variable in the current scope equal to the given value.

Parameters:
name - the name of the local variable to fetch or create.
value - The String value to store at the local variable.

createLocalVariableByValue

void createLocalVariableByValue(String name,
                                String value,
                                EscapeMode mode)
Creates and sets a local variable in the current scope equal to the given value. Also set the EscapeMode that was applied to its value. This may be used by the template renderer to decide whether to autoescape the variable.

Parameters:
name - the name of the local variable to fetch or create.
value - The String value to store at the local variable.
mode - EscapeMode that describes the escaping this variable has. EscapeMode.ESCAPE_NONE if the variable was not escaped. EscapeMode.ESCAPE_IS_CONSTANT if the variable was populated with a string or numeric literal.

createLocalVariableByValue

void createLocalVariableByValue(String name,
                                String value,
                                boolean isFirst,
                                boolean isLast)
Creates and sets a local variable in the current scope equal to the given value.

This method is a helper method for supporting the first() and last() functions on loops without requiring loops create a full Data tree.

Parameters:
name - the name of the local variable to fetch or create.
value - The String value to store at the local variable.
isFirst - What the local variable should return for Data.isFirstSibling()
isLast - What the local variable should return for Data.isLastSibling()

createLocalVariableByPath

void createLocalVariableByPath(String name,
                               String path)
Creates a local variable that references a (possibly non-existent) Data node. When the Data object for this variable is requested, it will return the Data object at the path location or null, if it does not exist. If findVariable(java.lang.String, boolean) is called with create == true, then if no Data object exists at the path location, it will be created.

Parameters:
name - the name of the local variable to fetch or create.
path - The path to the Data object

findVariable

Data findVariable(String name,
                  boolean create)
Searches the variable map stack for the specified variable name. If not found, it then searches the root Data object. If not found then and create is true, then a new node is created with the given name in the root Data object and that node is returned.

Note: This only creates nodes in the root Data object, not in any local variable map. To do that, use the Data node returned by pushVariableScope().

Parameters:
name - the name of the variable to find and/or create.
create - if true then a new node will be created if an existing Data node with the given name does not exist.
Returns:
The first Data node in the variable map stack that matches the given name, or a Data node in the root Data object matching the given name, or null if no such node exists and create is false.

findVariableEscapeMode

EscapeMode findVariableEscapeMode(String name)
Searches the variable map stack for the specified variable name, and returns its EscapeMode.

Returns:
If the variable is found, returns its EscapeMode, otherwise returns EscapeMode.ESCAPE_NONE.


Copyright © 2010-2012 Google. All Rights Reserved.