use of org.apache.jasper.el.ELContextImpl in project tomcat by apache.
the class TestValueExpressionImpl method testBug49345.
@Test
public void testBug49345() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl(factory);
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 org.apache.jasper.el.ELContextImpl in project tomcat by apache.
the class TestResourceBundleELResolver method bug53001.
@Test
public void bug53001() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl(factory);
ResourceBundle rb = new TesterResourceBundle();
ValueExpression var = factory.createValueExpression(rb, ResourceBundle.class);
context.getVariableMapper().setVariable("rb", var);
ValueExpression ve = factory.createValueExpression(context, "${rb.keys}", String.class);
MethodExpression me = factory.createMethodExpression(context, "${rb.getKeys()}", Enumeration.class, null);
// Ensure we are specification compliant
String result1 = (String) ve.getValue(context);
Assert.assertEquals("???keys???", result1);
// Check that the method expression does return the keys
Object result2 = me.invoke(context, null);
Assert.assertTrue(result2 instanceof Enumeration);
@SuppressWarnings("unchecked") Enumeration<String> e = (Enumeration<String>) result2;
Assert.assertTrue(e.hasMoreElements());
String element = e.nextElement();
if ("key1".equals(element)) {
Assert.assertEquals("key1", element);
Assert.assertTrue(e.hasMoreElements());
Assert.assertEquals("key2", e.nextElement());
Assert.assertFalse(e.hasMoreElements());
} else {
Assert.assertEquals("key2", element);
Assert.assertTrue(e.hasMoreElements());
Assert.assertEquals("key1", e.nextElement());
Assert.assertFalse(e.hasMoreElements());
}
}
use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.
the class JspApplicationContextImpl method createELContext.
public ELContextImpl createELContext(JspContext context) {
if (context == null) {
throw new IllegalArgumentException("JspContext was null");
}
// create ELContext for JspContext
final ELResolver r = this.createELResolver();
ELContextImpl ctx;
if (Constants.IS_SECURITY_ENABLED) {
ctx = AccessController.doPrivileged(new PrivilegedAction<ELContextImpl>() {
@Override
public ELContextImpl run() {
return new ELContextImpl(r);
}
});
} else {
ctx = new ELContextImpl(r);
}
ctx.putContext(JspContext.class, context);
// alert all ELContextListeners
ELContextEvent event = new ELContextEvent(ctx);
for (int i = 0; i < this.contextListeners.size(); i++) {
this.contextListeners.get(i).contextCreated(event);
}
return ctx;
}
use of org.apache.jasper.el.ELContextImpl 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 org.apache.jasper.el.ELContextImpl 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());
}
Aggregations