Search in sources :

Example 46 with ELContextImpl

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

the class TestValueExpressionImpl method testBug51177ObjectList.

@Test
public void testBug51177ObjectList() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);
    List<Object> list = new ArrayList<>();
    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(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ArrayList(java.util.ArrayList) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 47 with ELContextImpl

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

the class JspApplicationContextImpl method createELContext.

public ELContextImpl createELContext(JspContext context) {
    if (context == null) {
        throw new IllegalArgumentException(Localizer.getMessage("jsp.error.nullArgument"));
    }
    // create ELContext for JspContext
    final ELResolver r = this.createELResolver();
    ELContextImpl ctx;
    if (Constants.IS_SECURITY_ENABLED) {
        ctx = AccessController.doPrivileged((PrivilegedAction<ELContextImpl>) () -> new ELContextImpl(r));
    } else {
        ctx = new ELContextImpl(r);
    }
    ctx.putContext(JspContext.class, context);
    // alert all ELContextListeners
    fireListeners(ctx);
    return ctx;
}
Also used : ELResolver(jakarta.el.ELResolver) CompositeELResolver(jakarta.el.CompositeELResolver) JasperELResolver(org.apache.jasper.el.JasperELResolver) PrivilegedAction(java.security.PrivilegedAction) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Example 48 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat 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
 * @throws ELException If an error occurs during the evaluation
 */
public static Object proprietaryEvaluate(final String expression, final Class<?> expectedType, final PageContext pageContext, final ProtectedFunctionMapper functionMap) 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(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ELContextWrapper(org.apache.jasper.runtime.JspContextWrapper.ELContextWrapper) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Example 49 with ELContextImpl

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

the class TestAttributeParser method evalAttr.

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

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