Class VarResolver.Builder
- Enclosing class:
- VarResolver
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder()Constructor.protectedBuilder(VarResolver copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionallowFunctions(String... patterns) Restricts which functions (including the reserved$op Adds a bean to the resolvedVarResolver's local bean store.Returns the bean store used by this builder.build()Builds the var resolver.Registers the built-inVarFunctioncatalog.Adds the default variables to this builder.final VarResolver.Builderfunctions(Class<? extends VarFunction>... values) Register one or moreVarFunctionclasses on this builder.functions(VarFunction... values) Register one or moreVarFunctioninstances on this builder.Registers third-partyVarFunctionimplementations discovered throughServiceLoader(META-INF/services/org.apache.juneau.commons.svl.VarFunction).maxCollectionSize(int value) Sets the maximum number of elements allowed in a collection built by an expression.maxExprDepth(int value) Sets the maximum expression nesting depth accepted by the parser.maxRecursionDepth(int value) Sets the maximum depth for re-resolving a var's output.strict(boolean value) Enables or disables strict expression evaluation.valueFormatter(Function<Object, String> value) Sets the formatter that converts the typed result of a#{...}expression to text.final VarResolver.BuilderRegister new variables with this resolver.Register new variables with this resolver.Register new variables with this resolver.
-
Constructor Details
-
Builder
protected Builder()Constructor. -
Builder
Copy constructor.- Parameters:
copyFrom- The bean to copy from. Must not benull.
-
-
Method Details
-
maxRecursionDepth
Sets the maximum depth for re-resolving a var's output.Default is
VarResolver.DEFAULT_MAX_RECURSION_DEPTH(32). Must be positive.- Parameters:
value- The maximum recursion depth. Must be at least 1.- Returns:
- This object.
-
strict
Enables or disables strict expression evaluation.Default is
false (lenient).- Parameters:
value-true to enable strict mode.- Returns:
- This object.
-
maxCollectionSize
Sets the maximum number of elements allowed in a collection built by an expression.Default is
VarResolver.DEFAULT_MAX_COLLECTION_SIZE(1000). Must be positive.- Parameters:
value- The maximum collection size. Must be at least 1.- Returns:
- This object.
-
valueFormatter
Sets the formatter that converts the typed result of a#{...}expression to text.Default is a
JsonValueFormatterhonouringmaxCollectionSize(int)and strict mode. A session can replace it per render withVarResolverSession.valueFormatter(Function). Anull result from the formatter is treated as the empty string.A custom formatter replaces the default, so it does not get the default's depth, size, node and cycle limits (it must guard itself). It is also bypassed for
Structurevalues, which useStructure.toString()unless a session formatter is set.- Parameters:
value- The formatter.null restores the default.- Returns:
- This object.
-
maxExprDepth
Sets the maximum expression nesting depth accepted by the parser.Default is
VarResolver.DEFAULT_MAX_EXPR_DEPTH(32). Must be positive.- Parameters:
value- The maximum expression depth. Must be at least 1.- Returns:
- This object.
-
beanStore
Returns the bean store used by this builder.- Returns:
- The bean store used by this builder.
-
bean
Adds a bean to the resolvedVarResolver's local bean store.The bean is stored on this builder and merged into the resolver's local bean store at
build()time. The parent bean store passed at construction is not mutated, so beans added here are isolated toVarResolvers built from this builder.- Type Parameters:
T- The bean type.- Parameters:
c- The bean type.value- The bean.- Returns:
- This object .
-
defaultVars
Adds the default variables to this builder.The default variables are:
The 11 transformation
Vars previously listed here (SwitchVar,IfVar,CoalesceVar,PatternMatchVar,PatternReplaceVar,PatternExtractVar,UpperCaseVar,LowerCaseVar,NotEmptyVar,LenVar,SubstringVar) were deleted in 10.0.0 and replaced by the#{...}script syntax. UsedefaultFunctions()to register the built-in catalog.- Returns:
- This object .
-
vars
Register new variables with this resolver.- Parameters:
values- The variable resolver classes. These classes must subclass fromVarand have no-arg constructors.- Returns:
- This object .
-
vars
Register new variables with this resolver.- Parameters:
values- The variable resolver classes. These classes must subclass fromVarand have no-arg constructors.- Returns:
- This object .
-
vars
Register new variables with this resolver.- Parameters:
values- The variable resolver classes. These classes must subclass fromVarand have no-arg constructors.- Returns:
- This object .
-
allowFunctions
Restricts which functions (including the reserved$op.* operator functions) the resolver exposes.Each pattern is a glob over function names:
* matches any run of characters, anything else matches exactly. A function is permitted if its name matches at least one pattern. Operators dispatch to$op.* functions ($op.add ,$op.ternary ,$op.select , ...), so they are denied by the allowlist too; useallowFunctions("$op.*", ...) to keep them.If this method is never called, every function is permitted. Calling it with no patterns denies everything, operators included. Repeated calls are additive, including after
VarResolver.copy(): a copy can widen the allowlist but cannot narrow it. The filter is applied to the final function set atbuild()time, and is preserved byVarResolver.copy().A denied function or operator is treated like an unknown one (strict mode:
ExprExceptionsaying it is "not permitted"; lenient mode: the expression is emitted verbatim).- Parameters:
patterns- The glob patterns. Must not benull or containnull .- Returns:
- This builder.
-
functions
Register one or moreVarFunctioninstances on this builder.Functions registered here win over
BeanStore/ServiceLoader/ built-in catalog entries with the samename(later-wins-on-collision). Discovery channels merge these registrations with the auto-discovered set atbuild()time.- Parameters:
values- The functions to register.- Returns:
- This builder.
-
functions
Register one or moreVarFunctionclasses on this builder. Each class must have a public no-arg constructor; instances are created via the bean store atbuild()time so dependency injection works the same way it does forVars.- Parameters:
values- The function classes to register.- Returns:
- This builder.
-
defaultFunctions
Registers the built-inVarFunctioncatalog.Functions on the classpath that are advertised through
ServiceLoaderare not registered by this method; callloadServices()to opt in. Explicitfunctions(VarFunction...)/functions(Class...)calls made after this one override built-ins on name collision.- Returns:
- This builder.
-
loadServices
Registers third-partyVarFunctionimplementations discovered throughServiceLoader(META-INF/services/org.apache.juneau.commons.svl.VarFunction).This is opt-in. A discovered function never replaces a function that is already registered under the same name (including the built-ins registered by
defaultFunctions()), so call this method afterdefaultFunctions().- Returns:
- This builder.
-
build
Builds the var resolver.- Returns:
- A new
VarResolver.
-