Package io.pebbletemplates.pebble
Class PebbleEngine.Builder
java.lang.Object
io.pebbletemplates.pebble.PebbleEngine.Builder
- Enclosing class:
PebbleEngine
A builder to configure and construct an instance of a PebbleEngine.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private Locale
private boolean
private ExecutorService
private final ExtensionRegistryFactory
private boolean
private boolean
private boolean
private Loader
<?> private int
private MethodAccessValidator
private boolean
private Syntax
private PebbleCache
<CacheKey, Object> private PebbleCache
<Object, PebbleTemplate> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddEscapingStrategy
(String name, EscapingStrategy strategy) Adds an escaping strategy to the built-in escaper extension.allowOverrideCoreOperators
(boolean allowOverrideCoreOperators) Sets whether or not core operators overrides should be allowed.autoEscaping
(boolean autoEscaping) Sets whether or not escaping should be performed automatically.build()
Creates the PebbleEngine instance.cacheActive
(boolean cacheActive) Enable/disable all caches, i.e.defaultEscapingStrategy
(String strategy) Sets the default escaping strategy of the built-in escaper extension.defaultLocale
(Locale defaultLocale) Sets the Locale passed to all templates constructed by this PebbleEngine.executorService
(ExecutorService executorService) Sets the executor service which is required if using one of Pebble's multithreading features such as the "parallel" tag.Adds an extension, can be safely invoked several times to add different extensions.greedyMatchMethod
(boolean greedyMatchMethod) Enable/disable greedy matching mode for finding java method.literalDecimalTreatedAsInteger
(boolean literalDecimalTreatedAsInteger) Enable/disable treat literal decimal as Integer.literalNumbersAsBigDecimals
(boolean literalNumbersAsBigDecimals) Enable/disable treat literal numbers as BigDecimals.Sets the loader used to find templates.maxRenderedSize
(int maxRenderedSize) Sets the maximum size of the rendered template to protect against macro bombs.methodAccessValidator
(MethodAccessValidator methodAccessValidator) Validator that can be used to validate object/method accessnewLineTrimming
(boolean enableNewLineTrimming) Changes thenewLineTrimming
setting of the PebbleEngine.registerExtensionCustomizer
(Function<Extension, ExtensionCustomizer> customizer) Registers an implementation ofExtensionCustomizer
to change runtime-behaviour of standard functionality.strictVariables
(boolean strictVariables) Changes thestrictVariables
setting of the PebbleEngine.Sets the syntax to be used.tagCache
(PebbleCache<CacheKey, Object> tagCache) Sets the cache used by the "cache" tag.templateCache
(PebbleCache<Object, PebbleTemplate> templateCache) Sets the cache used by the engine to store compiled PebbleTemplate instances.
-
Field Details
-
loader
-
syntax
-
strictVariables
private boolean strictVariables -
enableNewLineTrimming
private boolean enableNewLineTrimming -
defaultLocale
-
maxRenderedSize
private int maxRenderedSize -
executorService
-
templateCache
-
cacheActive
private boolean cacheActive -
tagCache
-
literalDecimalTreatedAsInteger
private boolean literalDecimalTreatedAsInteger -
greedyMatchMethod
private boolean greedyMatchMethod -
literalNumbersAsBigDecimals
private boolean literalNumbersAsBigDecimals -
methodAccessValidator
-
factory
-
-
Constructor Details
-
Builder
public Builder()Creates the builder.
-
-
Method Details
-
loader
Sets the loader used to find templates.- Parameters:
loader
- A template loader- Returns:
- This builder object
-
extension
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
Sets the syntax to be used.- Parameters:
syntax
- The syntax to be used- Returns:
- This builder object
-
strictVariables
Changes thestrictVariables
setting 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
Changes thenewLineTrimming
setting 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
newLineTrimming
is 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
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
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
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
Sets the cache used by the engine to store compiled PebbleTemplate instances.- Parameters:
templateCache
- The template cache- Returns:
- This builder object
-
tagCache
Sets the cache used by the "cache" tag.- Parameters:
tagCache
- The tag cache- Returns:
- This builder object
-
autoEscaping
Sets whether or not escaping should be performed automatically.- Parameters:
autoEscaping
- The auto escaping setting- Returns:
- This builder object
-
allowOverrideCoreOperators
Sets whether or not core operators overrides should be allowed.- Parameters:
allowOverrideCoreOperators
- Whether or not core operators overrides should be allowed.- Returns:
- This builder object
-
defaultEscapingStrategy
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
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
Enable/disable all caches, i.e. cache used by the engine to store compiled PebbleTemplate instances and tags cache- Parameters:
cacheActive
- toggle to enable/disable all caches- Returns:
- This builder object
-
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
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
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
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:
-
registerExtensionCustomizer
public PebbleEngine.Builder registerExtensionCustomizer(Function<Extension, ExtensionCustomizer> customizer) Registers an implementation ofExtensionCustomizer
to change runtime-behaviour of standard functionality.- Parameters:
customizer
- The customizer which wraps any non-user-provided extension- Returns:
- This build object
-
build
Creates the PebbleEngine instance.- Returns:
- A PebbleEngine object that can be used to create PebbleTemplate objects.
-