Search in sources :

Example 26 with ELContext

use of javax.el.ELContext 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(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 27 with ELContext

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

the class TestScopedAttributeELResolverPerformance method testGetValuePerformance.

/*
     * With the caching of NotFound responses this test takes ~20ms. Without the
     * caching it takes ~6s.
     */
@Test
public void testGetValuePerformance() throws Exception {
    ELContext context = new StandardELContext(ELManager.getExpressionFactory());
    context.putContext(JspContext.class, new TesterPageContext());
    ELResolver resolver = new ScopedAttributeELResolver();
    for (int i = 0; i < 100000; i++) {
        resolver.getValue(context, null, "unknown");
    }
}
Also used : TesterPageContext(javax.servlet.jsp.TesterPageContext) StandardELContext(javax.el.StandardELContext) ELContext(javax.el.ELContext) ELResolver(javax.el.ELResolver) StandardELContext(javax.el.StandardELContext) Test(org.junit.Test)

Example 28 with ELContext

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

the class JuelExpression method evaluate.

public <T> T evaluate(Exchange exchange, Class<T> tClass) {
    // Create (if needed) the ExpressionFactory first from the CamelContext using FactoryFinder
    ExpressionFactory factory = getExpressionFactory(exchange.getContext());
    ELContext context = populateContext(createContext(), exchange);
    ValueExpression valueExpression = factory.createValueExpression(context, expression, type);
    Object value = valueExpression.getValue(context);
    LOG.trace("Value returned {}", value);
    return exchange.getContext().getTypeConverter().convertTo(tClass, value);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression)

Aggregations

ELContext (javax.el.ELContext)28 ValueExpression (javax.el.ValueExpression)27 ExpressionFactory (javax.el.ExpressionFactory)26 Test (org.junit.Test)23 ELContextImpl (org.apache.jasper.el.ELContextImpl)15 ELProcessor (javax.el.ELProcessor)7 ELException (javax.el.ELException)3 ValueReference (javax.el.ValueReference)3 VariableMapper (javax.el.VariableMapper)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 SimpleContext (de.odysseus.el.util.SimpleContext)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BeanELResolver (javax.el.BeanELResolver)1 ELManager (javax.el.ELManager)1 ELResolver (javax.el.ELResolver)1 FunctionMapper (javax.el.FunctionMapper)1 StandardELContext (javax.el.StandardELContext)1 TesterELContext (javax.el.TesterELContext)1 TesterPageContext (javax.servlet.jsp.TesterPageContext)1