Class JsonValuePropertyEvaluator

java.lang.Object
org.forgerock.config.util.JsonValuePropertyEvaluator

public final class JsonValuePropertyEvaluator extends Object
A utility that traverses a JsonValue and does property substitution as well as type coercion.
  • Constructor Details

    • JsonValuePropertyEvaluator

      public JsonValuePropertyEvaluator(SubstitutionService substitutionService, List<JsonValuePropertyEvaluator.CoercionFunctionSpec> coercionFunctions)
      Constructs a JsonValuePropertyEvaluator which traverses a JsonValue and does property substitution as well as type coercion. Custom coercion functions can be added to the additionalCoercionFunctions map. Custom functions should Be a function that takes a value like
           {
               "properties" : {
                    "$yourKey" : "your_object_stringified"
               }
           }
       
      and transforms it into
           {
               "properties" : your_transformed_object
           }
       
      Parameters:
      coercionFunctions - Any additional type coercion functions in addition to the standard functions
      substitutionService - The SubstitutionService to use to do property substitution.
  • Method Details

    • inlineCoercionFunction

      public static JsonValuePropertyEvaluator.CoercionFunctionSpec inlineCoercionFunction(Path relativeTo)
      Creates a coercion function that inlines the content of another file that may be a relative path to a current location.

      For example, given this content at /tmp/mycontent:

       Content that is too large to be
       written directly into a JSON file.
       e.g. email template
       
      The this format:
           {
               "attribute" : {
                    "$inline" : "/tmp/mycontent"
               }
           }
       
      would be converted into this
           {
               "attribute" : "Content that is too large to be\nwritten directly into a JSON file\ne.g. email template"
           }
       
      Parameters:
      relativeTo - The path that the inlined file will be resolved from, if it is not absolute.
      Returns:
      A pair of a predicate (that tests to see if this coercion function is referenced by a JSON object) and the coercion function.
    • coerce

      Define a coercion function.
      Parameters:
      predicate - The predicate that will match JSON that can be coerced.
      Returns:
      A build to complete the specification.
    • singleKeyWithName

      public static Predicate<JsonValue> singleKeyWithName(String name)
      Create a predicate for a JSON coercion function as used in the Map argument to JsonValuePropertyEvaluator(SubstitutionService, List).
      Parameters:
      name - The name of the coercion function.
      Returns:
      A JsonValue predicate.
    • evaluate

      public JsonValue evaluate(JsonValue object, boolean escape) throws SubstitutionException
      Traverses a JsonValue and does property substitution as well as any type coercion.
      Parameters:
      object - The JsonValue to traverse
      escape - If true the SubstitutionService.substitute(String, boolean) method will support escaping. If false the SubstitutionService.substitute(String, boolean) method will NOT support escaping
      Returns:
      A property substituted and coerced JsonValue
      Throws:
      SubstitutionException - when substitution is interrupted because of an error (unresolved var or cycle)
    • evaluate

      public JsonValue evaluate(JsonValue object, SubstitutionContext context) throws SubstitutionException
      Traverses a JsonValue and does property substitution as well as any type coercion.
      Parameters:
      object - The JsonValue to traverse
      context - The SubstitutionContext to use when evaluating the properties for substitution
      Returns:
      A property substituted and coerced JsonValue
      Throws:
      SubstitutionException - when substitution is interrupted because of an error (unresolved var or cycle)