javax.el.ELException Java Examples

The following examples show how to use javax.el.ELException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AstValue.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    Target t = getTarget(ctx);
    ctx.setPropertyResolved(false);
    ELResolver resolver = ctx.getELResolver();

    // coerce to the expected type
    Class<?> targetClass = resolver.getType(ctx, t.base, t.property);
    if (COERCE_TO_ZERO == true
            || !isAssignable(value, targetClass)) {
        resolver.setValue(ctx, t.base, t.property,
                ELSupport.coerceToType(value, targetClass));
    } else {
        resolver.setValue(ctx, t.base, t.property, value);
    }
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled", t.base, t.property));            
    }
}
 
Example #2
Source File: AstIdentifier.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getType(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example #3
Source File: ImplicitObjectELResolver.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@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 && property != null) {
        int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());
        if (idx >= 0) {
            context.setPropertyResolved(true);
            throw new PropertyNotWritableException();
        }
    }
}
 
Example #4
Source File: ScopedAttributeELResolver.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: AstEmpty.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: JuelExpression.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Object getValue(VariableScope variableScope) {
  ELContext elContext = Context.getProcessEngineConfiguration().getExpressionManager().getElContext(variableScope);
  try {
    ExpressionGetInvocation invocation = new ExpressionGetInvocation(valueExpression, elContext);
    Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(invocation);
    return invocation.getInvocationResult();
  } catch (PropertyNotFoundException pnfe) {
    throw new ActivitiException("Unknown property used in expression: " + expressionText, pnfe);
  } catch (MethodNotFoundException mnfe) {
    throw new ActivitiException("Unknown method used in expression: " + expressionText, mnfe);
  } catch (ELException ele) {
    throw new ActivitiException("Error while evaluating expression: " + expressionText, ele);
  } catch (Exception e) {
    throw new ActivitiException("Error while evaluating expression: " + expressionText, e);
  }
}
 
Example #7
Source File: TestELParser.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testJavaKeyWordSuffix() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);

    TesterBeanA beanA = new TesterBeanA();
    beanA.setInt("five");
    ValueExpression var =
        factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);

    // Should fail
    Exception e = null;
    try {
        factory.createValueExpression(context, "${beanA.int}",
                String.class);
    } catch (ELException ele) {
        e = ele;
    }
    Assert.assertNotNull(e);
}
 
Example #8
Source File: ELResolverImpl.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@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) {
            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 elResolver.getValue(context, base, property);
    }
    return null;
}
 
Example #9
Source File: ELResolverImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public Object getValue(ELContext context, Object base, Object property) {
    Objects.requireNonNull(context);

    if (base == null) {
        context.setPropertyResolved(base, property);
        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 elResolver.getValue(context, base, property);
    }
    return null;
}
 
Example #10
Source File: ELSupport.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #11
Source File: ScopedAttributeELResolver.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@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);
            }
        }
    }
}
 
Example #12
Source File: AbstractResolver.java    From gazpachoquest with GNU General Public License v3.0 6 votes vote down vote up
protected boolean isRevealed(String relevance, Map<String, Object> answers) {
    if (StringUtils.isBlank(relevance)) {
        return true;
    }
    SimpleContext context = new SimpleContext();
    for (Entry<String, Object> answer : answers.entrySet()) {
        String code = answer.getKey();
        Object value = answer.getValue();
        if (value != null) {
            context.setVariable(code, elFactory.createValueExpression(value, value.getClass()));
        }
    }
    Boolean revealed = false;
    try {
        // Evaluate the condition
        revealed = (Boolean) elFactory.createValueExpression(context, relevance, Boolean.class).getValue(context);
    } catch (ELException e) {
        logger.warn("Errors found in evaluating the relevance condition", e);
    }
    return revealed;
}
 
Example #13
Source File: AstEmpty.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #14
Source File: AstMod.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public Object getValue(EvaluationContext ctx)
        throws ELException {
    Object obj0 = this.children[0].getValue(ctx);
    Object obj1 = this.children[1].getValue(ctx);
    return ELArithmetic.mod(obj0, obj1);
}
 
Example #15
Source File: WebApplicationContextFacesELResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean isReadOnly(ELContext elContext, Object base, Object property) throws ELException {
	if (base instanceof WebApplicationContext) {
		elContext.setPropertyResolved(true);
		return true;
	}
	return false;
}
 
Example #16
Source File: WebApplicationContextFacesELResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean isReadOnly(ELContext elContext, Object base, Object property) throws ELException {
	if (base instanceof WebApplicationContext) {
		elContext.setPropertyResolved(true);
		return true;
	}
	return false;
}
 
