use of javax.el.ExpressionFactory 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);
}
use of javax.el.ExpressionFactory 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());
}
use of javax.el.ExpressionFactory in project tomcat70 by apache.
the class TestValueExpressionImpl method testBug50105.
@Test
public void testBug50105() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
TesterEnum testEnum = TesterEnum.APPLE;
ValueExpression var = factory.createValueExpression(testEnum, TesterEnum.class);
context.getVariableMapper().setVariable("testEnum", var);
// When coercing an Enum to a String, name() should always be used.
ValueExpression ve1 = factory.createValueExpression(context, "${testEnum}", String.class);
String result1 = (String) ve1.getValue(context);
Assert.assertEquals("APPLE", result1);
ValueExpression ve2 = factory.createValueExpression(context, "foo${testEnum}bar", String.class);
String result2 = (String) ve2.getValue(context);
Assert.assertEquals("fooAPPLEbar", result2);
}
use of javax.el.ExpressionFactory in project tomcat70 by apache.
the class TestValueExpressionImpl method testBug51544Direct.
/**
* Test using list directly as variable.
*/
@Test
public void testBug51544Direct() throws Exception {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
List<?> list = Collections.emptyList();
ValueExpression var = factory.createValueExpression(list, List.class);
context.getVariableMapper().setVariable("list", var);
ValueExpression ve = factory.createValueExpression(context, "${list.size()}", Integer.class);
Integer result = (Integer) ve.getValue(context);
Assert.assertEquals(Integer.valueOf(0), result);
}
use of javax.el.ExpressionFactory in project tomcat70 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();
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);
}
Aggregations