Search in sources :

Example 1 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl 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 2 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl 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 3 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl 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 4 with ELContextImpl

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

the class TestAttributeParser method evalAttr.

private String evalAttr(String expression, char quote) {
    ELContextImpl ctx = new ELContextImpl();
    ctx.setFunctionMapper(new TesterFunctions.FMapper());
    ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
    ValueExpression ve = exprFactory.createValueExpression(ctx, AttributeParser.getUnquoted(expression, quote, false, false, false, false), String.class);
    return (String) ve.getValue(ctx);
}
Also used : TesterFunctions(org.apache.el.TesterFunctions) ExpressionFactoryImpl(org.apache.el.ExpressionFactoryImpl) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Example 5 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl 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)

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