Package com.alibaba.citrus.service.template

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


    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

            // ����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_parse() 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_parse.vm", ctx);

        assertThat(content, containsString("1. &lt;world name=&quot;中国&quot; /&gt;"));
View Full Code Here

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

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

        // java
        assertThat(content, containsString("2. <world name=\\\"'中国'\\\" />"));

        // javascript
        assertThat(content, containsString("3. <world name=\\\"\\'中国\\'\\\" \\/>"));

        // html
        assertThat(content, containsString("4. &lt;world name=&quot;&#39;中国&#39;&quot; /&gt;"));

        // xml
        assertThat(content, containsString("5. &lt;world name=&quot;&apos;中国&apos;&quot; /&gt;"));

        // url
        assertThat(content, containsString("6. %3Cworld+name%3D%22'%D6%D0%B9%FA'%22+%2F%3E"));

        // sql
        assertThat(content, containsString("7. <world name=\"''中国''\" />"));

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

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

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

        // java
        assertThat(content, containsString("2. <world name=\\\"'中国'\\\" />"));

        // javascript/js
        assertThat(content, containsString("3. <world name=\\\"\\'中国\\'\\\" \\/>"));
        assertThat(content, containsString("4. <world name=\\\"\\'中国\\'\\\" \\/>"));

        // html
        assertThat(content, containsString("5. &lt;world name=&quot;&#39;中国&#39;&quot; /&gt;"));

        // xml
        assertThat(content, containsString("6. &lt;world name=&quot;&apos;中国&apos;&quot; /&gt;"));

        // url
        assertThat(content, containsString("7. %3Cworld+name%3D%22'%D6%D0%B9%FA'%22+%2F%3E"));

        // sql
        assertThat(content, containsString("8. <world name=\"''中国''\" />"));

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

    }

    private void escape_with_rules_internal(ApplicationContext factory) throws Exception {
        getEngine("with_rules", factory);

        TemplateContext ctx = new MappedTemplateContext();
        ctx.put("value", "<world name=\"'中国'\" />");
        ctx.put("jsValue", "<world name=\"'中国'\" />");
        ctx.put("control", new MyControl());
        ctx.put("Screen_Placeholder", "<world name=\"'中国'\" />");
        ctx.put("stringescapeutil", new StringEscapeUtil());

        String content = templateService.getText("escape/test_escape_rules.vm", ctx);

        // default = html
        assertThat(content, containsString("1. &lt;world name=&quot;&#39;中国&#39;&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.