1 25 26 package org.apache.jasper.runtime; 27 28 import java.util.Iterator ; 29 30 import javax.el.ELContext; 31 import javax.el.ELResolver; 32 import javax.el.ValueExpression; 33 import javax.el.ExpressionFactory; 34 35 import javax.servlet.jsp.PageContext ; 36 import javax.servlet.jsp.el.Expression ; 37 import javax.servlet.jsp.el.ELException ; 38 import javax.servlet.jsp.el.FunctionMapper ; 39 import javax.servlet.jsp.el.ExpressionEvaluator ; 40 import javax.servlet.jsp.el.VariableResolver ; 41 42 49 50 public class ExpressionEvaluatorImpl extends ExpressionEvaluator 51 { 52 private PageContext pageContext; 53 54 58 public ExpressionEvaluatorImpl (PageContext pageContext) { 59 this.pageContext = pageContext; 60 } 61 62 public Expression parseExpression(String expression, 64 Class expectedType, 65 FunctionMapper fMapper ) 66 throws ELException { 67 68 ExpressionFactory fac = JspApplicationContextImpl.expressionFactory; 69 javax.el.ValueExpression expr; 70 ELContextImpl elContext = new ELContextImpl(null); 71 javax.el.FunctionMapper fm = new FunctionMapperWrapper(fMapper); 72 elContext.setFunctionMapper(fm); 73 try { 74 expr = fac.createValueExpression( 75 elContext, 76 expression, expectedType); 77 } catch (javax.el.ELException ex) { 78 throw new ELException (ex); 79 } 80 return new ExpressionImpl(expr, pageContext); 81 } 82 83 public Object evaluate(String expression, 84 Class expectedType, 85 VariableResolver vResolver, 86 FunctionMapper fMapper ) 87 throws ELException { 88 89 ELContextImpl elContext; 90 if (vResolver instanceof VariableResolverImpl) { 91 elContext = (ELContextImpl) pageContext.getELContext(); 92 } 93 else { 94 elContext = new ELContextImpl(new ELResolverWrapper(vResolver)); 97 } 98 99 javax.el.FunctionMapper fm = new FunctionMapperWrapper(fMapper); 100 elContext.setFunctionMapper(fm); 101 ExpressionFactory fac = JspApplicationContextImpl.expressionFactory; 102 Object value; 103 try { 104 ValueExpression expr = fac.createValueExpression( 105 elContext, 106 expression, 107 expectedType); 108 value = expr.getValue(elContext); 109 } catch (javax.el.ELException ex) { 110 throw new ELException (ex); 111 } 112 return value; 113 } 114 115 static private class ExpressionImpl extends Expression { 116 117 private ValueExpression valueExpr; 118 private PageContext pageContext; 119 120 ExpressionImpl(ValueExpression valueExpr, 121 PageContext pageContext) { 122 this.valueExpr = valueExpr; 123 this.pageContext = pageContext; 124 } 125 126 public Object evaluate(VariableResolver vResolver) throws ELException { 127 128 ELContext elContext; 129 if (vResolver instanceof VariableResolverImpl) { 130 elContext = pageContext.getELContext(); 131 } 132 else { 133 elContext = new ELContextImpl(new ELResolverWrapper(vResolver)); 136 } 137 try { 138 return valueExpr.getValue(elContext); 139 } catch (javax.el.ELException ex) { 140 throw new ELException (ex); 141 } 142 } 143 } 144 145 private static class FunctionMapperWrapper 146 extends javax.el.FunctionMapper { 147 148 private FunctionMapper mapper; 149 150 FunctionMapperWrapper(FunctionMapper mapper) { 151 this.mapper = mapper; 152 } 153 154 public java.lang.reflect.Method resolveFunction(String prefix, 155 String localName) { 156 return mapper.resolveFunction(prefix, localName); 157 } 158 } 159 160 private static class ELResolverWrapper extends ELResolver { 161 private VariableResolver vResolver; 162 163 ELResolverWrapper(VariableResolver vResolver) { 164 this.vResolver = vResolver; 165 } 166 167 public Object getValue(ELContext context, 168 Object base, 169 Object property) 170 throws javax.el.ELException { 171 if (base == null) { 172 context.setPropertyResolved(true); 173 try { 174 return vResolver.resolveVariable(property.toString()); 175 } catch (ELException ex) { 176 throw new javax.el.ELException(ex); 177 } 178 } 179 return null; 180 } 181 182 public Class getType(ELContext context, 183 Object base, 184 Object property) 185 throws javax.el.ELException { 186 return null; 187 } 188 189 public void setValue(ELContext context, 190 Object base, 191 Object property, 192 Object value) 193 throws javax.el.ELException { 194 } 195 196 public boolean isReadOnly(ELContext context, 197 Object base, 198 Object property) 199 throws javax.el.ELException { 200 return false; 201 } 202 203 public Iterator getFeatureDescriptors(ELContext context, 204 Object base) { 205 return null; 206 } 207 208 public Class getCommonPropertyType(ELContext context, 209 Object base) { 210 return null; 211 } 212 } 213 } 214 | Popular Tags |