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