public int asInt(ExpressionContext context) throws ExpressionEvaluationException { try { Map<String, Object> globals = context.asMap(); return (Integer) Ognl.getValue(parsedExpression, globals, globals, Integer.class); } catch (OgnlException e) { throw new ExpressionEvaluationException("Error evaluating expression: " + expression, e); } }
Form form = (Form) f; Object t = bindings.get(Expressions.CURRENT_OBJECT); Super ts = (Super) bindings.get(Expressions.PARENT_OBJECT); Iter iter = (Iter) bindings.get(Expressions.ITER_OBJECT); bindings.put(Expressions.PARENT_OBJECT, s); bindings.put(Expressions.CURRENT_OBJECT, form); super.execute(bindings, out); bindings.put(Expressions.CURRENT_OBJECT, s.get()); bindings.put(Expressions.PARENT_OBJECT, s.getSuper()); bindings.put(Expressions.ITER_OBJECT, s.getIter()); } else { bindings.put(Expressions.CURRENT_OBJECT, t); bindings.put(Expressions.PARENT_OBJECT, ts); bindings.put(Expressions.ITER_OBJECT, iter);
private void compileExpressionEvaluator(ExpressionContext context) throws Scanner.ScanException, CompileException, Parser.ParseException { if (context.has(expression)) { isValue=true; Map<String, Object> globals = context.asMap(); parameterNames = new String[globals.size()]; parameterTypes = new Class[globals.size()];
public void setProperty(String name, Object property) { context.put(name, property); }
public static Locale getLocaleFromBindings(ExpressionContext context) { Locale locale = (Locale) context.get(LocaleVariable); if (locale == null) { locale = Locale.getDefault(); } return locale; } }
@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 setAllProperties(Map<String, Object> properties) { context.setVariables(properties); }
private void iterateIterable(ExpressionContext context, TagNode tag, Writer out, Iterable<Object> o) throws IOException, TemplateEvaluationException { Iter iter = new Iter(); context.put(getIterObjectName(), iter); Iterator<?> it = o.iterator(); while (it.hasNext()) { Object o1 = it.next(); if (!it.hasNext()) { iter.setLast(); } context.put(getCurrentObjectName(), o1); tag.execute(context, out); iter.next(); } }
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 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); } }
public boolean asBoolean(ExpressionContext context) throws ExpressionEvaluationException { try { Map<String, Object> globals = context.asMap(); return (Boolean) Ognl.getValue(parsedExpression, globals, globals, Boolean.class); } catch (OgnlException e) { throw new ExpressionEvaluationException("Error evaluating expression: " + expression, e); } }
private void iterateInt(ExpressionContext context, TagNode tag, Writer out, int[] o) throws IOException, TemplateEvaluationException { Iter iter = new Iter(); context.put(getIterObjectName(), iter); for (int i=0; i<o.length; i++) { if (i == o.length-1) iter.setLast(); context.put(getCurrentObjectName(), o[i]); tag.execute(context, out); iter.next(); } }
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); } }
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 float asFloat(ExpressionContext context) throws ExpressionEvaluationException { try { Map<String, Object> globals = context.asMap(); return (Float) Ognl.getValue(parsedExpression, globals, globals, Float.class); } catch (OgnlException e) { throw new ExpressionEvaluationException("Error evaluating expression: " + expression, e); } }
private void iterateArray(ExpressionContext context, TagNode tag, Writer out, Object[] o) throws IOException, TemplateEvaluationException { Iter iter = new Iter(); context.put(getIterObjectName(), iter); for (int i=0; i<o.length; i++) { if (i == o.length-1) iter.setLast(); context.put(getCurrentObjectName(), o[i]); tag.execute(context, out); iter.next(); } }
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 double asDouble(ExpressionContext context) throws ExpressionEvaluationException { try { Map<String, Object> globals = context.asMap(); return (Double) Ognl.getValue(parsedExpression, globals, globals, Double.class); } catch (OgnlException e) { throw new ExpressionEvaluationException("Error evaluating expression: " + expression, e); } }
private void iterateDouble(ExpressionContext context, TagNode tag, Writer out, double[] o) throws IOException, TemplateEvaluationException { Iter iter = new Iter(); context.put(getIterObjectName(), iter); for (int i=0; i<o.length; i++) { if (i == o.length-1) iter.setLast(); context.put(getCurrentObjectName(), o[i]); tag.execute(context, out); iter.next(); } }