Class VarResolver.Builder

java.lang.Object
org.apache.juneau.commons.svl.VarResolver.Builder
Enclosing class:
VarResolver

public static class VarResolver.Builder extends Object
Builder class.
  • Constructor Details

    • Builder

      protected Builder()
      Constructor.
    • Builder

      protected Builder(VarResolver copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The bean to copy from. Must not be null.
  • 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

      public VarResolver.Builder strict(boolean value)
      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 JsonValueFormatter honouring maxCollectionSize(int) and strict mode. A session can replace it per render with VarResolverSession.valueFormatter(Function). A null 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 Structure values, which use Structure.toString() unless a session formatter is set.

      Parameters:
      value - The formatter. null restores the default.
      Returns:
      This object.
    • maxExprDepth

      public VarResolver.Builder maxExprDepth(int value)
      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

      public <T> VarResolver.Builder bean(Class<T> c, T value)
      Adds a bean to the resolved VarResolver'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 to VarResolvers 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. Use defaultFunctions() to register the built-in catalog.

      Returns:
      This object .
    • vars

      @SafeVarargs public final VarResolver.Builder vars(Class<? extends Var>... values)
      Register new variables with this resolver.
      Parameters:
      values - The variable resolver classes. These classes must subclass from Var and have no-arg constructors.
      Returns:
      This object .
    • vars

      public VarResolver.Builder vars(Var... values)
      Register new variables with this resolver.
      Parameters:
      values - The variable resolver classes. These classes must subclass from Var and have no-arg constructors.
      Returns:
      This object .
    • vars

      public VarResolver.Builder vars(VarList values)
      Register new variables with this resolver.
      Parameters:
      values - The variable resolver classes. These classes must subclass from Var and 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; use allowFunctions("$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 at build() time, and is preserved by VarResolver.copy().

      A denied function or operator is treated like an unknown one (strict mode: ExprException saying it is "not permitted"; lenient mode: the expression is emitted verbatim).

      Parameters:
      patterns - The glob patterns. Must not be null or contain null.
      Returns:
      This builder.
    • functions

      Register one or more VarFunction instances on this builder.

      Functions registered here win over BeanStore / ServiceLoader / built-in catalog entries with the same name (later-wins-on-collision). Discovery channels merge these registrations with the auto-discovered set at build() time.

      Parameters:
      values - The functions to register.
      Returns:
      This builder.
    • functions

      @SafeVarargs public final VarResolver.Builder functions(Class<? extends VarFunction>... values)
      Register one or more VarFunction classes on this builder. Each class must have a public no-arg constructor; instances are created via the bean store at build() time so dependency injection works the same way it does for Vars.
      Parameters:
      values - The function classes to register.
      Returns:
      This builder.
    • defaultFunctions

      Registers the built-in VarFunction catalog.

      Functions on the classpath that are advertised through ServiceLoader are not registered by this method; call loadServices() to opt in. Explicit functions(VarFunction...) / functions(Class...) calls made after this one override built-ins on name collision.

      Returns:
      This builder.
    • loadServices

      Registers third-party VarFunction implementations discovered through ServiceLoader (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 after defaultFunctions().

      Returns:
      This builder.
    • build

      public VarResolver build()
      Builds the var resolver.
      Returns:
      A new VarResolver.