Search in sources :

Example 11 with ExpressionFactory

use of javax.el.ExpressionFactory in project tomcat70 by apache.

the class TestValueExpressionImpl method testGetValueReferenceVariable.

@Test
public void testGetValueReferenceVariable() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class);
    context.getVariableMapper().setVariable("beanB", var);
    ValueExpression var2 = factory.createValueExpression(context, "${beanB.name}", String.class);
    context.getVariableMapper().setVariable("foo", var2);
    ValueExpression ve = factory.createValueExpression(context, "${foo}", ValueExpression.class);
    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    Assert.assertNotNull(vr);
    Assert.assertEquals(beanB, vr.getBase());
    Assert.assertEquals("name", vr.getProperty());
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(javax.el.ValueReference) Test(org.junit.Test)

Example 12 with ExpressionFactory

use of javax.el.ExpressionFactory in project tomcat70 by apache.

the class TestValueExpressionImpl method testBug51177ObjectList.

@Test
public void testBug51177ObjectList() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);
    List<Object> list = new ArrayList<Object>();
    list.add(0, o1);
    list.add(1, o2);
    ValueExpression var = factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);
    ValueExpression ve1 = factory.createValueExpression(context, "${list[0]}", Object.class);
    ve1.setValue(context, o2);
    Assert.assertEquals(o2, ve1.getValue(context));
    ValueExpression ve2 = factory.createValueExpression(context, "${list[1]}", Object.class);
    ve2.setValue(context, o1);
    Assert.assertEquals(o1, ve2.getValue(context));
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ArrayList(java.util.ArrayList) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 13 with ExpressionFactory

use of javax.el.ExpressionFactory in project tomcat70 by apache.

the class TestValueExpressionImpl method testGetValueReference.

@Test
public void testGetValueReference() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class);
    context.getVariableMapper().setVariable("beanB", var);
    ValueExpression ve = factory.createValueExpression(context, "${beanB.name}", String.class);
    // First check the basics work
    String result = (String) ve.getValue(context);
    Assert.assertEquals("Tomcat", result);
    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    Assert.assertNotNull(vr);
    Assert.assertEquals(beanB, vr.getBase());
    Assert.assertEquals("name", vr.getProperty());
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(javax.el.ValueReference) Test(org.junit.Test)

Example 14 with ExpressionFactory

use of javax.el.ExpressionFactory in project tomcat70 by apache.

the class TestELParser method doTestParser.

private void doTestParser(String input, String expectedResult, String expectedBuilderOutput) throws JasperException {
    ELException elException = null;
    String elResult = null;
    // Don't try and evaluate expressions that depend on variables or functions
    if (expectedResult != null) {
        try {
            ExpressionFactory factory = ExpressionFactory.newInstance();
            ELContext context = new ELContextImpl();
            ValueExpression ve = factory.createValueExpression(context, input, String.class);
            elResult = ve.getValue(context).toString();
            Assert.assertEquals(expectedResult, elResult);
        } catch (ELException ele) {
            elException = ele;
        }
    }
    Nodes nodes = null;
    try {
        nodes = ELParser.parse(input, false);
        Assert.assertNull(elException);
    } catch (IllegalArgumentException iae) {
        Assert.assertNotNull(elResult, elException);
        // Not strictly true but enables us to report both
        iae.initCause(elException);
        throw iae;
    }
    TextBuilder textBuilder = new TextBuilder(false);
    nodes.visit(textBuilder);
    Assert.assertEquals(expectedBuilderOutput, textBuilder.getText());
}
Also used : ELContext(javax.el.ELContext) TextBuilder(org.apache.jasper.compiler.ELParser.TextBuilder) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ELException(javax.el.ELException) Nodes(org.apache.jasper.compiler.ELNode.Nodes)

Example 15 with ExpressionFactory

use of javax.el.ExpressionFactory 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)

Aggregations

ExpressionFactory (javax.el.ExpressionFactory)39 ValueExpression (javax.el.ValueExpression)28 Test (org.junit.Test)24 ELContext (javax.el.ELContext)22 ELContextImpl (org.apache.jasper.el.ELContextImpl)15 ELException (javax.el.ELException)4 ValueReference (javax.el.ValueReference)3 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 FacesException (javax.faces.FacesException)2 FacesContext (javax.faces.context.FacesContext)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 SimpleContext (de.odysseus.el.util.SimpleContext)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ELResolver (javax.el.ELResolver)1 ServletContextEvent (javax.servlet.ServletContextEvent)1