1 16 17 package org.springframework.mock.web; 18 19 import javax.servlet.jsp.JspException ; 20 import javax.servlet.jsp.PageContext ; 21 import javax.servlet.jsp.el.ELException ; 22 import javax.servlet.jsp.el.Expression ; 23 import javax.servlet.jsp.el.ExpressionEvaluator ; 24 import javax.servlet.jsp.el.FunctionMapper ; 25 import javax.servlet.jsp.el.VariableResolver ; 26 27 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 28 29 43 public class MockExpressionEvaluator extends ExpressionEvaluator { 44 45 private final PageContext pageContext; 46 47 48 52 public MockExpressionEvaluator(PageContext pageContext) { 53 this.pageContext = pageContext; 54 } 55 56 public Expression parseExpression( 57 final String expression, final Class expectedType, final FunctionMapper functionMapper) 58 throws ELException { 59 60 return new Expression () { 61 public Object evaluate(VariableResolver variableResolver) throws ELException { 62 return doEvaluate(expression, expectedType, functionMapper); 63 } 64 }; 65 } 66 67 public Object evaluate( 68 String expression, Class expectedType, VariableResolver variableResolver, FunctionMapper functionMapper) 69 throws ELException { 70 71 if (variableResolver != null) { 72 throw new IllegalArgumentException ("Custom VariableResolver not supported"); 73 } 74 return doEvaluate(expression, expectedType, functionMapper); 75 } 76 77 protected Object doEvaluate( 78 String expression, Class expectedType, FunctionMapper functionMapper) 79 throws ELException { 80 81 if (functionMapper != null) { 82 throw new IllegalArgumentException ("Custom FunctionMapper not supported"); 83 } 84 try { 85 return ExpressionEvaluatorManager.evaluate("JSP EL expression", expression, expectedType, this.pageContext); 86 } 87 catch (JspException ex) { 88 throw new ELException ("Parsing of JSP EL expression \"" + expression + "\" failed", ex); 89 } 90 } 91 92 } 93 | Popular Tags |