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

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


    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

    private TemplateContext        context;
    private TemplateContextAdapter adapter;

    @Before
    public void init() {
        context = new MappedTemplateContext();
        adapter = new TemplateContextAdapter(context);

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

    public void render_byTemplateService() throws Exception {
        getEngine("templateService", factory);
        assertProperty("input.encoding", "GBK");
        assertProperty("output.encoding", "UTF-8");

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

        String content;

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

    public void render_error() throws Exception {
        getEngine("templateService", factory);
        assertProperty("input.encoding", "GBK");
        assertProperty("output.encoding", "UTF-8");

        TemplateContext ctx = new MappedTemplateContext();

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

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

        TemplateContext ctx = new MappedTemplateContext();

        String content = templateService.getText("test_local_context.vm", ctx);

        assertThat(content, containsString("hello"));
        assertTrue(ctx.containsKey("varInContext")); // 模板中设置的变量会保留在context中
    }
View Full Code Here

    @Test
    public void render_set_null() throws Exception {
        getEngine("nostrict", factory);

        TemplateContext ctx = new MappedTemplateContext();

        String content = templateService.getText("test_set_null.vm", ctx);

        assertEquals("$a", content);
    }
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.