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.ResourceBundle; |
24 | |
import java.util.Map.Entry; |
25 | |
|
26 | |
import javax.el.ELContext; |
27 | |
import javax.el.PropertyNotFoundException; |
28 | |
import javax.el.PropertyNotWritableException; |
29 | |
import javax.faces.context.FacesContext; |
30 | |
|
31 | |
import org.apache.shale.test.mock.MockApplication12; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 1 | public class FacesResourceBundleELResolver extends AbstractELResolver { |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public Class getCommonPropertyType(ELContext context, Object base) { |
48 | |
|
49 | |
if (base != null) { |
50 | |
return null; |
51 | |
} else { |
52 | |
return String.class; |
53 | |
} |
54 | |
|
55 | |
} |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public Iterator getFeatureDescriptors(ELContext context, Object base) { |
66 | |
|
67 | |
if (base != null) { |
68 | |
return null; |
69 | |
} |
70 | |
|
71 | |
|
72 | |
List descriptors = new ArrayList(); |
73 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
74 | |
MockApplication12 application = |
75 | |
(MockApplication12) fcontext.getApplication(); |
76 | |
String key = null; |
77 | |
Object value = null; |
78 | |
|
79 | |
|
80 | |
Iterator entries = application.getResourceBundles().entrySet().iterator(); |
81 | |
while (entries.hasNext()) { |
82 | |
Entry entry = (Entry) entries.next(); |
83 | |
key = (String) entry.getKey(); |
84 | |
value = entry.getValue(); |
85 | |
descriptors.add(descriptor(key, key, "Resource Bundle " + key, |
86 | |
false, false, true, |
87 | |
ResourceBundle.class, true)); |
88 | |
} |
89 | |
|
90 | |
|
91 | |
return descriptors.iterator(); |
92 | |
|
93 | |
} |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public Class getType(ELContext context, Object base, Object property) { |
105 | |
|
106 | |
if (base != null) { |
107 | |
return null; |
108 | |
} |
109 | |
if (property == null) { |
110 | |
throw new PropertyNotFoundException("No property specified"); |
111 | |
} |
112 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
113 | |
ResourceBundle bundle = |
114 | |
fcontext.getApplication().getResourceBundle(fcontext, property.toString()); |
115 | |
if (bundle != null) { |
116 | |
context.setPropertyResolved(true); |
117 | |
return ResourceBundle.class; |
118 | |
} |
119 | |
return null; |
120 | |
|
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public Object getValue(ELContext context, Object base, Object property) { |
134 | |
|
135 | |
if (base != null) { |
136 | |
return null; |
137 | |
} |
138 | |
if (property == null) { |
139 | |
throw new PropertyNotFoundException("No property specified"); |
140 | |
} |
141 | |
|
142 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
143 | |
ResourceBundle bundle = |
144 | |
fcontext.getApplication().getResourceBundle(fcontext, property.toString()); |
145 | |
if (bundle != null) { |
146 | |
context.setPropertyResolved(true); |
147 | |
return bundle; |
148 | |
} |
149 | |
return null; |
150 | |
|
151 | |
} |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
public boolean isReadOnly(ELContext context, Object base, Object property) { |
163 | |
|
164 | |
if (base != null) { |
165 | |
return false; |
166 | |
} |
167 | |
if (property == null) { |
168 | |
throw new PropertyNotFoundException("No property specified"); |
169 | |
} |
170 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
171 | |
ResourceBundle bundle = |
172 | |
fcontext.getApplication().getResourceBundle(fcontext, property.toString()); |
173 | |
if (bundle != null) { |
174 | |
context.setPropertyResolved(true); |
175 | |
return true; |
176 | |
} |
177 | |
return false; |
178 | |
|
179 | |
} |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
public void setValue(ELContext context, Object base, Object property, Object value) { |
193 | |
|
194 | |
if (base != null) { |
195 | |
return; |
196 | |
} |
197 | |
if (property == null) { |
198 | |
throw new PropertyNotFoundException("No property specified"); |
199 | |
} |
200 | |
|
201 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
202 | |
ResourceBundle bundle = |
203 | |
fcontext.getApplication().getResourceBundle(fcontext, property.toString()); |
204 | |
if (bundle != null) { |
205 | |
context.setPropertyResolved(true); |
206 | |
throw new PropertyNotWritableException(property.toString()); |
207 | |
} |
208 | |
|
209 | |
} |
210 | |
|
211 | |
|
212 | |
} |