Package io.pebbletemplates.pebble
Class PebbleEngine.Builder
- java.lang.Object
-
- io.pebbletemplates.pebble.PebbleEngine.Builder
-
- Enclosing class:
- PebbleEngine
public static class PebbleEngine.Builder extends java.lang.ObjectA builder to configure and construct an instance of a PebbleEngine.
-
-
Field Summary
Fields Modifier and Type Field Description private booleancacheActiveprivate java.util.LocaledefaultLocaleprivate booleanenableNewLineTrimmingprivate java.util.concurrent.ExecutorServiceexecutorServiceprivate ExtensionRegistryFactoryfactoryprivate booleangreedyMatchMethodprivate booleanliteralDecimalTreatedAsIntegerprivate booleanliteralNumbersAsBigDecimalsprivate Loader<?>loaderprivate intmaxRenderedSizeprivate MethodAccessValidatormethodAccessValidatorprivate booleanstrictVariablesprivate Syntaxsyntaxprivate PebbleCache<CacheKey,java.lang.Object>tagCacheprivate PebbleCache<java.lang.Object,PebbleTemplate>templateCache
-
Constructor Summary
Constructors Constructor Description Builder()Creates the builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PebbleEngine.BuilderaddEscapingStrategy(java.lang.String name, EscapingStrategy strategy)Adds an escaping strategy to the built-in escaper extension.PebbleEngine.BuilderallowOverrideCoreOperators(boolean allowOverrideCoreOperators)Sets whether or not core operators overrides should be allowed.PebbleEngine.BuilderautoEscaping(boolean autoEscaping)Sets whether or not escaping should be performed automatically.PebbleEnginebuild()Creates the PebbleEngine instance.PebbleEngine.BuildercacheActive(boolean cacheActive)Enable/disable all caches, i.e.PebbleEngine.BuilderdefaultEscapingStrategy(java.lang.String strategy)Sets the default escaping strategy of the built-in escaper extension.PebbleEngine.BuilderdefaultLocale(java.util.Locale defaultLocale)Sets the Locale passed to all templates constructed by this PebbleEngine.PebbleEngine.BuilderexecutorService(java.util.concurrent.ExecutorService executorService)Sets the executor service which is required if using one of Pebble's multithreading features such as the "parallel" tag.PebbleEngine.Builderextension(Extension... extensions)Adds an extension, can be safely invoked several times to add different extensions.PebbleEngine.BuildergreedyMatchMethod(boolean greedyMatchMethod)Enable/disable greedy matching mode for finding java method.PebbleEngine.BuilderliteralDecimalTreatedAsInteger(boolean literalDecimalTreatedAsInteger)Enable/disable treat literal decimal as Integer.PebbleEngine.BuilderliteralNumbersAsBigDecimals(boolean literalNumbersAsBigDecimals)Enable/disable treat literal numbers as BigDecimals.PebbleEngine.Builderloader(Loader<?> loader)Sets the loader used to find templates.PebbleEngine.BuildermaxRenderedSize(int maxRenderedSize)Sets the maximum size of the rendered template to protect against macro bombs.PebbleEngine.BuildermethodAccessValidator(MethodAccessValidator methodAccessValidator)Validator that can be used to validate object/method accessPebbleEngine.BuildernewLineTrimming(boolean enableNewLineTrimming)Changes thenewLineTrimmingsetting of the PebbleEngine.PebbleEngine.BuilderregisterExtensionCustomizer(java.util.function.Function<Extension,ExtensionCustomizer> customizer)Registers an implementation ofExtensionCustomizerto change runtime-behaviour of standard functionality.PebbleEngine.BuilderstrictVariables(boolean strictVariables)Changes thestrictVariablessetting of the PebbleEngine.PebbleEngine.Buildersyntax(Syntax syntax)Sets the syntax to be used.PebbleEngine.BuildertagCache(PebbleCache<CacheKey,java.lang.Object> tagCache)Sets the cache used by the "cache" tag.PebbleEngine.BuildertemplateCache(PebbleCache<java.lang.Object,PebbleTemplate> templateCache)Sets the cache used by the engine to store compiled PebbleTemplate instances.
-
-
-
Field Detail
-
loader
private Loader<?> loader
-
syntax
private Syntax syntax
-
strictVariables
private boolean strictVariables
-
enableNewLineTrimming
private boolean enableNewLineTrimming
-
defaultLocale
private java.util.Locale defaultLocale
-
maxRenderedSize
private int maxRenderedSize
-
executorService
private java.util.concurrent.ExecutorService executorService
-
templateCache
private PebbleCache<java.lang.Object,PebbleTemplate> templateCache
-
cacheActive
private boolean cacheActive
-
tagCache
private PebbleCache<CacheKey,java.lang.Object> tagCache
-
literalDecimalTreatedAsInteger
private boolean literalDecimalTreatedAsInteger
-
greedyMatchMethod
private boolean greedyMatchMethod
-
literalNumbersAsBigDecimals
private boolean literalNumbersAsBigDecimals
-
methodAccessValidator
private MethodAccessValidator methodAccessValidator
-
factory
private final ExtensionRegistryFactory factory
-
-
Method Detail
-
loader
public PebbleEngine.Builder loader(Loader<?> loader)
Sets the loader used to find templates.- Parameters:
loader- A template loader- Returns:
- This builder object
-
extension
public PebbleEngine.Builder extension(Extension... extensions)
Adds an extension, can be safely invoked several times to add different extensions.- Parameters:
extensions- One or more extensions to add- Returns:
- This builder object
-
syntax
public PebbleEngine.Builder syntax(Syntax syntax)
Sets the syntax to be used.- Parameters:
syntax- The syntax to be used- Returns:
- This builder object
-
strictVariables
public PebbleEngine.Builder strictVariables(boolean strictVariables)
Changes thestrictVariablessetting of the PebbleEngine. The default value of this setting is "false".The following examples will all print empty strings if strictVariables is false but will throw exceptions if it is true:
{{ nonExistingVariable }} {{ nonExistingVariable.attribute }} {{ nullVariable.attribute }} {{ existingVariable.nullAttribute.attribute }} {{ existingVariable.nonExistingAttribute }} {{ array[-1] }}- Parameters:
strictVariables- Whether or not strict variables is used- Returns:
- This builder object
-
newLineTrimming
public PebbleEngine.Builder newLineTrimming(boolean enableNewLineTrimming)
Changes thenewLineTrimmingsetting of the PebbleEngine. The default value of this setting is "true".By default, Pebble will trim a newline that immediately follows a Pebble tag. For example,
{{key1}}\n{{key2}}will have the newline removed.If
newLineTrimmingis set to false, then the first newline following a Pebble tag won't be trimmed. All newlines will be preserved- Parameters:
enableNewLineTrimming- Whether or not the newline should be trimmed.- Returns:
- This builder object
-
defaultLocale
public PebbleEngine.Builder defaultLocale(java.util.Locale defaultLocale)
Sets the Locale passed to all templates constructed by this PebbleEngine.An individual template can always be given a new locale during evaluation.
- Parameters:
defaultLocale- The default locale- Returns:
- This builder object
-
maxRenderedSize
public PebbleEngine.Builder maxRenderedSize(int maxRenderedSize)
Sets the maximum size of the rendered template to protect against macro bombs. See for example https://github.com/PebbleTemplates/pebble/issues/526. If the rendered template exceeds this limit, then a PebbleException is thrown. The default value is -1 and it means unlimited.- Parameters:
maxRenderedSize- The maximum allowed size of the rendered template.- Returns:
- This builder object.
-
executorService
public PebbleEngine.Builder executorService(java.util.concurrent.ExecutorService executorService)
Sets the executor service which is required if using one of Pebble's multithreading features such as the "parallel" tag.- Parameters:
executorService- The executor service- Returns:
- This builder object
-
templateCache
public PebbleEngine.Builder templateCache(PebbleCache<java.lang.Object,PebbleTemplate> templateCache)
Sets the cache used by the engine to store compiled PebbleTemplate instances.- Parameters:
templateCache- The template cache- Returns:
- This builder object
-
tagCache
public PebbleEngine.Builder tagCache(PebbleCache<CacheKey,java.lang.Object> tagCache)
Sets the cache used by the "cache" tag.- Parameters:
tagCache- The tag cache- Returns:
- This builder object
-
autoEscaping
public PebbleEngine.Builder autoEscaping(boolean autoEscaping)
Sets whether or not escaping should be performed automatically. The default value of this setting is "true".- Parameters:
autoEscaping- The auto escaping setting.- Returns:
- This builder object
-
allowOverrideCoreOperators
public PebbleEngine.Builder allowOverrideCoreOperators(boolean allowOverrideCoreOperators)
Sets whether or not core operators overrides should be allowed. The default value of this setting is "false".- Parameters:
allowOverrideCoreOperators- Whether or not core operators overrides should be allowed.- Returns:
- This builder object
-
defaultEscapingStrategy
public PebbleEngine.Builder defaultEscapingStrategy(java.lang.String strategy)
Sets the default escaping strategy of the built-in escaper extension.- Parameters:
strategy- The name of the default escaping strategy- Returns:
- This builder object
-
addEscapingStrategy
public PebbleEngine.Builder addEscapingStrategy(java.lang.String name, EscapingStrategy strategy)
Adds an escaping strategy to the built-in escaper extension.- Parameters:
name- The name of the escaping strategystrategy- The strategy implementation- Returns:
- This builder object
-
cacheActive
public PebbleEngine.Builder cacheActive(boolean cacheActive)
Enable/disable all caches, i.e. cache used by the engine to store compiled PebbleTemplate instances and tags cache. The default value of this setting is "true".- Parameters:
cacheActive- toggle to enable/disable all caches- Returns:
- This builder object
-
methodAccessValidator
public PebbleEngine.Builder methodAccessValidator(MethodAccessValidator methodAccessValidator)
Validator that can be used to validate object/method access- Parameters:
methodAccessValidator- Validator that can be used to validate object/method access- Returns:
- This builder object
-
literalDecimalTreatedAsInteger
public PebbleEngine.Builder literalDecimalTreatedAsInteger(boolean literalDecimalTreatedAsInteger)
Enable/disable treat literal decimal as Integer. Default is disabled, treated as Long.- Parameters:
literalDecimalTreatedAsInteger- toggle to enable/disable literal decimal treated as integer- Returns:
- This builder object
-
literalNumbersAsBigDecimals
public PebbleEngine.Builder literalNumbersAsBigDecimals(boolean literalNumbersAsBigDecimals)
Enable/disable treat literal numbers as BigDecimals. Default is disabled, treated as Long/Double.- Parameters:
literalNumbersAsBigDecimals- toggle to enable/disable literal numbers treated as BigDecimals- Returns:
- This builder object
-
greedyMatchMethod
public PebbleEngine.Builder greedyMatchMethod(boolean greedyMatchMethod)
Enable/disable greedy matching mode for finding java method. Default is disabled. If enabled, when can not find perfect method (method name, parameter length and parameter type are all satisfied), reduce the limit of the parameter type, try to find other method which has compatible parameter types. For example,{{ obj.number(2) }}the expression can match all of below methods.public Long getNumber(Long v) {...} public Integer getNumber(Integer v) {...} public Short getNumber(Short v) {...} public Byte getNumber(Byte v) {...} ...- Parameters:
greedyMatchMethod- toggle to enable/disable greedy match method- Returns:
- This builder object
- See Also:
TypeUtils.compatibleCast(Object, Class)
-
registerExtensionCustomizer
public PebbleEngine.Builder registerExtensionCustomizer(java.util.function.Function<Extension,ExtensionCustomizer> customizer)
Registers an implementation ofExtensionCustomizerto change runtime-behaviour of standard functionality.- Parameters:
customizer- The customizer which wraps any non-user-provided extension- Returns:
- This build object
-
build
public PebbleEngine build()
Creates the PebbleEngine instance.- Returns:
- A PebbleEngine object that can be used to create PebbleTemplate objects.
-
-