Class EvaluationContextImpl
- java.lang.Object
-
- io.pebbletemplates.pebble.template.EvaluationContextImpl
-
- All Implemented Interfaces:
EvaluationContext
,RenderedSizeContext
public class EvaluationContextImpl extends java.lang.Object implements EvaluationContext, RenderedSizeContext
An evaluation context will store all stateful data that is necessary for the evaluation of a template. Passing the entire state around will assist with thread safety.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicInteger
charsRendered
Total number of chars written by all writers sharing this context.private EvaluationOptions
evaluationOptions
evaluation optionsprivate java.util.concurrent.ExecutorService
executorService
The user-provided ExecutorService (can be null).private ExtensionRegistry
extensionRegistry
All the available filters/tests/functions for this template.private Hierarchy
hierarchy
A template will look to it's parent and children for overridden macros and other features; this inheritance chain will help the template keep track of where in the inheritance chain it currently is.private java.util.List<PebbleTemplateImpl>
importedTemplates
The imported templates are used to look up macros.private java.util.Locale
locale
The locale of this template.private int
maxRenderedSize
The maximum size of the rendered template, in chars.private java.util.Map<java.lang.String,PebbleTemplateImpl>
namedImportedTemplates
The named imported templates are used to look up macros.private ScopeChain
scopeChain
A scope is a set of visible variables.private boolean
strictVariables
private PebbleCache<CacheKey,java.lang.Object>
tagCache
The tag cache
-
Constructor Summary
Constructors Constructor Description EvaluationContextImpl(PebbleTemplateImpl self, boolean strictVariables, java.util.Locale locale, int maxRenderedSize, ExtensionRegistry extensionRegistry, PebbleCache<CacheKey,java.lang.Object> tagCache, java.util.concurrent.ExecutorService executorService, java.util.List<PebbleTemplateImpl> importedTemplates, java.util.Map<java.lang.String,PebbleTemplateImpl> namedImportedTemplates, ScopeChain scopeChain, Hierarchy hierarchy, EvaluationOptions evaluationOptions)
Constructor used to provide all final variables.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addAndGet(int delta)
void
addNamedImportedTemplates(java.lang.String alias, PebbleTemplateImpl template)
EvaluationOptions
getEvaluationOptions()
Returns the evaluation options.java.util.concurrent.ExecutorService
getExecutorService()
Returns the executor service if exists or nullExtensionRegistry
getExtensionRegistry()
Returns the extension registry used to access all of the tests/filters/functionsHierarchy
getHierarchy()
Returns the data structure representing the entire hierarchy of the template currently being evaluated.java.util.List<PebbleTemplateImpl>
getImportedTemplates()
Returns a list of imported templates.java.util.Locale
getLocale()
Returns the localeint
getMaxRenderedSize()
Returns the max rendered size.PebbleTemplateImpl
getNamedImportedTemplate(java.lang.String alias)
Returns the named imported template.ScopeChain
getScopeChain()
Returns the scope chain data structure that allows variables to be added/removed from the current scope and retrieved from the nearest visible scopes.PebbleCache<CacheKey,java.lang.Object>
getTagCache()
Returns the cache used for the "cache" tagjava.lang.Object
getVariable(java.lang.String key)
boolean
isStrictVariables()
Returns whether or not this template is being evaluated in "strict templates" modeprivate void
pushScope(EvaluationContextImpl newContext, java.util.Map<?,?> additionalVariables, Callbacks.PebbleConsumer<EvaluationContextImpl> scopedFunction)
void
scopedShallowWithoutInheritanceChain(PebbleTemplateImpl template, java.util.Map<?,?> additionalVariables, Callbacks.PebbleConsumer<EvaluationContextImpl> scopedFunction)
EvaluationContextImpl
shallowCopyWithoutInheritanceChain(PebbleTemplateImpl self)
Makes an exact copy of the evaluation context EXCEPT for the inheritance chain.EvaluationContextImpl
threadSafeCopy(PebbleTemplateImpl self)
Makes a "snapshot" of the evaluation context.
-
-
-
Field Detail
-
strictVariables
private final boolean strictVariables
-
hierarchy
private final Hierarchy hierarchy
A template will look to it's parent and children for overridden macros and other features; this inheritance chain will help the template keep track of where in the inheritance chain it currently is.
-
scopeChain
private final ScopeChain scopeChain
A scope is a set of visible variables. A trivial template will only have one scope. New scopes are added with for loops and macros for example.Most scopes will have a link to their parent scope which allow an evaluation to look up the scope chain for variables. A macro is an exception to this as it only has access to it's local variables.
-
locale
private final java.util.Locale locale
The locale of this template.
-
maxRenderedSize
private final int maxRenderedSize
The maximum size of the rendered template, in chars.
-
extensionRegistry
private final ExtensionRegistry extensionRegistry
All the available filters/tests/functions for this template.
-
tagCache
private final PebbleCache<CacheKey,java.lang.Object> tagCache
The tag cache
-
executorService
private final java.util.concurrent.ExecutorService executorService
The user-provided ExecutorService (can be null).
-
importedTemplates
private final java.util.List<PebbleTemplateImpl> importedTemplates
The imported templates are used to look up macros.
-
namedImportedTemplates
private final java.util.Map<java.lang.String,PebbleTemplateImpl> namedImportedTemplates
The named imported templates are used to look up macros.
-
evaluationOptions
private final EvaluationOptions evaluationOptions
evaluation options
-
charsRendered
private final java.util.concurrent.atomic.AtomicInteger charsRendered
Total number of chars written by all writers sharing this context.
-
-
Constructor Detail
-
EvaluationContextImpl
public EvaluationContextImpl(PebbleTemplateImpl self, boolean strictVariables, java.util.Locale locale, int maxRenderedSize, ExtensionRegistry extensionRegistry, PebbleCache<CacheKey,java.lang.Object> tagCache, java.util.concurrent.ExecutorService executorService, java.util.List<PebbleTemplateImpl> importedTemplates, java.util.Map<java.lang.String,PebbleTemplateImpl> namedImportedTemplates, ScopeChain scopeChain, Hierarchy hierarchy, EvaluationOptions evaluationOptions)
Constructor used to provide all final variables.- Parameters:
self
- The template implementationstrictVariables
- Whether strict variables is to be usedlocale
- The locale of the templateextensionRegistry
- The extension registryexecutorService
- The optional executor servicescopeChain
- The scope chainhierarchy
- The inheritance chaintagCache
- The cache used by the "cache" tag
-
-
Method Detail
-
shallowCopyWithoutInheritanceChain
public EvaluationContextImpl shallowCopyWithoutInheritanceChain(PebbleTemplateImpl self)
Makes an exact copy of the evaluation context EXCEPT for the inheritance chain. This is necessary for the "include" tag.- Parameters:
self
- The template implementation- Returns:
- A copy of the evaluation context
-
threadSafeCopy
public EvaluationContextImpl threadSafeCopy(PebbleTemplateImpl self)
Makes a "snapshot" of the evaluation context. The scopeChain object will be a deep copy and the imported templates will be a new list. This is used for the "parallel" tag.- Parameters:
self
- The template implementation- Returns:
- A copy of the evaluation context
-
getNamedImportedTemplate
public PebbleTemplateImpl getNamedImportedTemplate(java.lang.String alias)
Returns the named imported template.- Returns:
- the named imported template.
-
addNamedImportedTemplates
public void addNamedImportedTemplates(java.lang.String alias, PebbleTemplateImpl template)
-
isStrictVariables
public boolean isStrictVariables()
Returns whether or not this template is being evaluated in "strict templates" mode- Specified by:
isStrictVariables
in interfaceEvaluationContext
- Returns:
- Whether or not this template is being evaluated in "strict templates" mode.
-
getLocale
public java.util.Locale getLocale()
Returns the locale- Specified by:
getLocale
in interfaceEvaluationContext
- Returns:
- The current locale
-
getMaxRenderedSize
public int getMaxRenderedSize()
Returns the max rendered size.- Specified by:
getMaxRenderedSize
in interfaceRenderedSizeContext
- Returns:
- The max rendered size.
-
getExtensionRegistry
public ExtensionRegistry getExtensionRegistry()
Returns the extension registry used to access all of the tests/filters/functions- Returns:
- The extension registry
-
getExecutorService
public java.util.concurrent.ExecutorService getExecutorService()
Returns the executor service if exists or null- Returns:
- The executor service if exists, or null
-
getImportedTemplates
public java.util.List<PebbleTemplateImpl> getImportedTemplates()
Returns a list of imported templates.- Returns:
- A list of imported templates.
-
getTagCache
public PebbleCache<CacheKey,java.lang.Object> getTagCache()
Returns the cache used for the "cache" tag- Returns:
- The cache used for the "cache" tag
-
getScopeChain
public ScopeChain getScopeChain()
Returns the scope chain data structure that allows variables to be added/removed from the current scope and retrieved from the nearest visible scopes.- Returns:
- The scope chain.
-
getHierarchy
public Hierarchy getHierarchy()
Returns the data structure representing the entire hierarchy of the template currently being evaluated.- Returns:
- The inheritance chain
-
getEvaluationOptions
public EvaluationOptions getEvaluationOptions()
Returns the evaluation options.- Returns:
- the evaluation options
-
getVariable
public java.lang.Object getVariable(java.lang.String key)
- Specified by:
getVariable
in interfaceEvaluationContext
-
pushScope
private void pushScope(EvaluationContextImpl newContext, java.util.Map<?,?> additionalVariables, Callbacks.PebbleConsumer<EvaluationContextImpl> scopedFunction) throws java.io.IOException
- Throws:
java.io.IOException
-
scopedShallowWithoutInheritanceChain
public void scopedShallowWithoutInheritanceChain(PebbleTemplateImpl template, java.util.Map<?,?> additionalVariables, Callbacks.PebbleConsumer<EvaluationContextImpl> scopedFunction) throws java.io.IOException
- Throws:
java.io.IOException
-
addAndGet
public int addAndGet(int delta)
- Specified by:
addAndGet
in interfaceRenderedSizeContext
-
-