@Override public Object eval(ExpressionContext context, CambridgeExpression[] params) throws ExpressionEvaluationException { try { ResourceBundle bundle = ResourceBundle.getBundle("Cambridge", context.getLocale()); if (params == null || params.length == 0) { return ""; } if (params.length == 1) { return bundle.getString(params[0].asString(context)); } else { String message = bundle.getString(params[0].asString(context)); Object[] messageParams = new Object[params.length - 1]; for (int i = 1; i < params.length; i++) { messageParams[i - 1] = params[i].eval(context); } return MessageFormat.format(message, messageParams); } } catch (MissingResourceException e) { return ""; } } }
public void eval(ExpressionContext context, Writer out) throws IOException, TemplateEvaluationException { try { Object value = expression.eval(context); if (value != null) { String str = applyFilters(value, context.getLocale()); if (raw) { out.write(str); } else { out.write(EscapeFilter.doFilter(str)); } } } catch (ExpressionEvaluationException e) { throw new TemplateEvaluationException(e, "Could not execute the expression: " + e.getMessage() + ", on line: " + getBeginLine() + ", column: " + getBeginColumn(), getBeginLine(), getBeginColumn(), value); } }