Search in sources :

Example 31 with CompiledTemplate

use of org.mvel2.templates.CompiledTemplate in project mvel by mikebrock.

the class TemplateTests method testOutputStream1.

public void testOutputStream1() {
    final StringBuilder sb = new StringBuilder();
    OutputStream outstream = new OutputStream() {

        @Override
        public void write(int b) throws IOException {
            sb.append((char) b);
        }
    };
    String template = "@foreach{item:['foo','far']}@{item}@end{}";
    CompiledTemplate compiled = TemplateCompiler.compileTemplate(template);
    TemplateRuntime.execute(compiled, new HashMap(), outstream);
    assertEquals("foofar", sb.toString());
}
Also used : OutputStream(java.io.OutputStream) CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Example 32 with CompiledTemplate

use of org.mvel2.templates.CompiledTemplate in project mvel by mikebrock.

the class TemplateTests method testPluginNode.

public void testPluginNode() {
    Map<String, Class<? extends Node>> plugins = new HashMap<String, Class<? extends Node>>();
    plugins.put("testNode", TestPluginNode.class);
    TemplateCompiler compiler = new TemplateCompiler("Foo:@testNode{}!!", plugins);
    CompiledTemplate compiled = compiler.compile();
    assertEquals("Foo:THIS_IS_A_TEST!!", TemplateRuntime.execute(compiled));
}
Also used : Node(org.mvel2.templates.res.Node) TestPluginNode(org.mvel2.tests.templates.tests.res.TestPluginNode) TemplateCompiler(org.mvel2.templates.TemplateCompiler) CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Example 33 with CompiledTemplate

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

the class TemplateTests method testOutputStream1.

public void testOutputStream1() {
    final StringBuilder sb = new StringBuilder();
    OutputStream outstream = new OutputStream() {

        @Override
        public void write(int b) throws IOException {
            sb.append((char) b);
        }
    };
    String template = "@foreach{item:['foo','far']}@{item}@end{}";
    CompiledTemplate compiled = TemplateCompiler.compileTemplate(template);
    TemplateRuntime.execute(compiled, new HashMap(), outstream);
    assertEquals("foofar", sb.toString());
}
Also used : OutputStream(java.io.OutputStream) CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Aggregations

CompiledTemplate (org.mvel2.templates.CompiledTemplate)32 HashMap (java.util.HashMap)8 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)6 Node (org.mvel2.templates.res.Node)5 InputStream (java.io.InputStream)4 SimpleTemplateRegistry (org.mvel2.templates.SimpleTemplateRegistry)4 TemplateRegistry (org.mvel2.templates.TemplateRegistry)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ParserContext (org.mvel2.ParserContext)3 TemplateCompiler (org.mvel2.templates.TemplateCompiler)3 OutputStream (java.io.OutputStream)2 Date (java.util.Date)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 JavaRuleBuilderHelper (org.drools.mvel.java.JavaRuleBuilderHelper)2 ImmutableDefaultFactory (org.mvel2.integration.impl.ImmutableDefaultFactory)2 TemplateError (org.mvel2.templates.TemplateError)2 TemplateRuntime (org.mvel2.templates.TemplateRuntime)2 TestPluginNode (org.mvel2.tests.templates.tests.res.TestPluginNode)2 StringAppender (org.mvel2.util.StringAppender)2 VertxInternal (io.vertx.core.impl.VertxInternal)1