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

            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

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

            // ����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", "�й�");

            // ��Ⱦ
            switch (type) {
                case 1:
                    assertEquals("", templateService.getText("/test.jsp", context));
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

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.