public Object getValue(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException { if (context == null) { throw new NullPointerException(); } if (base == null) { context.setPropertyResolved(true); if (property != null) { try { return this.variableResolver.resolveVariable(property .toString()); } catch (javax.servlet.jsp.el.ELException e) { throw new ELException(e.getMessage(), e.getCause()); } } } if (!context.isPropertyResolved()) { return getDefaultResolver().getValue(context, base, property); } return null; }
@SuppressWarnings("unchecked") public static final Enum<?> coerceToEnum(final Object obj, @SuppressWarnings("rawtypes") Class type) { if (obj == null || "".equals(obj)) { return null; } if (type.isAssignableFrom(obj.getClass())) { return (Enum<?>) obj; } if (!(obj instanceof String)) { throw new ELException(MessageFactory.get("error.convert", obj, obj.getClass(), type)); } Enum<?> result; try { result = Enum.valueOf(type, (String) obj); } catch (IllegalArgumentException iae) { throw new ELException(MessageFactory.get("error.convert", obj, obj.getClass(), type)); } return result; }
@Override public boolean isReadOnly(EvaluationContext ctx) throws ELException { VariableMapper varMapper = ctx.getVariableMapper(); if (varMapper != null) { ValueExpression expr = varMapper.resolveVariable(this.image); if (expr != null) { return expr.isReadOnly(ctx.getELContext()); } } ctx.setPropertyResolved(false); boolean result = ctx.getELResolver().isReadOnly(ctx, null, this.image); if (!ctx.isPropertyResolved()) { throw new PropertyNotFoundException(MessageFactory.get("error.resolver.unhandled.null", this.image)); } return result; }
@Override public boolean isReadOnly(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException { if (context == null) { throw new NullPointerException(); } if (base == null && property != null) { int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString()); if (idx >= 0) { context.setPropertyResolved(true); return true; } } return false; }
@Override public Object getValue(EvaluationContext ctx) throws ELException { Object obj = this.children[0].getValue(ctx); if (obj == null) { return Boolean.TRUE; } else if (obj instanceof String) { return Boolean.valueOf(((String) obj).length() == 0); } else if (obj instanceof Object[]) { return Boolean.valueOf(((Object[]) obj).length == 0); } else if (obj instanceof Collection<?>) { return Boolean.valueOf(((Collection<?>) obj).isEmpty()); } else if (obj instanceof Map<?,?>) { return Boolean.valueOf(((Map<?,?>) obj).isEmpty()); } return Boolean.FALSE; }
@Override public void setValue(EvaluationContext ctx, Object value) throws ELException { VariableMapper varMapper = ctx.getVariableMapper(); if (varMapper != null) { ValueExpression expr = varMapper.resolveVariable(this.image); if (expr != null) { expr.setValue(ctx.getELContext(), value); return; } } ctx.setPropertyResolved(false); ctx.getELResolver().setValue(ctx, null, this.image, value); if (!ctx.isPropertyResolved()) { throw new PropertyNotFoundException(MessageFactory.get( "error.resolver.unhandled.null", this.image)); } }
public MethodExpression createMethodExpression(Class<?> expectedReturnType, Class<?>[] expectedParamTypes) throws ELException { Node n = this.build(); if (!n.isParametersProvided() && expectedParamTypes == null) { throw new NullPointerException(MessageFactory .get("error.method.nullParms")); } if (n instanceof AstValue || n instanceof AstIdentifier) { return new MethodExpressionImpl(expression, n, this.fnMapper, this.varMapper, expectedReturnType, expectedParamTypes); } else if (n instanceof AstLiteralExpression) { return new MethodExpressionLiteral(expression, expectedReturnType, expectedParamTypes); } else { throw new ELException("Not a Valid Method Expression: " + expression); } }
public static final Character coerceToCharacter(final Object obj) throws ELException { if (obj == null || "".equals(obj)) { return Character.valueOf((char) 0); } if (obj instanceof String) { return Character.valueOf(((String) obj).charAt(0)); } if (ELArithmetic.isNumber(obj)) { return Character.valueOf((char) ((Number) obj).shortValue()); } Class<?> objType = obj.getClass(); if (obj instanceof Character) { return (Character) obj; } throw new ELException(MessageFactory.get("error.convert", obj, objType, Character.class)); }
@Test public void testJavaKeyWordIdentifier() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); TesterBeanA beanA = new TesterBeanA(); beanA.setInt("five"); ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class); context.getVariableMapper().setVariable("this", var); // Should fail Exception e = null; try { factory.createValueExpression(context, "${this}", String.class); } catch (ELException ele) { e = ele; } assertNotNull(e); }
/** * */ public ExpressionBuilder(String expression, ELContext ctx) throws ELException { this.expression = expression; FunctionMapper ctxFn = ctx.getFunctionMapper(); VariableMapper ctxVar = ctx.getVariableMapper(); if (ctxFn != null) { this.fnMapper = new FunctionMapperFactory(ctxFn); } if (ctxVar != null) { this.varMapper = new VariableMapperFactory(ctxVar); } }
public Class<?> getType(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException { if (context == null) { throw new NullPointerException(); } if (base == null) { context.setPropertyResolved(true); if (property != null) { try { Object obj = this.variableResolver.resolveVariable(property .toString()); return (obj != null) ? obj.getClass() : null; } catch (javax.servlet.jsp.el.ELException e) { throw new ELException(e.getMessage(), e.getCause()); } } } if (!context.isPropertyResolved()) { return getDefaultResolver().getType(context, base, property); } return null; }
@Override public Class<?> getType(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException { if (context == null) { throw new NullPointerException(); } if (base == null) { context.setPropertyResolved(true); if (property != null) { try { Object obj = this.variableResolver.resolveVariable(property.toString()); return (obj != null) ? obj.getClass() : null; } catch (javax.servlet.jsp.el.ELException e) { throw new ELException(e.getMessage(), e.getCause()); } } } if (!context.isPropertyResolved()) { return elResolver.getType(context, base, property); } return null; }
private void prepare(Node node) throws ELException { try { node.accept(this); } catch (Exception e) { if (e instanceof ELException) { throw (ELException) e; } else { throw (new ELException(e)); } } if (this.fnMapper instanceof FunctionMapperFactory) { this.fnMapper = ((FunctionMapperFactory) this.fnMapper).create(); } if (this.varMapper instanceof VariableMapperFactory) { this.varMapper = ((VariableMapperFactory) this.varMapper).create(); } }
@Override public void setValue(ELContext context, Object base, Object property, Object value) throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException { if (context == null) { throw new NullPointerException(); } if (base == null) { context.setPropertyResolved(true); if (property != null) { String key = property.toString(); PageContext page = (PageContext) context .getContext(JspContext.class); int scope = page.getAttributesScope(key); if (scope != 0) { page.setAttribute(key, value, scope); } else { page.setAttribute(key, value); } } } }
@Override public Object getValue(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException { if (context == null) { throw new NullPointerException(); } if (base == null) { context.setPropertyResolved(true); if (property != null) { String key = property.toString(); PageContext page = (PageContext) context .getContext(JspContext.class); return page.findAttribute(key); } } return null; }
public Object getValue(EvaluationContext ctx) throws ELException { Object base = this.children[0].getValue(ctx); int propCount = this.jjtGetNumChildren(); int i = 1; Object property = null; ELResolver resolver = ctx.getELResolver(); while (base != null && i < propCount) { property = this.children[i].getValue(ctx); if (property == null) { return null; } else { ctx.setPropertyResolved(false); base = resolver.getValue(ctx, base, property); } i++; } return base; }
@Override public Object getValue(ELContext elContext, Object base, Object property) throws ELException { if (base != null) { if (base instanceof WebApplicationContext) { WebApplicationContext wac = (WebApplicationContext) base; String beanName = property.toString(); if (logger.isTraceEnabled()) { logger.trace("Attempting to resolve property '" + beanName + "' in root WebApplicationContext"); } if (wac.containsBean(beanName)) { if (logger.isDebugEnabled()) { logger.debug("Successfully resolved property '" + beanName + "' in root WebApplicationContext"); } elContext.setPropertyResolved(true); try { return wac.getBean(beanName); } catch (BeansException ex) { throw new ELException(ex); } } else { // Mimic standard JSF/JSP behavior when base is a Map by returning null. return null; } } } else { if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) { elContext.setPropertyResolved(true); return getWebApplicationContext(elContext); } } return null; }
@Override public Object getValue(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException { context.setPropertyResolved(false); int start; Object result = null; if (base == null) { // call implicit and app resolvers int index = 1 /* implicit */ + appResolversSize; for (int i = 0; i < index; i++) { result = resolvers[i].getValue(context, base, property); if (context.isPropertyResolved()) { return result; } } // skip collection-based resolvers (map, resource, list, array, and // bean) start = index + 5; } else { // skip implicit resolver only start = 1; } for (int i = start; i < size; i++) { result = resolvers[i].getValue(context, base, property); if (context.isPropertyResolved()) { return result; } } return null; }
public Object getValue(EvaluationContext ctx) throws ELException { VariableMapper varMapper = ctx.getVariableMapper(); if (varMapper != null) { ValueExpression expr = varMapper.resolveVariable(this.image); if (expr != null) { return expr.getValue(ctx.getELContext()); } } ctx.setPropertyResolved(false); return ctx.getELResolver().getValue(ctx, null, this.image); }
/** * @param obj0 * @param obj1 * @return * @throws EvaluationException */ public final static int compare(final Object obj0, final Object obj1) throws ELException { if (obj0 == obj1 || equals(obj0, obj1)) { return 0; } if (isBigDecimalOp(obj0, obj1)) { BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class); BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class); return bd0.compareTo(bd1); } if (isDoubleOp(obj0, obj1)) { Double d0 = (Double) coerceToNumber(obj0, Double.class); Double d1 = (Double) coerceToNumber(obj1, Double.class); return d0.compareTo(d1); } if (isBigIntegerOp(obj0, obj1)) { BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class); BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class); return bi0.compareTo(bi1); } if (isLongOp(obj0, obj1)) { Long l0 = (Long) coerceToNumber(obj0, Long.class); Long l1 = (Long) coerceToNumber(obj1, Long.class); return l0.compareTo(l1); } if (obj0 instanceof String || obj1 instanceof String) { return coerceToString(obj0).compareTo(coerceToString(obj1)); } if (obj0 instanceof Comparable) { return (obj1 != null) ? ((Comparable) obj0).compareTo(obj1) : 1; } if (obj1 instanceof Comparable) { return (obj0 != null) ? -((Comparable) obj1).compareTo(obj0) : -1; } throw new ELException(MessageFactory.get("error.compare", obj0, obj1)); }
@Override public Class<?> getType(ELContext elContext, Object base, Object property) throws ELException { if (base == null) { String beanName = property.toString(); BeanFactory bf = getBeanFactory(elContext); if (bf.containsBean(beanName)) { elContext.setPropertyResolved(true); return bf.getType(beanName); } } return null; }
public Object getValue(EvaluationContext ctx) throws ELException { Object obj = this.children[0].getValue(ctx); if (obj == null) { return new Long(0); } if (obj instanceof BigDecimal) { return ((BigDecimal) obj).negate(); } if (obj instanceof BigInteger) { return ((BigInteger) obj).negate(); } if (obj instanceof String) { if (isStringFloat((String) obj)) { return new Double(-Double.parseDouble((String) obj)); } return new Long(-Long.parseLong((String) obj)); } if (obj instanceof Long) { return new Long(-((Long) obj).longValue()); } if (obj instanceof Double) { return new Double(-((Double) obj).doubleValue()); } if (obj instanceof Integer) { return new Integer(-((Integer) obj).intValue()); } if (obj instanceof Float) { return new Float(-((Float) obj).floatValue()); } if (obj instanceof Short) { return new Short((short) -((Short) obj).shortValue()); } if (obj instanceof Byte) { return new Byte((byte) -((Byte) obj).byteValue()); } Long num = (Long) coerceToNumber(obj, Long.class); return new Long(-num.longValue()); }
@Override public void setImage(String image) { if (!Validation.isIdentifier(image)) { throw new ELException(MessageFactory.get("error.identifier.notjava", image)); } this.image = image; }
@Override public Object getValue(EvaluationContext ctx) throws ELException { Object obj0 = this.children[0].getValue(ctx); Object obj1 = this.children[1].getValue(ctx); return ELArithmetic.add(obj0, obj1); }
public final static void throwUnhandled(Object base, Object property) throws ELException { if (base == null) { throw new PropertyNotFoundException(MessageFactory.get( "error.resolver.unhandled.null", property)); } else { throw new PropertyNotFoundException(MessageFactory.get( "error.resolver.unhandled", base.getClass(), property)); } }
@Override public Class<Object> getType(ELContext context, Object base, Object property) throws NullPointerException, PropertyNotFoundException, ELException { if (context == null) { throw new NullPointerException(); } if (base == null) { context.setPropertyResolved(true); return Object.class; } return null; }
@Override public Object getValue(EvaluationContext ctx) throws ELException { Object obj0 = this.children[0].getValue(ctx); Object obj1 = this.children[1].getValue(ctx); return ELArithmetic.subtract(obj0, obj1); }
/** * Allow node to validate itself * * @param ef * @param ctx * @throws ELException */ public void validateEL(ExpressionFactory ef, ELContext ctx) throws ELException { if (this.el != null) { // determine exact type ef.createValueExpression(ctx, this.value, String.class); } }
@Override public Object getValue(ELContext context) throws PropertyNotFoundException, ELException { EvaluationContext ctx = new EvaluationContext(context, this.fnMapper, this.varMapper); Object value = this.getNode().getValue(ctx); if (this.expectedType != null) { return ELSupport.coerceToType(value, this.expectedType); } return value; }
public Object invoke(FacesContext facesContext, Object[] params) { try { return _me.invoke(facesContext.getELContext(), params); } // Convert EL exceptions into EvaluationExceptions catch (ELException ee) { throw new EvaluationException(ee.getMessage(), ee.getCause()); } }
public boolean isReadOnly(EvaluationContext ctx) throws ELException { VariableMapper varMapper = ctx.getVariableMapper(); if (varMapper != null) { ValueExpression expr = varMapper.resolveVariable(this.image); if (expr != null) { return expr.isReadOnly(ctx.getELContext()); } } ctx.setPropertyResolved(false); return ctx.getELResolver().isReadOnly(ctx, null, this.image); }
@Override public Object getValue(EvaluationContext ctx) throws ELException { Object obj0 = this.children[0].getValue(ctx); if (obj0 == null) { return Boolean.FALSE; } Object obj1 = this.children[1].getValue(ctx); if (obj1 == null) { return Boolean.FALSE; } return (compare(obj0, obj1) > 0) ? Boolean.TRUE : Boolean.FALSE; }
@Override public Object getValue(EvaluationContext ctx) throws ELException { Object obj = this.children[0].getValue(ctx); if (obj == null) { return Long.valueOf(0); } if (obj instanceof BigDecimal) { return ((BigDecimal) obj).negate(); } if (obj instanceof BigInteger) { return ((BigInteger) obj).negate(); } if (obj instanceof String) { if (isStringFloat((String) obj)) { return new Double(-Double.parseDouble((String) obj)); } return Long.valueOf(-Long.parseLong((String) obj)); } if (obj instanceof Long) { return Long.valueOf(-((Long) obj).longValue()); } if (obj instanceof Double) { return new Double(-((Double) obj).doubleValue()); } if (obj instanceof Integer) { return Integer.valueOf(-((Integer) obj).intValue()); } if (obj instanceof Float) { return new Float(-((Float) obj).floatValue()); } if (obj instanceof Short) { return Short.valueOf((short) -((Short) obj).shortValue()); } if (obj instanceof Byte) { return Byte.valueOf((byte) -((Byte) obj).byteValue()); } Long num = (Long) coerceToNumber(obj, Long.class); return Long.valueOf(-num.longValue()); }
public Object getValue(EvaluationContext ctx) throws ELException { Object obj0 = this.children[0].getValue(ctx); Object obj1 = this.children[1].getValue(ctx); if (obj0 == obj1) { return Boolean.TRUE; } if (obj0 == null || obj1 == null) { return Boolean.FALSE; } return (compare(obj0, obj1) >= 0) ? Boolean.TRUE : Boolean.FALSE; }
private Node build() throws ELException { Node n = createNodeInternal(this.expression); this.prepare(n); if (n instanceof AstDeferredExpression || n instanceof AstDynamicExpression) { n = n.jjtGetChild(0); } return n; }
@Override public Object getValue(EvaluationContext ctx) throws ELException { Object obj0 = this.children[0].getValue(ctx); Boolean b0 = coerceToBoolean(obj0); return this.children[((b0.booleanValue() ? 1 : 2))].getValue(ctx); }
@Override public boolean isReadOnly(EvaluationContext ctx) throws ELException { Target t = getTarget(ctx); ctx.setPropertyResolved(false); boolean result = ctx.getELResolver().isReadOnly(ctx, t.base, t.property); if (!ctx.isPropertyResolved()) { throw new PropertyNotFoundException(MessageFactory.get( "error.resolver.unhandled", t.base, t.property)); } return result; }