Search in sources :

Example 21 with ExpressionFactory

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

the class PageContextImpl method proprietaryEvaluate.

/**
 * Proprietary method to evaluate EL expressions. XXX - This method should
 * go away once the EL interpreter moves out of JSTL and into its own
 * project. For now, this is necessary because the standard machinery is too
 * slow.
 *
 * @param expression
 *            The expression to be evaluated
 * @param expectedType
 *            The expected resulting type
 * @param pageContext
 *            The page context
 * @param functionMap
 *            Maps prefix and name to Method
 * @return The result of the evaluation
 */
public static Object proprietaryEvaluate(final String expression, final Class<?> expectedType, final PageContext pageContext, final ProtectedFunctionMapper functionMap, final boolean escape) throws ELException {
    final ExpressionFactory exprFactory = jspf.getJspApplicationContext(pageContext.getServletContext()).getExpressionFactory();
    ELContext ctx = pageContext.getELContext();
    ELContextImpl ctxImpl;
    if (ctx instanceof ELContextWrapper) {
        ctxImpl = (ELContextImpl) ((ELContextWrapper) ctx).getWrappedELContext();
    } else {
        ctxImpl = (ELContextImpl) ctx;
    }
    ctxImpl.setFunctionMapper(functionMap);
    ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
    return ve.getValue(ctx);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ELContextWrapper(org.apache.jasper.runtime.JspContextWrapper.ELContextWrapper) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Example 22 with ExpressionFactory

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

the class TestValueExpressionImpl method testBug49345.

@Test
public void testBug49345() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    TesterBeanA beanA = new TesterBeanA();
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    beanA.setBean(beanB);
    ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);
    ValueExpression ve = factory.createValueExpression(context, "${beanA.bean.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 23 with ExpressionFactory

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

the class TestValueExpressionImpl method testBug50105.

@Test
public void testBug50105() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    TesterEnum testEnum = TesterEnum.APPLE;
    ValueExpression var = factory.createValueExpression(testEnum, TesterEnum.class);
    context.getVariableMapper().setVariable("testEnum", var);
    // When coercing an Enum to a String, name() should always be used.
    ValueExpression ve1 = factory.createValueExpression(context, "${testEnum}", String.class);
    String result1 = (String) ve1.getValue(context);
    Assert.assertEquals("APPLE", result1);
    ValueExpression ve2 = factory.createValueExpression(context, "foo${testEnum}bar", String.class);
    String result2 = (String) ve2.getValue(context);
    Assert.assertEquals("fooAPPLEbar", result2);
}
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 24 with ExpressionFactory

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

the class TestValueExpressionImpl method testBug51544Direct.

/**
 * Test using list directly as variable.
 */
@Test
public void testBug51544Direct() throws Exception {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    List<?> list = Collections.emptyList();
    ValueExpression var = factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);
    ValueExpression ve = factory.createValueExpression(context, "${list.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 25 with ExpressionFactory

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

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