1 29 30 package com.caucho.jsp.el; 31 32 import com.caucho.el.Expr; 33 34 import javax.el.ELContext; 35 import javax.el.ELResolver; 36 import javax.servlet.jsp.el.Expression ; 37 import javax.servlet.jsp.el.ExpressionEvaluator ; 38 import javax.servlet.jsp.el.FunctionMapper ; 39 import java.lang.reflect.Method ; 40 41 44 public class ExpressionEvaluatorImpl extends ExpressionEvaluator { 45 private ELContext _elContext; 46 47 50 public ExpressionEvaluatorImpl(ELContext elContext) 51 { 52 _elContext = elContext; 53 } 54 55 58 public Object evaluate(String expression, Class expectedType, 59 javax.servlet.jsp.el.VariableResolver resolver, 60 FunctionMapper funMapper) 61 throws javax.servlet.jsp.el.ELException 62 { 63 Expression expr = parseExpression(expression, expectedType, funMapper); 64 65 return expr.evaluate(resolver); 66 } 67 68 71 public Expression parseExpression(String expression, 72 Class expectedType, 73 FunctionMapper funMapper) 74 throws javax.servlet.jsp.el.ELException 75 { 76 ELContext elContext; 77 78 if (funMapper != null) 79 elContext = new ParseELContext(funMapper); 80 else 81 elContext = _elContext; 82 83 JspELParser parser = new JspELParser(elContext, expression); 84 85 87 try { 88 Expr expr = parser.parse(); 89 90 return new ExpressionImpl(expr); 91 } catch (com.caucho.el.ELParseException e) { 92 throw new javax.servlet.jsp.el.ELParseException (e.getMessage()); 93 } 94 } 95 96 public class ParseELContext extends ELContext 97 { 98 private javax.el.FunctionMapper _funMapper; 99 100 ParseELContext(FunctionMapper funMapper) 101 { 102 _funMapper = new FunctionMapperAdapter(funMapper); 103 } 104 105 public ELResolver getELResolver() 106 { 107 return _elContext.getELResolver(); 108 } 109 110 public javax.el.FunctionMapper getFunctionMapper() 111 { 112 return _funMapper; 113 } 114 115 public javax.el.VariableMapper getVariableMapper() 116 { 117 return _elContext.getVariableMapper(); 118 } 119 } 120 121 public class FunctionMapperAdapter extends javax.el.FunctionMapper 122 { 123 private FunctionMapper _funMap; 124 125 FunctionMapperAdapter(FunctionMapper funMap) 126 { 127 _funMap = funMap; 128 } 129 130 public Method resolveFunction(String prefix, String localName) 131 { 132 return _funMap.resolveFunction(prefix, localName); 133 } 134 } 135 } 136 | Popular Tags |