Example #17
Source File: FeelEngineFactoryImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ExpressionFactory createExpressionFactory() {
  Properties properties = new Properties();
  properties.put(ExpressionFactoryImpl.PROP_CACHE_SIZE, String.valueOf(expressionCacheSize));

  try {
    return new ExpressionFactoryImpl(properties, createTypeConverter());
  }
  catch (ELException e) {
    throw LOG.unableToInitializeFeelEngine(e);
  }
}
 
Example #18
Source File: AstEqual.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public Object getValue(EvaluationContext ctx)
        throws ELException {
    Object obj0 = this.children[0].getValue(ctx);
    Object obj1 = this.children[1].getValue(ctx);
    return Boolean.valueOf(equals(ctx, obj0, obj1));
}
 
Example #19
Source File: ValueExpressionImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #20
Source File: ELSupport.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Compare two objects for equality, after coercing to the same type if appropriate.
 * 
 * If the objects are identical (including both null) return true.
 * If either object is null, return false.
 * If either object is Boolean, coerce both to Boolean and check equality.
 * Similarly for Enum, String, BigDecimal, Double(Float), Long(Integer, Short, Byte, Character)
 * Otherwise default to using Object.equals().
 * 
 * @param obj0 the first object
 * @param obj1 the second object
 * @return true if the objects are equal
 * @throws ELException
 */
public static final boolean equals(final Object obj0, final Object obj1)
        throws ELException {
    if (obj0 == obj1) {
        return true;
    } else if (obj0 == null || obj1 == null) {
        return false;
    } else if (isBigDecimalOp(obj0, obj1)) {
        BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class);
        BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class);
        return bd0.equals(bd1);
    } else if (isDoubleOp(obj0, obj1)) {
        Double d0 = (Double) coerceToNumber(obj0, Double.class);
        Double d1 = (Double) coerceToNumber(obj1, Double.class);
        return d0.equals(d1);
    } else if (isBigIntegerOp(obj0, obj1)) {
        BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class);
        BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class);
        return bi0.equals(bi1);
    } else         if (isLongOp(obj0, obj1)) {
        Long l0 = (Long) coerceToNumber(obj0, Long.class);
        Long l1 = (Long) coerceToNumber(obj1, Long.class);
        return l0.equals(l1);
    } else if (obj0 instanceof Boolean || obj1 instanceof Boolean) {
        return coerceToBoolean(obj0).equals(coerceToBoolean(obj1));
    } else if (obj0.getClass().isEnum()) {
        return obj0.equals(coerceToEnum(obj1, obj0.getClass()));
    } else if (obj1.getClass().isEnum()) {
        return obj1.equals(coerceToEnum(obj0, obj1.getClass()));
    } else if (obj0 instanceof String || obj1 instanceof String) {
        int lexCompare = coerceToString(obj0).compareTo(coerceToString(obj1));
        return (lexCompare == 0) ? true : false;
    } else {
        return obj0.equals(obj1);
    }
}
 
Example #21
Source File: AstLessThanEqual.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
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;
}
 
Example #22
Source File: ELParser.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public static Node parse(String ref) throws ELException
{
    try {
        return (new ELParser(new StringReader(ref))).CompositeExpression();
    } catch (ParseException pe) {
        throw new ELException(pe.getMessage());
    }
}
 
Example #23
Source File: NamedParameterOperator.java    From jinjava with Apache License 2.0 5 votes vote down vote up
@Override
public AstNode createAstNode(AstNode... children) {
  if (!(children[0] instanceof AstIdentifier)) {
    throw new ELException("Expected IDENTIFIER, found " + children[0].toString());
  }
  AstIdentifier name = (AstIdentifier) children[0];
  return new AstNamedParameter(name, children[1]);
}
 
Example #24
Source File: FeelEngineImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ValueExpression transformSimpleUnaryTests(String simpleUnaryTests, String inputName, ELContext elContext) {

    String juelExpression = transformToJuelExpression(simpleUnaryTests, inputName);

    try {
      return expressionFactory.createValueExpression(elContext, juelExpression, Object.class);
    }
    catch (ELException e) {
      throw LOG.invalidExpression(simpleUnaryTests, e);
    }
  }
 
Example #25
Source File: AstNotEqual.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public Object getValue(EvaluationContext ctx)
        throws ELException {
    Object obj0 = this.children[0].getValue(ctx);
    Object obj1 = this.children[1].getValue(ctx);
    return Boolean.valueOf(!equals(obj0, obj1));
}
 
