Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
* contributor license agreements. See the NOTICE file distributed with |
4 |
* this work for additional information regarding copyright ownership. |
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
* (the "License"); you may not use this file except in compliance with |
7 |
* the License. You may obtain a copy of the License at |
8 |
* |
9 |
* 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 |
|
18 |
package org.apache.jasper.el; |
19 |
|
20 |
import java.util.List; |
21 |
|
22 |
import javax.el.ArrayELResolver; |
23 |
import javax.el.BeanELResolver; |
24 |
import javax.el.CompositeELResolver; |
25 |
import javax.el.ELContext; |
26 |
import javax.el.ELException; |
27 |
import javax.el.ELResolver; |
28 |
import javax.el.ListELResolver; |
29 |
import javax.el.MapELResolver; |
30 |
import javax.el.PropertyNotFoundException; |
31 |
import javax.el.ResourceBundleELResolver; |
32 |
import javax.servlet.jsp.el.ImplicitObjectELResolver; |
33 |
import javax.servlet.jsp.el.ScopedAttributeELResolver; |
34 |
|
35 |
import org.apache.el.lang.ELSupport; |
36 |
|
37 |
/* |
38 |
* Jasper-specific CompositeELResolver that optimizes certain functions to avoid unnecessary resolver calls. |
39 |
*/ |
40 |
public class JasperELResolver extends CompositeELResolver { |
41 |
|
42 |
private int size; |
43 |
private ELResolver[] resolvers; |
44 |
private int appResolversSize; |
45 |
|
46 |
public JasperELResolver(List<ELResolver> appResolvers) { |
47 |
appResolversSize = appResolvers.size(); |
48 |
resolvers = new ELResolver[7 /* 7 standard EL resolvers */ + appResolversSize]; |
49 |
size = resolvers.length; |
50 |
|
51 |
int index = 0; |
52 |
resolvers[index++] = new ImplicitObjectELResolver(); |
53 |
for (ELResolver appResolver : appResolvers) { |
54 |
resolvers[index++] = appResolver; |
55 |
} |
56 |
resolvers[index++] = new MapELResolver(); |
57 |
resolvers[index++] = new ResourceBundleELResolver(); |
58 |
resolvers[index++] = new ListELResolver(); |
59 |
resolvers[index++] = new ArrayELResolver(); |
60 |
resolvers[index++] = new BeanELResolver(); |
61 |
resolvers[index++] = new ScopedAttributeELResolver(); |
62 |
} |
63 |
|
64 |
@Override |
65 |
public synchronized void add(ELResolver elResolver) { |
66 |
super.add(elResolver); |
67 |
|
68 |
ELResolver[] nr = new ELResolver[size + 1]; |
69 |
System.arraycopy(resolvers, 0, nr, 0, size); |
70 |
nr[size] = elResolver; |
71 |
|
72 |
resolvers = nr; |
73 |
size ++; |
74 |
} |
75 |
|
76 |
@Override |
77 |
public Object getValue(ELContext context, Object base, Object property) |
78 |
throws NullPointerException, PropertyNotFoundException, ELException { |
79 |
context.setPropertyResolved(false); |
80 |
|
81 |
int start; |
82 |
Object result = null; |
83 |
|
84 |
if (base == null) { |
85 |
// call implicit and app resolvers |
86 |
int index = 1 /* implicit */ + appResolversSize; |
87 |
for (int i = 0; i < index; i++) { |
88 |
result = resolvers[i].getValue(context, base, property); |
89 |
if (context.isPropertyResolved()) { |
90 |
return result; |
91 |
} |
92 |
} |
93 |
// skip collection-based resolvers (map, resource, list, array, and bean) |
94 |
start = index + 5; |
95 |
} else { |
96 |
// skip implicit resolver only |
97 |
start = 1; |
98 |
} |
99 |
|
100 |
for (int i = start; i < size; i++) { |
101 |
result = resolvers[i].getValue(context, base, property); |
102 |
if (context.isPropertyResolved()) { |
103 |
return result; |
104 |
} |
105 |
} |
106 |
|
107 |
return null; |
108 |
} |
109 |
|
110 |
@Override |
111 |
public Object invoke(ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params) { |
112 |
String targetMethod = ELSupport.coerceToString(method); |
113 |
if (targetMethod.length() == 0) { |
114 |
throw new ELException(new NoSuchMethodException()); |
115 |
} |
116 |
|
117 |
context.setPropertyResolved(false); |
118 |
|
119 |
Object result = null; |
120 |
|
121 |
// skip implicit and call app resolvers |
122 |
int index = 1 /* implicit */ + appResolversSize; |
123 |
for (int i = 1; i < index; i++) { |
124 |
result = resolvers[i].invoke(context, base, targetMethod, paramTypes, params); |
125 |
if (context.isPropertyResolved()) { |
126 |
return result; |
127 |
} |
128 |
} |
129 |
|
130 |
// skip map, resource, list, and array resolvers |
131 |
index += 4; |
132 |
// call bean and the rest of resolvers |
133 |
for (int i = index; i < size; i++) { |
134 |
result = resolvers[i].invoke(context, base, targetMethod, paramTypes, params); |
135 |
if (context.isPropertyResolved()) { |
136 |
return result; |
137 |
} |
138 |
} |
139 |
|
140 |
return null; |
141 |
} |
142 |
|
143 |
} |
0 |
+ text/plain |
144 |
+ text/plain |
1 |
+ Date Revision |
145 |
+ Date Revision |
2 |
+ native |
146 |
+ native |