Package com.alibaba.citrus.service.template.support

Examples of com.alibaba.citrus.service.template.support.MappedTemplateContext


    @Test
    public void escape_directive_default() throws Exception {
        getEngine("with_defaultEscape", factory);

        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("count", new Counter());
        ctx.put("object", new MyRenderable("<world name=\"中国\" />"));

        String content = templateService.getText("escape/test_escape.vm", ctx);

        // original - default html
        assertThat(content, containsString("1. &lt;world name=&quot;中国&quot; /&gt;"));

        // html
        assertThat(content, containsString("2. &lt;world name=&quot;中国&quot; /&gt;"));

        // javascript
        assertThat(content, containsString("3. <world name=\\\"中国\\\" \\/>"));

        // html (restored)
        assertThat(content, containsString("4. &lt;world name=&quot;中国&quot; /&gt;"));

        // noescape
        assertThat(content, containsString("5. <world name=\"中国\" />"));

        // url encoding
        assertThat(content, containsString("6. %3Cworld+name%3D%22%D6%D0%B9%FA%22+%2F%3E"));

        // noescape (restored)
        assertThat(content, containsString("7. <world name=\"中国\" />"));

        // html (restored)
        assertThat(content, containsString("8. &lt;world name=&quot;中国&quot; /&gt;"));

        // original (restored) - default html
        assertThat(content, containsString("9. &lt;world name=&quot;中国&quot; /&gt;"));

        assertFalse(ctx.containsKey("_ESCAPE_SUPPORT_TYPE_"));
    }
View Full Code Here


    @Test
    public void escape_directive_default_interplate() throws Exception {
        getEngine("with_defaultEscape", factory);

        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("count", new Counter());
        ctx.put("object", new MyRenderable("<world name=\"中国\" />"));

        String content = templateService.getText("escape/test_escape_interpolation.vm", ctx);

        assertThat(content, containsString("1. &lt;world name=&quot;中国&quot; /&gt;"));
    }
View Full Code Here

    @Test
    public void escape_directive_parse() throws Exception {
        getEngine("with_escape", factory);

        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("count", new Counter());
        ctx.put("object", new MyRenderable("<world name=\"中国\" />"));

        String content = templateService.getText("escape/test_escape_parse.vm", ctx);

        assertThat(content, containsString("1. &lt;world name=&quot;中国&quot; /&gt;"));
View Full Code Here

    @Test
    public void escape_directive_all_types() throws Exception {
        getEngine("with_escape", factory);

        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("count", new Counter());
        ctx.put("object", new MyRenderable("<world name=\"'中国'\" />"));

        String content = templateService.getText("escape/test_escape_all_types.vm", ctx);

        // noescape
        assertThat(content, containsString("1. <world name=\"'中国'\" />"));

        // java
        assertThat(content, containsString("2. <world name=\\\"'中国'\\\" />"));

        // javascript
        assertThat(content, containsString("3. <world name=\\\"\\'中国\\'\\\" \\/>"));

        // html
        assertThat(content, containsString("4. &lt;world name=&quot;&#39;中国&#39;&quot; /&gt;"));

        // xml
        assertThat(content, containsString("5. &lt;world name=&quot;&apos;中国&apos;&quot; /&gt;"));

        // url
        assertThat(content, containsString("6. %3Cworld+name%3D%22'%D6%D0%B9%FA'%22+%2F%3E"));

        // sql
        assertThat(content, containsString("7. <world name=\"''中国''\" />"));

        assertFalse(ctx.containsKey("_ESCAPE_SUPPORT_TYPE_"));
    }
View Full Code Here

    @Test
    public void escape_directive_macros() throws Exception {
        getEngine("with_escape", factory);

        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("count", new Counter());
        ctx.put("object", new MyRenderable("<world name=\"'中国'\" />"));

        String content = templateService.getText("escape/test_escape_macros.vm", ctx);

        // noescape
        assertThat(content, containsString("1. <world name=\"'中国'\" />"));

        // java
        assertThat(content, containsString("2. <world name=\\\"'中国'\\\" />"));

        // javascript/js
        assertThat(content, containsString("3. <world name=\\\"\\'中国\\'\\\" \\/>"));
        assertThat(content, containsString("4. <world name=\\\"\\'中国\\'\\\" \\/>"));

        // html
        assertThat(content, containsString("5. &lt;world name=&quot;&#39;中国&#39;&quot; /&gt;"));

        // xml
        assertThat(content, containsString("6. &lt;world name=&quot;&apos;中国&apos;&quot; /&gt;"));

        // url
        assertThat(content, containsString("7. %3Cworld+name%3D%22'%D6%D0%B9%FA'%22+%2F%3E"));

        // sql
        assertThat(content, containsString("8. <world name=\"''中国''\" />"));

        assertFalse(ctx.containsKey("_ESCAPE_SUPPORT_TYPE_"));
    }
View Full Code Here

    }

    private void escape_with_rules_internal(ApplicationContext factory) throws Exception {
        getEngine("with_rules", factory);

        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("value", "<world name=\"'中国'\" />");
        ctx.put("jsValue", "<world name=\"'中国'\" />");
        ctx.put("control", new MyControl());
        ctx.put("Screen_Placeholder", "<world name=\"'中国'\" />");
        ctx.put("stringescapeutil", new StringEscapeUtil());

        String content = templateService.getText("escape/test_escape_rules.vm", ctx);

        // default = html
        assertThat(content, containsString("1. &lt;world name=&quot;&#39;中国&#39;&quot; /&gt;"));
View Full Code Here

    @Test
    public void escape_define() throws Exception {
        getEngine("with_defaultEscape", factory);

        TemplateContext ctx = new MappedTemplateContext();

        String content = templateService.getText("escape/test_escape_define.vm", ctx);

        assertThat(content, containsString("1. Hello World!"));
        assertThat(content, containsString("2. Hello &lt;World /&gt;"));
View Full Code Here

    /** 测试noescape时,直接返回value object,而不是对其执行toString方法。 */
    @Test
    public void escape_object_noescape() throws Exception {
        getEngine("with_rules_for_object", factory);

        TemplateContext ctx = new MappedTemplateContext();

        // EscapeSupport先执行,由于是noescape,所以直接返回value object,而不是value.toString()
        // 后续的Renderable2Handler得以执行,并调用render方法。
        ctx.put("myref", new Renderable2() {
            public String render2() {
                return "render";
            }

            @Override
View Full Code Here

        Iterator<?> i = velocityEngine.getConfiguration().getEventCartridge().getReferenceInsertionEventHandlers();
        assertThat(i.next(), instanceOf(RenderableHandler.class));
        assertFalse(i.hasNext());

        // 渲染
        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("object", new MyRenderable());

        String content = templateService.getText("test_renderable.vm", ctx);
        assertThat(content, containsString("from render()"));
        assertThat(content, not(containsString("from toString()")));
    }
View Full Code Here

        assertThat(i.next(), instanceOf(MakeEverythingRenderable.class));
        assertThat(i.next(), instanceOf(RenderableHandler.class));
        assertFalse(i.hasNext());

        // 渲染
        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("object", "world");

        String content = templateService.getText("test_renderable.vm", ctx);
        assertThat(content, containsString("Hello, world"));
    }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.service.template.support.MappedTemplateContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.