use of org.apache.commons.jexl3.JxltEngine in project commons-jexl by apache.
the class Issues200Test method testTemplate6565a.
@Test
public void testTemplate6565a() throws Exception {
final JexlEngine jexl = new JexlBuilder().create();
final JxltEngine jexlt = jexl.createJxltEngine();
final String source = "$$ var res = '';\n" + "$$ var meta = session.data['METADATA'];\n" + "$$ if (meta) {\n" + "$$ var entry = meta['ID'];\n" + "$$ if (entry) {\n" + "$$ var value = session.data[entry];\n" + "$$ res = value?: '';\n" + "$$ }\n" + "$$ }\n" + "${res}\n";
final JxltEngine.Template script = jexlt.createTemplate("$$", new StringReader(source));
Assert.assertNotNull(script);
final TemplateDebugger dbg = new TemplateDebugger();
final String refactored = dbg.debug(script) ? dbg.toString() : "";
Assert.assertNotNull(refactored);
Assert.assertEquals(source, refactored);
}
use of org.apache.commons.jexl3.JxltEngine in project commons-jexl by apache.
the class JXLTTest method testSanboxedTemplate.
@Test
public void testSanboxedTemplate() throws Exception {
final String src = "Hello ${user}";
final JexlContext ctxt = new MapContext();
ctxt.set("user", "Francesco");
// / this uberspect can not access jexl3 classes (besides test)
Uberspect uberspect = new Uberspect(LogFactory.getLog(JXLTTest.class), null, NOJEXL3);
Method method = uberspect.getMethod(TemplateInterpreter.class, "print", new Object[] { Integer.TYPE });
Assert.assertNull(method);
// ensures JXLT sandboxed still executes
final JexlEngine jexl = new JexlBuilder().uberspect(uberspect).create();
final JxltEngine jxlt = jexl.createJxltEngine();
JxltEngine.Template tmplt = jxlt.createTemplate(src);
Writer strw = new StringWriter();
tmplt.evaluate(ctxt, strw);
String result = strw.toString();
Assert.assertEquals("Hello Francesco", result);
}
use of org.apache.commons.jexl3.JxltEngine in project syncope by apache.
the class JexlUtilsTest method newJxltEngine.
@Test
public void newJxltEngine() {
JxltEngine engine = JexlUtils.newJxltEngine();
assertNotNull(engine);
}
use of org.apache.commons.jexl3.JxltEngine in project commons-jexl by apache.
the class JXLTTest method testSanboxed311i.
@Test
public void testSanboxed311i() throws Exception {
// / this uberspect can not access jexl3 classes (besides test)
Uberspect uberspect = new Uberspect(LogFactory.getLog(JXLTTest.class), null, NOJEXL3);
Method method = uberspect.getMethod(TemplateInterpreter.class, "print", new Object[] { Integer.TYPE });
final JexlEngine jexl = new JexlBuilder().uberspect(uberspect).create();
final JxltEngine jxlt = jexl.createJxltEngine();
final JexlContext ctx311 = new Context311();
final String rpt = "$$var u = 'Universe'; exec('4').execute((a, b)->{" + "\n<p>${u} ${a}${b}</p>" + "\n$$}, '2')";
final JxltEngine.Template t = jxlt.createTemplate("$$", new StringReader(rpt));
final StringWriter strw = new StringWriter();
t.evaluate(ctx311, strw, 42);
final String output = strw.toString();
Assert.assertEquals("<p>Universe 42</p>\n", output);
}
use of org.apache.commons.jexl3.JxltEngine in project commons-jexl by apache.
the class Issues200Test method testTemplate6565b.
@Test
public void testTemplate6565b() throws Exception {
final JexlEngine jexl = new JexlBuilder().create();
final JxltEngine jexlt = jexl.createJxltEngine();
final String source = "$$ var res = '';\n" + "$$ var meta = session.data['METADATA'];\n" + "$$ if (meta) {\n" + "$$ var entry = meta['ID'];\n" + "$$ if (entry) {\n" + "$$ var value = session.data[entry];\n" + "$$ res = value?: '';\n" + "${res}\n" + "$$ }\n" + "$$ }\n";
final JxltEngine.Template script = jexlt.createTemplate("$$", new StringReader(source));
Assert.assertNotNull(script);
final TemplateDebugger dbg = new TemplateDebugger();
final String refactored = dbg.debug(script) ? dbg.toString() : "";
Assert.assertNotNull(refactored);
Assert.assertEquals(source, refactored);
}
Aggregations