Search in sources :

Example 11 with ValueExpression

use of javax.el.ValueExpression in project tomcat by apache.

the class TestMethodExpressionImpl method testBug53792a.

@Test
public void testBug53792a() {
    MethodExpression me = factory.createMethodExpression(context, "${beanA.setBean(beanB)}", null, new Class<?>[] { TesterBeanB.class });
    me.invoke(context, null);
    me = factory.createMethodExpression(context, "${beanB.setName('" + BUG53792 + "')}", null, new Class<?>[] { TesterBeanB.class });
    me.invoke(context, null);
    ValueExpression ve = factory.createValueExpression(context, "#{beanA.getBean().name}", java.lang.String.class);
    String actual = (String) ve.getValue(context);
    assertEquals(BUG53792, actual);
}
Also used : ValueExpression(javax.el.ValueExpression) MethodExpression(javax.el.MethodExpression) Test(org.junit.Test)

Example 12 with ValueExpression

use of javax.el.ValueExpression in project tomcat by apache.

the class ExpressionEvaluatorImpl method parseExpression.

@Override
public Expression parseExpression(String expression, @SuppressWarnings("rawtypes") Class expectedType, FunctionMapper fMapper) throws ELException {
    try {
        ELContextImpl ctx = new ELContextImpl(ELContextImpl.getDefaultResolver(factory));
        if (fMapper != null) {
            ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
        }
        ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
        return new ExpressionImpl(ve, factory);
    } catch (javax.el.ELException e) {
        throw new ELParseException(e.getMessage());
    }
}
Also used : ValueExpression(javax.el.ValueExpression) ELParseException(javax.servlet.jsp.el.ELParseException)

Example 13 with ValueExpression

use of javax.el.ValueExpression in project tomcat by apache.

the class TestELParser method doTestBug56179.

private void doTestBug56179(int parenthesesCount, String innerExpr) {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    ValueExpression var = factory.createValueExpression(Boolean.TRUE, Boolean.class);
    context.getVariableMapper().setVariable("test", var);
    StringBuilder expr = new StringBuilder();
    expr.append("${");
    for (int i = 0; i < parenthesesCount; i++) {
        expr.append("(");
    }
    expr.append(innerExpr);
    for (int i = 0; i < parenthesesCount; i++) {
        expr.append(")");
    }
    expr.append("}");
    ValueExpression ve = factory.createValueExpression(context, expr.toString(), String.class);
    String result = (String) ve.getValue(context);
    assertEquals("true", result);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Example 14 with ValueExpression

use of javax.el.ValueExpression in project tomcat by apache.

the class TestELParser method bug56185.

@Test
public void bug56185() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    TesterBeanC beanC = new TesterBeanC();
    ValueExpression var = factory.createValueExpression(beanC, TesterBeanC.class);
    context.getVariableMapper().setVariable("myBean", var);
    ValueExpression ve = factory.createValueExpression(context, "${(myBean.int1 > 1 and myBean.myBool) or " + "((myBean.myBool or myBean.myBool1) and myBean.int1 > 1)}", Boolean.class);
    assertEquals(Boolean.FALSE, ve.getValue(context));
    beanC.setInt1(2);
    beanC.setMyBool1(true);
    assertEquals(Boolean.TRUE, ve.getValue(context));
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 15 with ValueExpression

use of javax.el.ValueExpression in project tomcat by apache.

the class TestELParser method testExpression.

private void testExpression(String expression, String expected) {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    ValueExpression ve = factory.createValueExpression(context, expression, String.class);
    String result = (String) ve.getValue(context);
    assertEquals(expected, result);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Aggregations

ValueExpression (javax.el.ValueExpression)59 Test (org.junit.Test)36 ExpressionFactory (javax.el.ExpressionFactory)33 ELContext (javax.el.ELContext)27 ELContextImpl (org.apache.jasper.el.ELContextImpl)17 VariableMapper (javax.el.VariableMapper)9 ELException (javax.el.ELException)7 ELProcessor (javax.el.ELProcessor)7 MethodExpression (javax.el.MethodExpression)7 PropertyNotFoundException (javax.el.PropertyNotFoundException)4 ValueReference (javax.el.ValueReference)4 SimpleContext (de.odysseus.el.util.SimpleContext)2 HashMap (java.util.HashMap)2 ELClass (javax.el.ELClass)2 FunctionMapper (javax.el.FunctionMapper)2 ELParseException (javax.servlet.jsp.el.ELParseException)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1