use of com.bluenimble.platform.templating.impls.DefaultExpressionCompiler in project serverless by bluenimble.
the class TestTemplate method main.
public static void main(String[] args) {
String exp1 = "[model.a] [NoNs]";
String exp2 = "Hello [model.c]";
String exp3 = "[model.b] done";
String exp4 = "simple text";
String exp5 = "simple [model.b] [alpha.a] [beta | 'alpha']";
String exp6 = "{ price: '[model.b]' }>>json";
final JsonObject model = (JsonObject) new JsonObject().set("a", "A Value").set("b", 409).set("c", "Hello");
VariableResolver vr = new VariableResolver() {
private static final long serialVersionUID = -485939153491337463L;
@Override
public Object resolve(String namespace, String... property) {
System.out.println(namespace);
if (namespace == null) {
return null;
}
System.out.println(Lang.join(property, Lang.DOT));
if (namespace == null || namespace.equals("model")) {
return Json.find(model, property);
}
return null;
}
};
DefaultExpressionCompiler compiler = new DefaultExpressionCompiler();
System.out.println("exp1: " + compiler.compile(exp1, null).eval(vr));
System.out.println("exp2: " + compiler.compile(exp2, null).eval(vr));
System.out.println("exp3: " + compiler.compile(exp3, null).eval(vr));
System.out.println("exp4: " + compiler.compile(exp4, null).eval(vr));
System.out.println("exp5: " + compiler.compile(exp5, null).eval(vr));
System.out.println("exp6: " + compiler.compile(exp6, null).eval(vr));
}
Aggregations