Search in sources :

Example 6 with SimpleTemplateRegistry

use of org.mvel2.templates.SimpleTemplateRegistry in project mvel by mvel.

the class TemplateTests method testDRLTemplate.

public void testDRLTemplate() {
    String template = "@declare{\"drl\"}@includeNamed{\"ced\"; node=root }@end{}" + "" + "@declare{\"ced\"}" + "@if{ node.base==1 } @includeNamed{ \"cedX\"; connect=\"AND\"; args=node.list }" + "@elseif{ node.base ==2 }@includeNamed{ \"cedX\"; connect=\"OR\"; args=node.list }" + "@end{}" + "@end{}" + "" + "@declare{\"cedX\"}@{connect}@foreach{child : args}" + "@includeNamed{\"ced\"; node=child; }@end{} @{connect}@end{}";
    TemplateRegistry reportRegistry = new SimpleTemplateRegistry();
    reportRegistry.addNamedTemplate("drl", TemplateCompiler.compileTemplate(template));
    TemplateRuntime.execute(reportRegistry.getNamedTemplate("drl"), null, reportRegistry);
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("root", new Node(2, Arrays.asList(new Node(1, Collections.EMPTY_LIST))));
    String result = (String) TemplateRuntime.execute(reportRegistry.getNamedTemplate("drl"), null, new MapVariableResolverFactory(context), reportRegistry);
    assertEquals("OR AND AND OR", result);
}
Also used : TemplateRegistry(org.mvel2.templates.TemplateRegistry) SimpleTemplateRegistry(org.mvel2.templates.SimpleTemplateRegistry) TestPluginNode(org.mvel2.tests.templates.tests.res.TestPluginNode) SimpleTemplateRegistry(org.mvel2.templates.SimpleTemplateRegistry) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 7 with SimpleTemplateRegistry

use of org.mvel2.templates.SimpleTemplateRegistry in project mvel by mvel.

the class TemplateTests method testInclusionOfNamedTemplate.

public void testInclusionOfNamedTemplate() {
    SimpleTemplateRegistry registry = new SimpleTemplateRegistry();
    registry.addNamedTemplate("footemplate", compileTemplate("@{_foo_}@{_bar_}"));
    registry.addNamedTemplate("bartemplate", compileTemplate("@{_bar_}@{_foo_}"));
    String s = "@includeNamed{'footemplate'}  ::  @includeNamed{'bartemplate'}";
    assertEquals("FooBar  ::  BarFoo", TemplateRuntime.eval(s, map, registry));
}
Also used : SimpleTemplateRegistry(org.mvel2.templates.SimpleTemplateRegistry)

Example 8 with SimpleTemplateRegistry

use of org.mvel2.templates.SimpleTemplateRegistry in project drools by kiegroup.

the class MiningSegmentation method initTemplates.

private static synchronized void initTemplates() {
    if (templates == null) {
        templates = new SimpleTemplateRegistry();
    }
    if (templateNameToFile == null) {
        templateNameToFile = new HashMap<>();
        templateNameToFile.put(MULTIPLEMODELMETHOD.SELECT_FIRST.name(), segmentActivationSelectFirst);
        templateNameToFile.put(MULTIPLEMODELMETHOD.SELECT_ALL.name(), segmentSelectAll);
        templateNameToFile.put(MULTIPLEMODELMETHOD.MODEL_CHAIN.name(), segmentModelChain);
    }
}
Also used : SimpleTemplateRegistry(org.mvel2.templates.SimpleTemplateRegistry)

Aggregations

SimpleTemplateRegistry (org.mvel2.templates.SimpleTemplateRegistry)8 TemplateRegistry (org.mvel2.templates.TemplateRegistry)3 CompiledTemplate (org.mvel2.templates.CompiledTemplate)2 Node (org.mvel2.templates.res.Node)2 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)1 TestPluginNode (org.mvel2.tests.templates.tests.res.TestPluginNode)1