Example #26
Source File: AstDiv.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public Object getValue(EvaluationContext ctx)
        throws ELException {
    Object obj0 = this.children[0].getValue(ctx);
    Object obj1 = this.children[1].getValue(ctx);
    return ELArithmetic.divide(obj0, obj1);
}
 
Example #27
Source File: TestELEvaluation.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testParserStringLiteral() {
    // Inspired by work on bug 45451, comments from kkolinko on the dev
    // list and looking at the spec to find some edge cases

    // The only characters that can be escaped inside a String literal
    // are \ " and '. # and $ are not escaped inside a String literal.
    assertEquals("\\", evaluateExpression("${'\\\\'}"));
    assertEquals("\\", evaluateExpression("${\"\\\\\"}"));
    assertEquals("\\\"'$#", evaluateExpression("${'\\\\\\\"\\'$#'}"));
    assertEquals("\\\"'$#", evaluateExpression("${\"\\\\\\\"\\'$#\"}"));

    // Trying to quote # or $ should throw an error
    Exception e = null;
    try {
        evaluateExpression("${'\\$'}");
    } catch (ELException el) {
        e = el;
    }
    assertNotNull(e);

    assertEquals("\\$", evaluateExpression("${'\\\\$'}"));
    assertEquals("\\\\$", evaluateExpression("${'\\\\\\\\$'}"));


    // Can use ''' inside '"' when quoting with '"' and vice versa without
    // escaping
    assertEquals("\\\"", evaluateExpression("${'\\\\\"'}"));
    assertEquals("\"\\", evaluateExpression("${'\"\\\\'}"));
    assertEquals("\\'", evaluateExpression("${'\\\\\\''}"));
    assertEquals("'\\", evaluateExpression("${'\\'\\\\'}"));
    assertEquals("\\'", evaluateExpression("${\"\\\\'\"}"));
    assertEquals("'\\", evaluateExpression("${\"'\\\\\"}"));
    assertEquals("\\\"", evaluateExpression("${\"\\\\\\\"\"}"));
    assertEquals("\"\\", evaluateExpression("${\"\\\"\\\\\"}"));
}
 
Example #28
Source File: ELParser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void parse(Snapshot snapshot, Task task, SourceModificationEvent event) throws ParseException {
    this.result = new ELParserResult(snapshot);

   final String expressionSeparator = Constants.LANGUAGE_SNIPPET_SEPARATOR; //NOI18N
   String[] sources = snapshot.getText().toString().split(expressionSeparator); //NOI18N
   int embeddedOffset = 0;
   for (String expression : sources) {
       int startOffset = embeddedOffset;
       int endOffset = startOffset + expression.length();
       embeddedOffset += (expression.length() + expressionSeparator.length());
       
       ELPreprocessor elPreprocessor;
       //hack - we need to distinguish EL inside and outside of attribute values
       //since there's no API in parsing.api how to set some metadata to the virtual source
       //it is done this ugly way
       if(expression.endsWith(ATTRIBUTE_EL_MARKER)) {
           //inside attribute
           endOffset--;
           expression = expression.substring(0, expression.length() - 1);
           elPreprocessor = new ELPreprocessor(expression, 
                   ELPreprocessor.XML_ENTITY_REFS_CONVERSION_TABLE, 
                   ELPreprocessor.ESCAPED_CHARACTERS);
       } else {
           elPreprocessor = new ELPreprocessor(expression, 
                   ELPreprocessor.XML_ENTITY_REFS_CONVERSION_TABLE);               
       }
       OffsetRange embeddedRange = new OffsetRange(startOffset, endOffset);
       try {
           Node node = parse(elPreprocessor);
           result.addValidElement(node, elPreprocessor, embeddedRange);
       } catch (ELException ex) {
           result.addErrorElement(ex, elPreprocessor, embeddedRange);
       }
   }

}
 
Example #29
Source File: TestELSupport.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testCoerceEnumAToEnumB() {
    Object output = null;
    try {
        output = ELSupport.coerceToEnum(TestEnumA.VALA1, TestEnumB.class);
    } catch (ELException ele) {
        // Ignore
    }
    assertNull(output);
}
 
Example #30
Source File: AstDotSuffix.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void setImage(String image) {
    if (!Validation.isIdentifier(image)) {
        throw new ELException(MessageFactory.get("error.identifier.notjava",
                image));
    }
    this.image = image;
}