Search in sources :

Example 31 with ELContext

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

the class TestValueExpressionImpl method testBug51544Bean.

/**
 * Test returning an empty list as a bean property.
 */
@Test
public void testBug51544Bean() throws Exception {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    TesterBeanA beanA = new TesterBeanA();
    beanA.setValList(Collections.emptyList());
    ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);
    ValueExpression ve = factory.createValueExpression(context, "${beanA.valList.size()}", Integer.class);
    Integer result = (Integer) ve.getValue(context);
    Assert.assertEquals(Integer.valueOf(0), result);
}
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 32 with ELContext

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

the class TestValueExpressionImpl method testBug51177ObjectMap.

@Test
public void testBug51177ObjectMap() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);
    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put("key1", o1);
    map.put("key2", o2);
    ValueExpression var = factory.createValueExpression(map, Map.class);
    context.getVariableMapper().setVariable("map", var);
    ValueExpression ve1 = factory.createValueExpression(context, "${map.key1}", Object.class);
    ve1.setValue(context, o2);
    Assert.assertEquals(o2, ve1.getValue(context));
    ValueExpression ve2 = factory.createValueExpression(context, "${map.key2}", Object.class);
    ve2.setValue(context, o1);
    Assert.assertEquals(o1, ve2.getValue(context));
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) HashMap(java.util.HashMap) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 33 with ELContext

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

the class TestELParser method testJavaKeyWordSuffix.

@Test
public void testJavaKeyWordSuffix() {
    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("beanA", var);
    // Should fail
    Exception e = null;
    try {
        factory.createValueExpression(context, "${beanA.int}", 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 34 with ELContext

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

the class TestELParser method testExpression.

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

Example 35 with ELContext

use of javax.el.ELContext in project ysoserial by frohoff.

the class Myfaces1 method makeExpressionPayload.

public static Object makeExpressionPayload(String expr) throws IllegalArgumentException, IllegalAccessException, Exception {
    FacesContextImpl fc = new FacesContextImpl((ServletContext) null, (ServletRequest) null, (ServletResponse) null);
    ELContext elContext = new FacesELContext(new CompositeELResolver(), fc);
    Reflections.getField(FacesContextImplBase.class, "_elContext").set(fc, elContext);
    ExpressionFactory expressionFactory = ExpressionFactory.newInstance();
    ValueExpression ve1 = expressionFactory.createValueExpression(elContext, expr, Object.class);
    ValueExpressionMethodExpression e = new ValueExpressionMethodExpression(ve1);
    ValueExpression ve2 = expressionFactory.createValueExpression(elContext, "${true}", Object.class);
    ValueExpressionMethodExpression e2 = new ValueExpressionMethodExpression(ve2);
    return Gadgets.makeMap(e2, e);
}
Also used : FacesELContext(org.apache.myfaces.el.unified.FacesELContext) FacesELContext(org.apache.myfaces.el.unified.FacesELContext) ELContext(javax.el.ELContext) CompositeELResolver(org.apache.myfaces.el.CompositeELResolver) FacesContextImpl(org.apache.myfaces.context.servlet.FacesContextImpl) ExpressionFactory(javax.el.ExpressionFactory) ValueExpressionMethodExpression(org.apache.myfaces.view.facelets.el.ValueExpressionMethodExpression) FacesContextImplBase(org.apache.myfaces.context.servlet.FacesContextImplBase) ValueExpression(javax.el.ValueExpression)

Aggregations

ELContext (javax.el.ELContext)47 ValueExpression (javax.el.ValueExpression)31 Test (org.junit.Test)29 ExpressionFactory (javax.el.ExpressionFactory)22 ELContextImpl (org.apache.jasper.el.ELContextImpl)15 ValueReference (javax.el.ValueReference)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 UIComponent (javax.faces.component.UIComponent)7 ELException (javax.el.ELException)4 ELResolver (javax.el.ELResolver)4 BeanELResolver (javax.el.BeanELResolver)3 ArrayELResolver (javax.el.ArrayELResolver)2 CompositeELResolver (javax.el.CompositeELResolver)2 FunctionMapper (javax.el.FunctionMapper)2 ListELResolver (javax.el.ListELResolver)2 MapELResolver (javax.el.MapELResolver)2 ResourceBundleELResolver (javax.el.ResourceBundleELResolver)2 VariableMapper (javax.el.VariableMapper)2 FacesContext (javax.faces.context.FacesContext)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1