use of org.mvel2.templates.CompiledTemplate in project mvel by mikebrock.
the class CompiledNamedIncludeNode method eval.
public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) {
if (cPreExpression != null) {
MVEL.executeExpression(cPreExpression, ctx, factory);
}
if (next != null) {
String namedTemplate = MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class);
CompiledTemplate ct = runtime.getNamedTemplateRegistry().getNamedTemplate(namedTemplate);
if (ct == null)
throw new TemplateError("named template does not exist: " + namedTemplate);
return next.eval(runtime, appender.append(String.valueOf(TemplateRuntime.execute(ct, ctx, factory, runtime.getNamedTemplateRegistry()))), ctx, factory);
// return next.eval(runtime,
// appender.append(String.valueOf(TemplateRuntime.execute(runtime.getNamedTemplateRegistry().getNamedTemplate(MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class)), ctx, factory))), ctx, factory);
} else {
return appender.append(String.valueOf(TemplateRuntime.execute(runtime.getNamedTemplateRegistry().getNamedTemplate(MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class)), ctx, factory, runtime.getNamedTemplateRegistry())));
}
}
use of org.mvel2.templates.CompiledTemplate in project mvel by mikebrock.
the class TemplateTests method testMVEL244.
public void testMVEL244() {
Foo244 foo = new Foo244("plop");
String template = "@foreach{val : foo.liste[0].liste} plop @end{}";
CompiledTemplate compiledTemplate = TemplateCompiler.compileTemplate(template);
Map<String, Object> model = new HashMap<String, Object>();
model.put("foo", foo);
System.out.println(TemplateRuntime.execute(compiledTemplate, new ParserContext(), new MapVariableResolverFactory(model)));
}
use of org.mvel2.templates.CompiledTemplate in project drools by kiegroup.
the class AccumulateTemplateTest method getRuleTemplateRegistry.
private TemplateRegistry getRuleTemplateRegistry() {
TemplateRegistry ruleRegistry = new SimpleTemplateRegistry();
CompiledTemplate compiled = TemplateCompiler.compileTemplate(JavaRuleBuilderHelper.class.getResourceAsStream("javaRule.mvel"), (Map<String, Class<? extends Node>>) null);
TemplateRuntime.execute(compiled, null, ruleRegistry);
return ruleRegistry;
}
use of org.mvel2.templates.CompiledTemplate in project drools by kiegroup.
the class DefaultGenerator method getTemplate.
private CompiledTemplate getTemplate(String templateName) throws IOException {
CompiledTemplate contents;
if (!registry.contains(templateName)) {
RuleTemplate template = ruleTemplates.get(templateName);
contents = TemplateCompiler.compileTemplate(template.getContents());
registry.addNamedTemplate(templateName, contents);
} else {
contents = registry.getNamedTemplate(templateName);
}
return contents;
}
use of org.mvel2.templates.CompiledTemplate in project mvel by mvel.
the class MVELIncludeTest method testEvalFile1.
/**
* evalFile with sub template in utf-8 encoding
*
* @throws IOException
*/
public void testEvalFile1() throws IOException {
final CompiledTemplate template = TemplateCompiler.compileTemplate(file);
final String tr = (String) new TemplateRuntime(template.getTemplate(), null, template.getRoot(), "./samples/scripts/").execute(new StringAppender(), new HashMap<String, String>(), new ImmutableDefaultFactory());
assertEquals("Hello mister Gaël Périé", tr);
}
Aggregations