use of jakarta.el.ValueExpression in project tomcat 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(factory);
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);
}
use of jakarta.el.ValueExpression in project tomcat by apache.
the class TestValueExpressionImpl method testGetValueReferenceVariable.
@Test
public void testGetValueReferenceVariable() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl(factory);
TesterBeanB beanB = new TesterBeanB();
beanB.setName("Tomcat");
ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class);
context.getVariableMapper().setVariable("beanB", var);
ValueExpression var2 = factory.createValueExpression(context, "${beanB.name}", String.class);
context.getVariableMapper().setVariable("foo", var2);
ValueExpression ve = factory.createValueExpression(context, "${foo}", ValueExpression.class);
// Now check the value reference
ValueReference vr = ve.getValueReference(context);
Assert.assertNotNull(vr);
Assert.assertEquals(beanB, vr.getBase());
Assert.assertEquals("name", vr.getProperty());
}
use of jakarta.el.ValueExpression 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 jakarta.el.ValueExpression in project tomcat by apache.
the class TestMethodExpressionImpl method testBugPrimitives.
@Test
public void testBugPrimitives() throws Exception {
MethodExpression me = factory.createMethodExpression(context, "${beanA.setValLong(5)}", null, null);
me.invoke(context, null);
ValueExpression ve = factory.createValueExpression(context, "#{beanA.valLong}", java.lang.String.class);
Assert.assertEquals("5", ve.getValue(context));
}
use of jakarta.el.ValueExpression 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);
}
Aggregations