Java Code Examples for com.jfinal.template.io.Writer#write()

The following examples show how to use com.jfinal.template.io.Writer#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParaDirective.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    Controller controller = JbootControllerContext.get();

    String key = getPara(0, scope);
    String defaultValue = getPara(1, scope);

    if (StrUtil.isBlank(key)) {
        throw new IllegalArgumentException("#para(...) argument must not be empty" + getLocation());
    }

    String value = controller.getPara(key);
    if (StrUtil.isBlank(value)) {
        value = StrUtil.isNotBlank(defaultValue) ? defaultValue : "";
    }

    try {
        writer.write(value);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: MaxLengthDirective.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {
    String content = getPara(0, scope);
    if (StrUtil.isBlank(content)) {
        return;
    }

    int maxLength = getParaToInt(1, scope, 0);
    if (maxLength <= 0) {
        throw new IllegalArgumentException("#maxLength(content,length) 参数错误,length必须大于0 " + getLocation());
    }

    String suffix = getPara(2, scope);
    try {
        writer.write(CommonsUtils.maxLength(content, maxLength, suffix));
    } catch (IOException e) {
        throw new TemplateException(e.getMessage(), location, e);
    }
}
 
Example 3
Source File: OptionDirective.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    String key = getPara(0, scope);
    if (StrUtil.isBlank(key)) {
        throw new IllegalArgumentException("#option(...) argument must not be empty " + getLocation());
    }

    String defaultValue = getPara(1, scope, "");

    String value = JPressOptions.get(key);
    if (value == null || value == "") {
        value = defaultValue;
    }

    try {
        writer.write(value);
    } catch (IOException e) {
        throw new TemplateException(e.getMessage(), location, e);
    }
}
 
Example 4
Source File: JbootDirectiveBase.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void renderText(Writer writer, String text) {
    try {
        writer.write(text);
    } catch (IOException e) {
        throw new TemplateException(e.getMessage(), location, e);
    }
}