1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.shale.test.el; |
19 | |
|
20 | |
import java.util.ArrayList; |
21 | |
import java.util.Iterator; |
22 | |
import java.util.List; |
23 | |
import java.util.Map; |
24 | |
import java.util.Set; |
25 | |
import java.util.Map.Entry; |
26 | |
|
27 | |
import javax.el.ELContext; |
28 | |
import javax.el.PropertyNotFoundException; |
29 | |
import javax.faces.context.ExternalContext; |
30 | |
import javax.faces.context.FacesContext; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 1 | public class FacesScopedAttributeELResolver extends AbstractELResolver { |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public Class getCommonPropertyType(ELContext context, Object base) { |
47 | |
|
48 | |
if (base != null) { |
49 | |
return null; |
50 | |
} else { |
51 | |
return String.class; |
52 | |
} |
53 | |
|
54 | |
} |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public Iterator getFeatureDescriptors(ELContext context, Object base) { |
65 | |
|
66 | |
if (base != null) { |
67 | |
return null; |
68 | |
} |
69 | |
|
70 | |
|
71 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
72 | |
ExternalContext econtext = fcontext.getExternalContext(); |
73 | |
List descriptors = new ArrayList(); |
74 | |
Map map = null; |
75 | |
Set set = null; |
76 | |
Iterator items = null; |
77 | |
String key = null; |
78 | |
Object value = null; |
79 | |
|
80 | |
|
81 | |
set = econtext.getRequestMap().entrySet(); |
82 | |
items = set.iterator(); |
83 | |
while (items.hasNext()) { |
84 | |
Entry item = (Entry) items.next(); |
85 | |
key = (String) item.getKey(); |
86 | |
value = item.getValue(); |
87 | |
descriptors.add(descriptor(key, key, "Request Scope Attribute " + key, |
88 | |
false, false, true, value.getClass(), true)); |
89 | |
} |
90 | |
|
91 | |
|
92 | |
set = econtext.getSessionMap().entrySet(); |
93 | |
items = set.iterator(); |
94 | |
while (items.hasNext()) { |
95 | |
Entry item = (Entry) items.next(); |
96 | |
key = (String) item.getKey(); |
97 | |
value = item.getValue(); |
98 | |
descriptors.add(descriptor(key, key, "Session Scope Attribute " + key, |
99 | |
false, false, true, value.getClass(), true)); |
100 | |
} |
101 | |
|
102 | |
|
103 | |
set = econtext.getApplicationMap().entrySet(); |
104 | |
items = set.iterator(); |
105 | |
while (items.hasNext()) { |
106 | |
Entry item = (Entry) items.next(); |
107 | |
key = (String) item.getKey(); |
108 | |
value = item.getValue(); |
109 | |
descriptors.add(descriptor(key, key, "Application Scope Attribute " + key, |
110 | |
false, false, true, value.getClass(), true)); |
111 | |
} |
112 | |
|
113 | |
|
114 | |
return descriptors.iterator(); |
115 | |
|
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
public Class getType(ELContext context, Object base, Object property) { |
129 | |
|
130 | |
if (base != null) { |
131 | |
return null; |
132 | |
} |
133 | |
if (property == null) { |
134 | |
throw new PropertyNotFoundException("No property specified"); |
135 | |
} |
136 | |
context.setPropertyResolved(true); |
137 | |
return Object.class; |
138 | |
|
139 | |
} |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public Object getValue(ELContext context, Object base, Object property) { |
152 | |
|
153 | |
if (base != null) { |
154 | |
return null; |
155 | |
} |
156 | |
if (property == null) { |
157 | |
throw new PropertyNotFoundException("No property specified"); |
158 | |
} |
159 | |
|
160 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
161 | |
ExternalContext econtext = fcontext.getExternalContext(); |
162 | |
Object value = null; |
163 | |
value = econtext.getRequestMap().get(property); |
164 | |
if (value != null) { |
165 | |
context.setPropertyResolved(true); |
166 | |
return value; |
167 | |
} |
168 | |
value = econtext.getSessionMap().get(property); |
169 | |
if (value != null) { |
170 | |
context.setPropertyResolved(true); |
171 | |
return value; |
172 | |
} |
173 | |
value = econtext.getApplicationMap().get(property); |
174 | |
if (value != null) { |
175 | |
context.setPropertyResolved(true); |
176 | |
return value; |
177 | |
} |
178 | |
|
179 | |
return null; |
180 | |
|
181 | |
} |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
public boolean isReadOnly(ELContext context, Object base, Object property) { |
193 | |
|
194 | |
if (base == null) { |
195 | |
context.setPropertyResolved(true); |
196 | |
return false; |
197 | |
} |
198 | |
return false; |
199 | |
|
200 | |
} |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
public void setValue(ELContext context, Object base, Object property, Object value) { |
214 | |
|
215 | |
if (base != null) { |
216 | |
return; |
217 | |
} |
218 | |
if (property == null) { |
219 | |
throw new PropertyNotFoundException("No property specified"); |
220 | |
} |
221 | |
|
222 | |
context.setPropertyResolved(true); |
223 | |
String key = property.toString(); |
224 | |
Object result = null; |
225 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
226 | |
ExternalContext econtext = fcontext.getExternalContext(); |
227 | |
|
228 | |
if (econtext.getRequestMap().containsKey(property)) { |
229 | |
econtext.getRequestMap().put(key, value); |
230 | |
} else if (econtext.getSessionMap().containsKey(property)) { |
231 | |
econtext.getSessionMap().put(key, value); |
232 | |
} else if (econtext.getApplicationMap().containsKey(property)) { |
233 | |
econtext.getApplicationMap().put(key, value); |
234 | |
} else { |
235 | |
econtext.getRequestMap().put(key, value); |
236 | |
} |
237 | |
|
238 | |
} |
239 | |
|
240 | |
|
241 | |
} |