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