Search in sources :

Example 26 with ELContextImpl

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

the class TestValueExpressionImpl method testBug49345.

@Test
public void testBug49345() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    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(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(jakarta.el.ValueReference) Test(org.junit.Test)

Example 27 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);
    Assert.assertTrue(result2 instanceof Enumeration);
    @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 28 with ELContextImpl

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

the class JspApplicationContextImpl method createELContext.

public ELContextImpl createELContext(JspContext context) {
    if (context == null) {
        throw new IllegalArgumentException("JspContext was null");
    }
    // create ELContext for JspContext
    final ELResolver r = this.createELResolver();
    ELContextImpl ctx;
    if (Constants.IS_SECURITY_ENABLED) {
        ctx = AccessController.doPrivileged(new PrivilegedAction<ELContextImpl>() {

            @Override
            public ELContextImpl run() {
                return new ELContextImpl(r);
            }
        });
    } else {
        ctx = new ELContextImpl(r);
    }
    ctx.putContext(JspContext.class, context);
    // alert all ELContextListeners
    ELContextEvent event = new ELContextEvent(ctx);
    for (int i = 0; i < this.contextListeners.size(); i++) {
        this.contextListeners.get(i).contextCreated(event);
    }
    return ctx;
}
Also used : ELResolver(javax.el.ELResolver) JasperELResolver(org.apache.jasper.el.JasperELResolver) CompositeELResolver(javax.el.CompositeELResolver) PrivilegedAction(java.security.PrivilegedAction) ELContextImpl(org.apache.jasper.el.ELContextImpl) ELContextEvent(javax.el.ELContextEvent)

Example 29 with ELContextImpl

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

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

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