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