Package com.alibaba.citrus.service.template

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


    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

    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

            // 设置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

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.