Package org.forgerock.config.util
Class JsonValuePropertyEvaluator
- java.lang.Object
-
- org.forgerock.config.util.JsonValuePropertyEvaluator
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JsonValuePropertyEvaluator.CoercionFunctionSpec
The specification for a coercion function.static class
JsonValuePropertyEvaluator.CoercionFunctionSpecBuilder
Builder to create aJsonValuePropertyEvaluator.CoercionFunctionSpec
.
-
Constructor Summary
Constructors Constructor Description JsonValuePropertyEvaluator(SubstitutionService substitutionService, List<JsonValuePropertyEvaluator.CoercionFunctionSpec> coercionFunctions)
Constructs a JsonValuePropertyEvaluator which traverses aJsonValue
and does property substitution as well as type coercion.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JsonValuePropertyEvaluator.CoercionFunctionSpecBuilder
coerce(Predicate<JsonValue> predicate)
Define a coercion function.JsonValue
evaluate(JsonValue object, boolean escape)
Traverses aJsonValue
and does property substitution as well as any type coercion.JsonValue
evaluate(JsonValue object, SubstitutionContext context)
Traverses aJsonValue
and does property substitution as well as any type coercion.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.static Predicate<JsonValue>
singleKeyWithName(String name)
Create a predicate for a JSON coercion function as used in theMap
argument toJsonValuePropertyEvaluator(SubstitutionService, List)
.
-
-
-
Constructor Detail
-
JsonValuePropertyEvaluator
public JsonValuePropertyEvaluator(SubstitutionService substitutionService, List<JsonValuePropertyEvaluator.CoercionFunctionSpec> coercionFunctions)
Constructs a JsonValuePropertyEvaluator which traverses aJsonValue
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 functionssubstitutionService
- TheSubstitutionService
to use to do property substitution.
-
-
Method Detail
-
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
public static JsonValuePropertyEvaluator.CoercionFunctionSpecBuilder coerce(Predicate<JsonValue> predicate)
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 theMap
argument toJsonValuePropertyEvaluator(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 aJsonValue
and does property substitution as well as any type coercion.- Parameters:
object
- TheJsonValue
to traverseescape
- If true theSubstitutionService.substitute(String, boolean)
method will support escaping. If false theSubstitutionService.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 aJsonValue
and does property substitution as well as any type coercion.- Parameters:
object
- TheJsonValue
to traversecontext
- TheSubstitutionContext
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)
-
-