Package jetbrick.template.utils

Examples of jetbrick.template.utils.UnsafeCharArrayWriter


    public JetTagContext(JetPageContext ctx) {
        this.ctx = ctx;
    }

    public String getBodyContent() {
        UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
        String encoding = ctx.getEngine().getConfig().getOutputEncoding();
        try {
            render(ctx.getContext(), JetWriter.create(out, encoding));
        } catch (Throwable e) {
            handleException(e);
        }
        return out.toString();
    }
View Full Code Here


    }

    @Test
    public void found() throws Exception {
        JetTemplate template = engine.createTemplate("${copyright} - ${today.format('yyyy')}");
        UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
        template.render(new JetContext(), out);
        Assert.assertEquals(out.toString(), "copyright@2000-2010 - 2014");
    }
View Full Code Here

    @Test
    public void pkgAccess() throws Exception {
        try {
            JetTemplate template = engine.createTemplate("${new HashMap()}");
            UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
            template.render(new JetContext(), out);
        } catch (AccessControlException e) {
            return;
        }
        Assert.fail();
View Full Code Here

    }

    @Test
    public void classAccess() throws Exception {
        JetTemplate template = engine.createTemplate("${new Date()}");
        UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
        template.render(new JetContext(), out);
    }
View Full Code Here

    @Test
    public void methodAccess() throws Exception {
        try {
            JetTemplate template = engine.createTemplate("${new Date().time}");
            UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
            template.render(new JetContext(), out);
        } catch (AccessControlException e) {
            return;
        }
        Assert.fail();
View Full Code Here

    @Test
    public void fieldAccess() throws Exception {
        try {
            JetTemplate template = engine.createTemplate("${@Integer.MAX_VALUE}");
            UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
            template.render(new JetContext(), out);
        } catch (AccessControlException e) {
            return;
        }
        Assert.fail();
View Full Code Here

    public void noneCompiled() {
        Properties config = new Properties();
        config.put(JetConfig.COMPILE_STRATEGY, "none");
        JetEngine engine = JetEngine.create(config);
        JetTemplate template = engine.getTemplate("/template/text-plain.jetx");
        UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
        JetContext context = new JetContext();
        template.render(context, out);
        System.out.println(out.toString());

        // 在 none 的情况下,source code 还是要编译的
        template = engine.createTemplate("你好");
        out = new UnsafeCharArrayWriter();
        template.render(new JetContext(), out);
        System.out.println(out.toString());
        Assert.assertEquals(out.toString(), "你好");
    }
View Full Code Here

    private final JetEngine engine = JetEngine.create();

    @Test
    public void plain() {
        JetTemplate template = engine.createTemplate("你好");
        UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
        template.render(new JetContext(), out);
        Assert.assertEquals("你好", out.toString());
    }
View Full Code Here

    }

    @Test
    public void expression() {
        JetTemplate template = engine.createTemplate("${1+2*3}");
        UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
        template.render(new JetContext(), out);
        Assert.assertEquals("7", out.toString());
    }
View Full Code Here

        sb.append("  #for(String app: apps)\n");
        sb.append("    ${app}\n");
        sb.append("  #end\n");
        sb.append("#end\n");
        JetTemplate template = engine.createTemplate(sb.toString());
        UnsafeCharArrayWriter out = new UnsafeCharArrayWriter();
        template.render(context, out);
        Assert.assertEquals("    1\n    2\n    3\n    a\n    b\n    c\n", out.toString());
    }
View Full Code Here

TOP

Related Classes of jetbrick.template.utils.UnsafeCharArrayWriter

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.