Search in sources :

Example 11 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.

the class TestELParser method doTestBug56179.

private void doTestBug56179(int parenthesesCount, String innerExpr) {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    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);
    Assert.assertEquals("true", result);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Example 12 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.

the class TestELParser method bug56185.

@Test
public void bug56185() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    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);
    Assert.assertEquals(Boolean.FALSE, ve.getValue(context));
    beanC.setInt1(2);
    beanC.setMyBool1(true);
    Assert.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 13 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.

the class TestELParser method testJavaKeyWordIdentifier.

@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;
    }
    Assert.assertNotNull(e);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ELException(javax.el.ELException) ELException(javax.el.ELException) Test(org.junit.Test)

Example 14 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat by apache.

the class TestResourceBundleELResolver method bug53001.

@Test
public void bug53001() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    ResourceBundle rb = new TesterResourceBundle();
    ValueExpression var = factory.createValueExpression(rb, ResourceBundle.class);
    context.getVariableMapper().setVariable("rb", var);
    ValueExpression ve = factory.createValueExpression(context, "${rb.keys}", String.class);
    MethodExpression me = factory.createMethodExpression(context, "${rb.getKeys()}", Enumeration.class, null);
    // Ensure we are specification compliant
    String result1 = (String) ve.getValue(context);
    Assert.assertEquals("???keys???", result1);
    // Check that the method expression does return the keys
    Object result2 = me.invoke(context, null);
    @SuppressWarnings("unchecked") Enumeration<String> e = (Enumeration<String>) result2;
    Assert.assertTrue(e.hasMoreElements());
    String element = e.nextElement();
    if ("key1".equals(element)) {
        Assert.assertEquals("key1", element);
        Assert.assertTrue(e.hasMoreElements());
        Assert.assertEquals("key2", e.nextElement());
        Assert.assertFalse(e.hasMoreElements());
    } else {
        Assert.assertEquals("key2", element);
        Assert.assertTrue(e.hasMoreElements());
        Assert.assertEquals("key1", e.nextElement());
        Assert.assertFalse(e.hasMoreElements());
    }
}
Also used : Enumeration(java.util.Enumeration) ELContextImpl(org.apache.jasper.el.ELContextImpl) ResourceBundle(java.util.ResourceBundle) ListResourceBundle(java.util.ListResourceBundle) Test(org.junit.Test)

Example 15 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl 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);
    Assert.assertEquals(expected, result);
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Aggregations

ELContextImpl (org.apache.jasper.el.ELContextImpl)49 Test (org.junit.Test)34 ValueExpression (jakarta.el.ValueExpression)17 ValueExpression (javax.el.ValueExpression)17 ELContext (jakarta.el.ELContext)16 ExpressionFactory (jakarta.el.ExpressionFactory)16 ELContext (javax.el.ELContext)15 ExpressionFactory (javax.el.ExpressionFactory)15 ListResourceBundle (java.util.ListResourceBundle)8 ResourceBundle (java.util.ResourceBundle)8 ValueReference (jakarta.el.ValueReference)3 FeatureDescriptor (java.beans.FeatureDescriptor)3 Enumeration (java.util.Enumeration)3 HashMap (java.util.HashMap)3 ELException (javax.el.ELException)3 ValueReference (javax.el.ValueReference)3 ELException (jakarta.el.ELException)2 PrivilegedAction (java.security.PrivilegedAction)2 ArrayList (java.util.ArrayList)2 ExpressionFactoryImpl (org.apache.el.ExpressionFactoryImpl)2