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));
}
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;
}
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);
}
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);
}
Aggregations