Search in sources :

Example 1 with ByteWriter

use of org.beetl.core.ByteWriter in project beetl2.0 by javamonkey.

the class ContentBodyExpression method evaluate.

public Object evaluate(Context ctx) {
    ByteWriter real = ctx.byteWriter;
    ByteWriter temp = real.getTempWriter(real);
    ctx.byteWriter = temp;
    block.execute(ctx);
    ctx.byteWriter = real;
    return temp.getTempConent();
}
Also used : ByteWriter(org.beetl.core.ByteWriter)

Example 2 with ByteWriter

use of org.beetl.core.ByteWriter in project beetl2.0 by javamonkey.

the class BeetlUtil method getWriterByByteWriter.

public static Writer getWriterByByteWriter(ByteWriter byteWriter) {
    ByteWriter temp = null;
    while ((temp = byteWriter.getParent()) != null) {
        byteWriter = temp;
    }
    Writer w = null;
    if (byteWriter instanceof ByteWriter_Char) {
        ByteWriter_Char bw = (ByteWriter_Char) byteWriter;
        w = bw.getW();
    } else {
        ByteWriter_Byte bw = (ByteWriter_Byte) byteWriter;
        try {
            w = new OutputStreamWriter(bw.getOs(), bw.getCs());
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
    return w;
}
Also used : ByteWriter_Char(org.beetl.core.io.ByteWriter_Char) ByteWriter_Byte(org.beetl.core.io.ByteWriter_Byte) ByteWriter(org.beetl.core.ByteWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) ByteWriter(org.beetl.core.ByteWriter) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 3 with ByteWriter

use of org.beetl.core.ByteWriter in project beetl2.0 by javamonkey.

the class IncludeTag method render.

@Override
public void render() {
    String resourceId = getRelResourceId();
    ;
    Template t = gt.getTemplate(resourceId, this.ctx.getResourceId());
    // 快速复制父模板的变量
    t.binding(this.ctx.globalVar);
    if (ctx.objectKeys != null && ctx.objectKeys.size() != 0) {
        t.dynamic(ctx.objectKeys);
    }
    if (this.args.length == 2) {
        Map<String, Object> map = (Map<String, Object>) this.args[1];
        for (Entry<String, Object> entry : map.entrySet()) {
            Object value = entry.getValue();
            if (value instanceof Map || value instanceof Collection) {
                t.binding((String) entry.getKey(), value, true);
            } else {
                t.binding((String) entry.getKey(), value);
            }
        }
    }
    ByteWriter bw = ctx.byteWriter;
    t.renderTo(bw);
}
Also used : Collection(java.util.Collection) ByteWriter(org.beetl.core.ByteWriter) Map(java.util.Map) Template(org.beetl.core.Template)

Example 4 with ByteWriter

use of org.beetl.core.ByteWriter in project beetl2.0 by javamonkey.

the class Println method call.

public String call(Object[] paras, Context ctx) {
    try {
        ByteWriter w = ctx.byteWriter;
        if (paras.length == 0) {
            w.writeString(ctx.template.program.metaData.lineSeparator);
            return "";
        }
        Object o = paras[0];
        if (o != null) {
            w.writeString(o.toString());
            w.writeString(ctx.template.program.metaData.lineSeparator);
        }
    } catch (IOException e) {
        BeetlException be = new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR);
        throw be;
    }
    return "";
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) ByteWriter(org.beetl.core.ByteWriter) IOException(java.io.IOException)

Aggregations

ByteWriter (org.beetl.core.ByteWriter)4 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Template (org.beetl.core.Template)1 BeetlException (org.beetl.core.exception.BeetlException)1 ByteWriter_Byte (org.beetl.core.io.ByteWriter_Byte)1 ByteWriter_Char (org.beetl.core.io.ByteWriter_Char)1