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

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


public class TemplateContextAdapterTests {
    private TemplateContext ctx;

    @Before
    public void init() {
        ctx = new MappedTemplateContext();

        ctx.put("aaa", 111);
        ctx.put("bbb", 222);
        ctx.put("ccc", 333);
    }
View Full Code Here


            public void removeAttribute(String name) {
                map.remove(name);
            }
        };

        context = new MappedTemplateContext();

        context.put("ccc", 3333);
        context.put("ddd", 4444);

        adapter = new TemplateContextAdapter(request, context);
View Full Code Here

            // 设置contentType和charset,和jsp中的设置不同,以此为准
            rc.getResponse().setContentType("text/plain; charset=GBK"); // JSP: text/html; charset=UTF-8

            // 预备template context
            TemplateContext context = new MappedTemplateContext();
            context.put("hello", "中国");

            String jsp = jspx ? "/test.jspx" : "/test.jsp";

            // 渲染
            switch (type) {
View Full Code Here

            // 设置contentType和charset,和jsp中的设置不同,以此为准
            rc.getResponse().setContentType("text/plain; charset=GBK"); // JSP: text/html; charset=UTF-8

            // 预备template context
            TemplateContext context = new MappedTemplateContext();
            context.put("hello", "中国");

            String jsp = jspx ? "/test.jspx" : "/test.jsp";

            // 渲染
            switch (type) {
View Full Code Here

    public void render_byTemplateService() throws Exception {
        getEngine("templateService", factory);
        assertProperty("default_encoding", "GBK");
        assertProperty("output_encoding", "UTF-8");

        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("world", "世界");

        String content;

        // TemplateService.getText()
        content = templateService.getText("test_render.ftl", ctx);
View Full Code Here

    public void render_error() throws Exception {
        getEngine("templateService", factory);
        assertProperty("default_encoding", "GBK");
        assertProperty("output_encoding", "UTF-8");

        TemplateContext ctx = new MappedTemplateContext();

        // 未找到模板
        try {
            templateService.getText("notExist.ftl", ctx);
            fail();
View Full Code Here

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

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

        String content = templateService.getText("test_renderable.ftl", ctx);
        assertThat(content, containsString("from render()"));
        assertThat(content, not(containsString("from toString()")));
    }
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

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.