org.thymeleaf.context
Class AbstractContext

Object
  extended by org.thymeleaf.context.AbstractContext
All Implemented Interfaces:
IContext
Direct Known Subclasses:
Context, WebContext

public abstract class AbstractContext
extends Object
implements IContext

Abstract class for IContext implementations, providing some of the features required to implement this interface.

Since:
1.0
Author:
Daniel Fernández

Field Summary
static String EXEC_INFO_VARIABLE_NAME
           Name of the variable containing the "execution info" object.
 
Constructor Summary
protected AbstractContext()
           Create an instance without specifying a locale.
protected AbstractContext(Locale locale)
           Create an instance specifying a locale.
protected AbstractContext(Locale locale, Map<String,?> variables)
           Create an instance specifying a locale and an initial set of context variables.
 
Method Summary
 void addContextExecutionInfo(String templateName)
           Adds the context execution info to the variables map.
protected abstract  IContextExecutionInfo buildContextExecutionInfo(String templateName)
           Creates the specific instance of IContextExecutionInfo to be added to the context as the execInfo variable.
 void clearVariables()
           Removes from the map all the context variables currently set.
 Locale getLocale()
           Returns the locale that will be used for template execution.
 VariablesMap<String,Object> getVariables()
           Returns the VariablesMap object containing the variables that will be available for the execution of expressions inside templates.
 void setLocale(Locale locale)
           Set the locale to be used for template execution.
 void setVariable(String name, Object value)
           Adds a variable to the current set of context variables.
 void setVariables(Map<String,?> additionalVariables)
           Adds a set of variables to the current set of context variables.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXEC_INFO_VARIABLE_NAME

public static final String EXEC_INFO_VARIABLE_NAME

Name of the variable containing the "execution info" object.

See Also:
Constant Field Values
Constructor Detail

AbstractContext

protected AbstractContext()

Create an instance without specifying a locale. Using this constructor, the default locale (Locale.getDefault()) will be used.


AbstractContext

protected AbstractContext(Locale locale)

Create an instance specifying a locale.

Parameters:
locale - the locale to be used.

AbstractContext

protected AbstractContext(Locale locale,
                          Map<String,?> variables)

Create an instance specifying a locale and an initial set of context variables.

Parameters:
locale - the locale to be used.
variables - the initial set of context variables.
Method Detail

getLocale

public Locale getLocale()
Description copied from interface: IContext

Returns the locale that will be used for template execution. This locale will determine the language of the externalized messages resolved by the message resolvers.

Specified by:
getLocale in interface IContext
Returns:
the locale to be used for template execution.

setLocale

public void setLocale(Locale locale)

Set the locale to be used for template execution.

The locale specified using this method overrides the one that might have been set using a constructor.

Parameters:
locale - the locale to be set.

getVariables

public final VariablesMap<String,Object> getVariables()
Description copied from interface: IContext

Returns the VariablesMap object containing the variables that will be available for the execution of expressions inside templates.

Specified by:
getVariables in interface IContext
Returns:
the variables map.

setVariable

public final void setVariable(String name,
                              Object value)

Adds a variable to the current set of context variables.

Parameters:
name - the name of the variable.
value - the value of the variable.

setVariables

public final void setVariables(Map<String,?> additionalVariables)

Adds a set of variables to the current set of context variables.

Parameters:
additionalVariables - the new variables to be added.

clearVariables

public final void clearVariables()

Removes from the map all the context variables currently set.


addContextExecutionInfo

public final void addContextExecutionInfo(String templateName)

Adds the context execution info to the variables map.

This IContext implementation adds an object of the ContextExecutionInfo class with variable name execInfo.

Specified by:
addContextExecutionInfo in interface IContext
Parameters:
templateName - the name of the template being executed

buildContextExecutionInfo

protected abstract IContextExecutionInfo buildContextExecutionInfo(String templateName)

Creates the specific instance of IContextExecutionInfo to be added to the context as the execInfo variable.

Parameters:
templateName - the name of the template being executed
Returns:
the execution info object


Copyright © 2012 The THYMELEAF team. All Rights Reserved.