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