Package com.alibaba.citrus.service.template

Examples of com.alibaba.citrus.service.template.TemplateContext


    @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 <World />"));
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

    @Test
    public void escape_url() throws Exception {
        getEngine("templateService", factory);

        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("world", "中国");

        // configured value: UTF-8
        String content = templateService.getText("test_url_encode.ftl", ctx);
        assertThat(content, containsString("你好,%E4%B8%AD%E5%9B%BD"));
View Full Code Here

    @Test
    public void escape_html() throws Exception {
        getEngine("templateService", factory);

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

        // configured value: UTF-8
        String content = templateService.getText("test_html_escape.ftl", ctx);
        assertThat(content, containsString("你好,&lt;country name=&quot;中国&quot; /&gt;"));
    }
View Full Code Here

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

        TemplateContext ctx = new MappedTemplateContext();

        try {
            templateService.getText("escape/test_escape_wrong_args_0.vm", ctx);
            fail();
        } catch (TemplateException e) {
View Full Code Here

    @Test
    public void escape_directive() 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.vm", ctx);

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

        // 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)
        assertThat(content, containsString("9. <world name=\"中国\" />"));

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

    @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

TOP

Related Classes of com.alibaba.citrus.service.template.TemplateContext

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.