1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.resolver; |
16 |
| |
17 |
| import org.apache.commons.logging.Log; |
18 |
| import org.apache.hivemind.ApplicationRuntimeException; |
19 |
| import org.apache.hivemind.Resource; |
20 |
| import org.apache.tapestry.INamespace; |
21 |
| import org.apache.tapestry.IRequestCycle; |
22 |
| import org.apache.tapestry.PageNotFoundException; |
23 |
| import org.apache.tapestry.Tapestry; |
24 |
| import org.apache.tapestry.services.ComponentPropertySource; |
25 |
| import org.apache.tapestry.spec.ComponentSpecification; |
26 |
| import org.apache.tapestry.spec.IComponentSpecification; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| public class PageSpecificationResolverImpl extends AbstractSpecificationResolver implements |
61 |
| PageSpecificationResolver |
62 |
| { |
63 |
| |
64 |
| private Log _log; |
65 |
| |
66 |
| |
67 |
| private String _simpleName; |
68 |
| |
69 |
| |
70 |
| private INamespace _applicationNamespace; |
71 |
| |
72 |
| |
73 |
| private INamespace _frameworkNamespace; |
74 |
| |
75 |
| |
76 |
| |
77 |
| private ComponentPropertySource _componentPropertySource; |
78 |
| |
79 |
113
| public void initializeService()
|
80 |
| { |
81 |
113
| _applicationNamespace = getSpecificationSource().getApplicationNamespace();
|
82 |
113
| _frameworkNamespace = getSpecificationSource().getFrameworkNamespace();
|
83 |
| |
84 |
113
| super.initializeService();
|
85 |
| } |
86 |
| |
87 |
143
| protected void reset()
|
88 |
| { |
89 |
143
| _simpleName = null;
|
90 |
| |
91 |
143
| super.reset();
|
92 |
| } |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
143
| public void resolve(IRequestCycle cycle, String prefixedName)
|
103 |
| { |
104 |
143
| reset();
|
105 |
| |
106 |
143
| INamespace namespace = null;
|
107 |
| |
108 |
143
| int colonx = prefixedName.indexOf(':');
|
109 |
| |
110 |
143
| if (colonx > 0)
|
111 |
| { |
112 |
4
| _simpleName = prefixedName.substring(colonx + 1);
|
113 |
4
| String namespaceId = prefixedName.substring(0, colonx);
|
114 |
| |
115 |
4
| if (namespaceId.equals(INamespace.FRAMEWORK_NAMESPACE))
|
116 |
1
| namespace = _frameworkNamespace;
|
117 |
| else |
118 |
3
| namespace = _applicationNamespace.getChildNamespace(namespaceId);
|
119 |
| } |
120 |
| else |
121 |
| { |
122 |
139
| _simpleName = prefixedName;
|
123 |
| |
124 |
139
| namespace = _applicationNamespace;
|
125 |
| } |
126 |
| |
127 |
143
| setNamespace(namespace);
|
128 |
| |
129 |
143
| if (namespace.containsPage(_simpleName))
|
130 |
| { |
131 |
42
| setSpecification(namespace.getPageSpecification(_simpleName));
|
132 |
42
| return;
|
133 |
| } |
134 |
| |
135 |
| |
136 |
| |
137 |
101
| searchForPage(cycle);
|
138 |
| |
139 |
101
| if (getSpecification() == null)
|
140 |
2
| throw new PageNotFoundException(ResolverMessages.noSuchPage(_simpleName, namespace));
|
141 |
| } |
142 |
| |
143 |
141
| public String getSimplePageName()
|
144 |
| { |
145 |
141
| return _simpleName;
|
146 |
| } |
147 |
| |
148 |
101
| private void searchForPage(IRequestCycle cycle)
|
149 |
| { |
150 |
101
| INamespace namespace = getNamespace();
|
151 |
| |
152 |
101
| if (_log.isDebugEnabled())
|
153 |
8
| _log.debug(ResolverMessages.resolvingPage(_simpleName, namespace));
|
154 |
| |
155 |
101
| String expectedName = _simpleName + ".page";
|
156 |
| |
157 |
101
| Resource namespaceLocation = namespace.getSpecificationLocation();
|
158 |
| |
159 |
| |
160 |
| |
161 |
| |
162 |
| |
163 |
101
| if (found(namespaceLocation.getRelativeResource(expectedName)))
|
164 |
46
| return;
|
165 |
| |
166 |
55
| if (namespace.isApplicationNamespace())
|
167 |
| { |
168 |
| |
169 |
| |
170 |
| |
171 |
53
| if (found(getWebInfAppLocation().getRelativeResource(expectedName)))
|
172 |
1
| return;
|
173 |
| |
174 |
52
| if (found(getWebInfLocation().getRelativeResource(expectedName)))
|
175 |
1
| return;
|
176 |
| |
177 |
51
| if (found(getContextRoot().getRelativeResource(expectedName)))
|
178 |
1
| return;
|
179 |
| |
180 |
| |
181 |
| |
182 |
| |
183 |
50
| String templateName = _simpleName + "." + getTemplateExtension();
|
184 |
| |
185 |
50
| Resource templateResource = getContextRoot().getRelativeResource(templateName);
|
186 |
| |
187 |
50
| if (_log.isDebugEnabled())
|
188 |
2
| _log.debug(ResolverMessages.checkingResource(templateResource));
|
189 |
| |
190 |
50
| if (templateResource.getResourceURL() != null)
|
191 |
| { |
192 |
20
| setupImplicitPage(templateResource);
|
193 |
20
| return;
|
194 |
| } |
195 |
| |
196 |
| |
197 |
| |
198 |
30
| if (_frameworkNamespace.containsPage(_simpleName))
|
199 |
| { |
200 |
29
| if (_log.isDebugEnabled())
|
201 |
1
| _log.debug(ResolverMessages.foundFrameworkPage(_simpleName));
|
202 |
| |
203 |
29
| setNamespace(_frameworkNamespace);
|
204 |
| |
205 |
| |
206 |
| |
207 |
| |
208 |
| |
209 |
29
| setSpecification(_frameworkNamespace.getPageSpecification(_simpleName));
|
210 |
29
| return;
|
211 |
| } |
212 |
| } |
213 |
| |
214 |
| |
215 |
| |
216 |
| |
217 |
3
| IComponentSpecification specification = getDelegate().findPageSpecification(
|
218 |
| cycle, |
219 |
| namespace, |
220 |
| _simpleName); |
221 |
| |
222 |
3
| if (specification != null)
|
223 |
| { |
224 |
1
| setSpecification(specification);
|
225 |
1
| install();
|
226 |
| } |
227 |
| } |
228 |
| |
229 |
20
| private void setupImplicitPage(Resource resource)
|
230 |
| { |
231 |
20
| if (_log.isDebugEnabled())
|
232 |
1
| _log.debug(ResolverMessages.foundHTMLTemplate(resource));
|
233 |
| |
234 |
| |
235 |
| |
236 |
| |
237 |
20
| IComponentSpecification specification = new ComponentSpecification();
|
238 |
20
| specification.setPageSpecification(true);
|
239 |
20
| specification.setSpecificationLocation(resource);
|
240 |
| |
241 |
20
| setSpecification(specification);
|
242 |
| |
243 |
20
| install();
|
244 |
| } |
245 |
| |
246 |
257
| private boolean found(Resource resource)
|
247 |
| { |
248 |
257
| if (_log.isDebugEnabled())
|
249 |
20
| _log.debug(ResolverMessages.checkingResource(resource));
|
250 |
| |
251 |
257
| if (resource.getResourceURL() == null)
|
252 |
208
| return false;
|
253 |
| |
254 |
49
| setSpecification(getSpecificationSource().getPageSpecification(resource));
|
255 |
| |
256 |
49
| install();
|
257 |
| |
258 |
49
| return true;
|
259 |
| } |
260 |
| |
261 |
70
| private void install()
|
262 |
| { |
263 |
70
| INamespace namespace = getNamespace();
|
264 |
70
| IComponentSpecification specification = getSpecification();
|
265 |
| |
266 |
70
| if (_log.isDebugEnabled())
|
267 |
4
| _log.debug(ResolverMessages.installingPage(_simpleName, namespace, specification));
|
268 |
| |
269 |
70
| namespace.installPageSpecification(_simpleName, specification);
|
270 |
| } |
271 |
| |
272 |
| |
273 |
| |
274 |
| |
275 |
| |
276 |
| |
277 |
| |
278 |
50
| private String getTemplateExtension()
|
279 |
| { |
280 |
50
| return _componentPropertySource.getNamespaceProperty(
|
281 |
| getNamespace(), |
282 |
| Tapestry.TEMPLATE_EXTENSION_PROPERTY); |
283 |
| } |
284 |
| |
285 |
| |
286 |
| |
287 |
110
| public void setLog(Log log)
|
288 |
| { |
289 |
110
| _log = log;
|
290 |
| } |
291 |
| |
292 |
| |
293 |
104
| public void setComponentPropertySource(ComponentPropertySource componentPropertySource)
|
294 |
| { |
295 |
104
| _componentPropertySource = componentPropertySource;
|
296 |
| } |
297 |
| } |