01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jasper.el;
18:
19: import javax.el.ELContext;
20: import javax.el.ExpressionFactory;
21: import javax.el.ValueExpression;
22: import javax.servlet.jsp.el.ELException;
23: import javax.servlet.jsp.el.ELParseException;
24: import javax.servlet.jsp.el.Expression;
25: import javax.servlet.jsp.el.ExpressionEvaluator;
26: import javax.servlet.jsp.el.FunctionMapper;
27: import javax.servlet.jsp.el.VariableResolver;
28:
29: public final class ExpressionEvaluatorImpl extends ExpressionEvaluator {
30:
31: private final ExpressionFactory factory;
32:
33: public ExpressionEvaluatorImpl(ExpressionFactory factory) {
34: this .factory = factory;
35: }
36:
37: public Expression parseExpression(String expression,
38: Class expectedType, FunctionMapper fMapper)
39: throws ELException {
40: try {
41: ELContextImpl ctx = new ELContextImpl(
42: ELResolverImpl.DefaultResolver);
43: if (fMapper != null) {
44: ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
45: }
46: ValueExpression ve = this .factory.createValueExpression(
47: ctx, expression, expectedType);
48: return new ExpressionImpl(ve);
49: } catch (javax.el.ELException e) {
50: throw new ELParseException(e.getMessage());
51: }
52: }
53:
54: public Object evaluate(String expression, Class expectedType,
55: VariableResolver vResolver, FunctionMapper fMapper)
56: throws ELException {
57: return this.parseExpression(expression, expectedType, fMapper)
58: .evaluate(vResolver);
59: }
60:
61: }
|