public static Locale getLocaleFromBindings(ExpressionContext context) { Locale locale = (Locale) context.get(LocaleVariable); if (locale == null) { locale = Locale.getDefault(); } return locale; } }
private Object[] getArguments(ExpressionContext context) { Object[] arguments = new Object[parameterNames.length]; for (int i = 0; i < parameterNames.length; i++) { String name = parameterNames[i]; Object argument = context.get(name); if (argument != null) { if (!parameterTypes[i].isAssignableFrom(argument.getClass())) { if (PRINT_ERRORS) System.err.println("Wrong argument type passed for " + parameterNames[i] + ". Expecting " + parameterTypes[i].getName() + " but got " + argument.getClass().getName()); } } arguments[i] = argument; } return arguments; }
public Object eval(ExpressionContext context) throws ExpressionEvaluationException { if (properties == null) { return context.get(varName); } PropertyUtils utils = PropertyUtils.instance(); Object object = context.get(varName); if (object == null) { return null; } for (VarProperty property : properties) { if (property instanceof IdentifierVarProperty) { IdentifierVarProperty id = (IdentifierVarProperty) property; try { object = utils.getBeanProperty(object, id.name); } catch (PropertyAccessException e) { throw new ExpressionEvaluationException(e); } } else { MapVarProperty m = (MapVarProperty) property; if (object instanceof Map) { object = ((Map<?,?>) object).get(m.expression.eval(context)); } else if (object instanceof List) { object = ((List<?>) object).get(m.expression.asInt(context)); } else if (object instanceof Object[]) { object = ((Object[]) object)[m.expression.asInt(context)]; } } } return object; }
public Object eval(ExpressionContext context) throws ExpressionEvaluationException { try { if (expressionEvaluator == null && isValue == null) compileExpressionEvaluator(context); // don't bother compiling expressions when returning values if (isValue) return context.get(expression); return expressionEvaluator.evaluate(getArguments(context)); } catch (Exception e) { throw new ExpressionEvaluationException(getErrorMsg(), e); } }
public void eval(ExpressionContext context, Writer out) throws IOException, TemplateEvaluationException { try { Object value = expression.eval(context); if (value != null) { Locale locale = (Locale) context.get(DefaultTemplateBindings.LocaleVariable); if (locale == null) { locale = Locale.getDefault(); } String str = applyFilters(value, locale); 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: " + getLine() + ", column: " + getColumn(), getLine(), getColumn()); } }
public final void execute(ExpressionContext context, TagNode tag, Writer out) throws TemplateEvaluationException, IOException { Object t = context.get(getCurrentObjectName()); Super ts = (Super) context.get(getParentObjectName()); Iter iter = (Iter) context.get(getIterObjectName()); Super s = null; if (t != null) { s = new Super(t, ts, iter); context.put(getParentObjectName(), s); } doExecute(context, tag, out); if (t != null) { context.put(getCurrentObjectName(), s.get()); context.put(getParentObjectName(), s.getSuper()); context.put(getIterObjectName(), s.getIter()); } else { context.put(getCurrentObjectName(), t); context.put(getParentObjectName(), ts); context.put(getIterObjectName(), iter); } }