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();
}
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;
}
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);
}
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 "";
}
Aggregations