Search in sources :

Example 1 with BodyContent

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

the class HTMLTagSupportWrapper method callHtmlTag.

protected void callHtmlTag(String path) {
    Template t = null;
    t = gt.getHtmlFunctionOrTagTemplate(path, this.ctx.getResourceId());
    t.binding(ctx.globalVar);
    t.dynamic(ctx.objectKeys);
    if (args.length == 2) {
        Map<String, Object> map = (Map<String, Object>) args[1];
        for (Entry<String, Object> entry : map.entrySet()) {
            t.binding(entry.getKey(), entry.getValue());
        }
    }
    BodyContent bodyContent = super.getBodyContent();
    t.binding("tagBody", bodyContent);
    t.renderTo(ctx.byteWriter);
}
Also used : BodyContent(org.beetl.core.BodyContent) Map(java.util.Map) Template(org.beetl.core.Template)

Example 2 with BodyContent

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

the class CacheTag method render.

@Override
public void render() {
    try {
        String key = null;
        long refreshPeriod = 0;
        BodyContent cahcedObject = null;
        key = (String) this.args[0];
        if (this.args.length == 3) {
            boolean refreshNow = ((Boolean) this.args[2]).booleanValue();
            if (refreshNow) {
                cahcedObject = super.getBodyContent();
                cacheManager.setObject(key, cahcedObject, refreshPeriod);
                cahcedObject.fill(bw);
                return;
            }
        }
        if (this.args.length >= 2) {
            refreshPeriod = ((Number) this.args[1]).longValue();
        } else {
            // 默认1小时刷新一次
            refreshPeriod = 60 * 60;
        }
        if (refreshPeriod < 0) {
            cahcedObject = super.getBodyContent();
            cacheManager.setObject(key, cahcedObject, refreshPeriod);
            cahcedObject.fill(bw);
        } else {
            cahcedObject = (BodyContent) cacheManager.getObject(key);
            if (cahcedObject == null) {
                cahcedObject = super.getBodyContent();
                cacheManager.setObject(key, cahcedObject, refreshPeriod);
            }
            cahcedObject.fill(this.bw);
        }
        return;
    } catch (IOException ex) {
        if (!ctx.gt.getConf().isIgnoreClientIOError()) {
            throw new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, "IO Error", ex);
        }
    }
}
Also used : BodyContent(org.beetl.core.BodyContent) BeetlException(org.beetl.core.exception.BeetlException) IOException(java.io.IOException)

Example 3 with BodyContent

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

the class LayoutTag method render.

@Override
public void render() {
    if (args.length == 0 || args.length > 3) {
        throw new RuntimeException("参数错误,期望child,map");
    }
    String layoutFile = getRelResourceId();
    Template t = this.gt.getTemplate(layoutFile, this.ctx.getResourceId());
    t.binding(ctx.globalVar);
    t.dynamic(ctx.objectKeys);
    if (args.length >= 2) {
        Map<String, Object> map = (Map<String, Object>) args[1];
        for (Entry<String, Object> entry : map.entrySet()) {
            t.binding(entry.getKey(), entry.getValue());
        }
    }
    BodyContent content = this.getBodyContent();
    if (args.length == 3) {
        t.binding((String) args[2], content);
    } else {
        t.binding(defaultLayoutName, content);
    }
    t.renderTo(ctx.byteWriter);
}
Also used : BodyContent(org.beetl.core.BodyContent) Map(java.util.Map) Template(org.beetl.core.Template)

Aggregations

BodyContent (org.beetl.core.BodyContent)3 Map (java.util.Map)2 Template (org.beetl.core.Template)2 IOException (java.io.IOException)1 BeetlException (org.beetl.core.exception.BeetlException)1