Search in sources :

Example 1 with Format

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

the class FormatExpression method evaluateValue.

public Object evaluateValue(Object o, Context ctx) {
    Format format = null;
    if (name != null) {
        format = ctx.gt.getFormat(name);
    } else {
        if (o == null)
            return null;
        format = ctx.gt.getDefaultFormat(o.getClass());
    }
    if (format == null) {
        BeetlException ex = new BeetlException(BeetlException.FORMAT_NOT_FOUND);
        ex.pushToken(token);
        throw ex;
    }
    try {
        if (format instanceof ContextFormat) {
            return ((ContextFormat) format).format(o, pattern, ctx);
        } else {
            return format.format(o, pattern);
        }
    } catch (Exception e) {
        BeetlException ex = new BeetlException(BeetlException.NATIVE_CALL_EXCEPTION, "调用格式化函数抛出异常", e);
        ex.pushToken(token);
        throw ex;
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) Format(org.beetl.core.Format) ContextFormat(org.beetl.core.ContextFormat) ContextFormat(org.beetl.core.ContextFormat) BeetlException(org.beetl.core.exception.BeetlException)

Aggregations

ContextFormat (org.beetl.core.ContextFormat)1 Format (org.beetl.core.Format)1 BeetlException (org.beetl.core.exception.BeetlException)1