1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry; |
16 |
|
|
17 |
|
import org.apache.commons.logging.Log; |
18 |
|
import org.apache.commons.logging.LogFactory; |
19 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
20 |
|
import org.apache.tapestry.engine.NullWriter; |
21 |
|
import org.apache.tapestry.event.*; |
22 |
|
import org.apache.tapestry.services.ResponseBuilder; |
23 |
|
import org.apache.tapestry.util.StringSplitter; |
24 |
|
|
25 |
|
import javax.swing.event.EventListenerList; |
26 |
|
import java.util.EventListener; |
27 |
|
import java.util.Locale; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
public abstract class AbstractPage extends BaseComponent implements IPage |
37 |
|
{ |
38 |
7 |
private static final Log LOG = LogFactory.getLog(AbstractPage.class); |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private ChangeObserver _changeObserver; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private IEngine _engine; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
private String _pageName; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
private IRequestCycle _requestCycle; |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
private Locale _locale; |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
private EventListenerList _listenerList; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
private String _outputEncoding; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
private boolean _hasForms; |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
private boolean _hasWidgets; |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
public AbstractPage() |
111 |
32 |
{ |
112 |
32 |
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
public void detach() |
128 |
|
{ |
129 |
3 |
Tapestry.addMethodInvocation(Tapestry.ABSTRACTPAGE_DETACH_METHOD_ID); |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
3 |
_changeObserver = null; |
135 |
|
|
136 |
3 |
firePageDetached(); |
137 |
|
|
138 |
3 |
_engine = null; |
139 |
3 |
_requestCycle = null; |
140 |
3 |
} |
141 |
|
|
142 |
|
public IEngine getEngine() |
143 |
|
{ |
144 |
0 |
return _engine; |
145 |
|
} |
146 |
|
|
147 |
|
public ChangeObserver getChangeObserver() |
148 |
|
{ |
149 |
0 |
return _changeObserver; |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
public String getExtendedId() |
157 |
|
{ |
158 |
0 |
return _pageName; |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
public String getIdPath() |
166 |
|
{ |
167 |
2 |
return null; |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
public Locale getLocale() |
176 |
|
{ |
177 |
40 |
return _locale; |
178 |
|
} |
179 |
|
|
180 |
|
public void setLocale(Locale value) |
181 |
|
{ |
182 |
20 |
if (_locale != null) |
183 |
0 |
throw new ApplicationRuntimeException(Tapestry |
184 |
|
.getMessage("AbstractPage.attempt-to-change-locale")); |
185 |
|
|
186 |
20 |
_locale = value; |
187 |
20 |
} |
188 |
|
|
189 |
|
public IComponent getNestedComponent(String path) |
190 |
|
{ |
191 |
|
StringSplitter splitter; |
192 |
|
IComponent current; |
193 |
|
String[] elements; |
194 |
|
int i; |
195 |
|
|
196 |
0 |
if (path == null) |
197 |
0 |
return this; |
198 |
|
|
199 |
0 |
splitter = new StringSplitter('.'); |
200 |
0 |
current = this; |
201 |
|
|
202 |
0 |
elements = splitter.splitToArray(path); |
203 |
0 |
for (i = 0; i < elements.length; i++) |
204 |
|
{ |
205 |
0 |
current = current.getComponent(elements[i]); |
206 |
|
} |
207 |
|
|
208 |
0 |
return current; |
209 |
|
|
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
public void attach(IEngine engine, IRequestCycle cycle) |
220 |
|
{ |
221 |
4 |
if (_engine != null) |
222 |
0 |
LOG.error(this + " attach(" + engine + "), but engine = " + _engine); |
223 |
|
|
224 |
4 |
_engine = engine; |
225 |
4 |
_requestCycle = cycle; |
226 |
4 |
} |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
public void renderPage(ResponseBuilder builder, IRequestCycle cycle) |
241 |
|
{ |
242 |
|
try |
243 |
|
{ |
244 |
6 |
firePageBeginRender(); |
245 |
|
|
246 |
6 |
if (!cycle.isRewinding()) |
247 |
0 |
cycle.commitPageChanges(); |
248 |
|
|
249 |
6 |
builder.render(cycle.isRewinding() ? NullWriter.getSharedInstance() : null, this, cycle); |
250 |
|
} |
251 |
|
finally |
252 |
|
{ |
253 |
6 |
firePageEndRender(); |
254 |
6 |
} |
255 |
6 |
} |
256 |
|
|
257 |
|
public void setChangeObserver(ChangeObserver value) |
258 |
|
{ |
259 |
0 |
_changeObserver = value; |
260 |
0 |
} |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
public void setPageName(String pageName) |
265 |
|
{ |
266 |
2 |
if (_pageName != null) |
267 |
0 |
throw new ApplicationRuntimeException(Tapestry |
268 |
|
.getMessage("AbstractPage.attempt-to-change-name")); |
269 |
|
|
270 |
2 |
_pageName = pageName; |
271 |
2 |
} |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
public void validate(IRequestCycle cycle) |
278 |
|
{ |
279 |
3 |
Tapestry.addMethodInvocation(Tapestry.ABSTRACTPAGE_VALIDATE_METHOD_ID); |
280 |
|
|
281 |
3 |
firePageValidate(); |
282 |
3 |
} |
283 |
|
|
284 |
|
public IRequestCycle getRequestCycle() |
285 |
|
{ |
286 |
1 |
return _requestCycle; |
287 |
|
} |
288 |
|
|
289 |
|
public void addPageDetachListener(PageDetachListener listener) |
290 |
|
{ |
291 |
1 |
addListener(PageDetachListener.class, listener); |
292 |
1 |
} |
293 |
|
|
294 |
|
private void addListener(Class listenerClass, EventListener listener) |
295 |
|
{ |
296 |
5 |
if (_listenerList == null) |
297 |
5 |
_listenerList = new EventListenerList(); |
298 |
|
|
299 |
5 |
_listenerList.add(listenerClass, listener); |
300 |
5 |
} |
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
private void removeListener(Class listenerClass, EventListener listener) |
307 |
|
{ |
308 |
5 |
if (_listenerList != null) |
309 |
5 |
_listenerList.remove(listenerClass, listener); |
310 |
5 |
} |
311 |
|
|
312 |
|
|
313 |
|
public void addPageBeginRenderListener(PageBeginRenderListener listener) |
314 |
|
{ |
315 |
1 |
addListener(PageBeginRenderListener.class, listener); |
316 |
1 |
} |
317 |
|
|
318 |
|
|
319 |
|
public void addPageEndRenderListener(PageEndRenderListener listener) |
320 |
|
{ |
321 |
1 |
addListener(PageEndRenderListener.class, listener); |
322 |
1 |
} |
323 |
|
|
324 |
|
|
325 |
|
public void removePageBeginRenderListener(PageBeginRenderListener listener) |
326 |
|
{ |
327 |
1 |
removeListener(PageBeginRenderListener.class, listener); |
328 |
1 |
} |
329 |
|
|
330 |
|
|
331 |
|
public void removePageEndRenderListener(PageEndRenderListener listener) |
332 |
|
{ |
333 |
1 |
removeListener(PageEndRenderListener.class, listener); |
334 |
1 |
} |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
public void firePageAttached() |
341 |
|
{ |
342 |
1 |
if (_listenerList == null) |
343 |
0 |
return; |
344 |
|
|
345 |
1 |
PageEvent event = null; |
346 |
1 |
Object[] listeners = _listenerList.getListenerList(); |
347 |
|
|
348 |
2 |
for(int i = listeners.length-2; i >= 0; i -= 2) |
349 |
|
{ |
350 |
1 |
if (listeners[i] == PageAttachListener.class) |
351 |
|
{ |
352 |
1 |
PageAttachListener l = (PageAttachListener) listeners[i + 1]; |
353 |
|
|
354 |
1 |
if (event == null) |
355 |
1 |
event = new PageEvent(this, _requestCycle); |
356 |
|
|
357 |
1 |
l.pageAttached(event); |
358 |
|
} |
359 |
|
} |
360 |
1 |
} |
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
protected void firePageDetached() |
367 |
|
{ |
368 |
3 |
if (_listenerList == null) |
369 |
1 |
return; |
370 |
|
|
371 |
2 |
PageEvent event = null; |
372 |
2 |
Object[] listeners = _listenerList.getListenerList(); |
373 |
|
|
374 |
3 |
for (int i = 0; i < listeners.length; i += 2) |
375 |
|
{ |
376 |
1 |
if (listeners[i] == PageDetachListener.class) |
377 |
|
{ |
378 |
1 |
PageDetachListener l = (PageDetachListener) listeners[i + 1]; |
379 |
|
|
380 |
1 |
if (event == null) |
381 |
1 |
event = new PageEvent(this, _requestCycle); |
382 |
|
|
383 |
1 |
l.pageDetached(event); |
384 |
|
} |
385 |
|
} |
386 |
2 |
} |
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
protected void firePageBeginRender() |
393 |
|
{ |
394 |
6 |
if (_listenerList == null) |
395 |
2 |
return; |
396 |
|
|
397 |
4 |
PageEvent event = null; |
398 |
4 |
Object[] listeners = _listenerList.getListenerList(); |
399 |
|
|
400 |
6 |
for(int i = listeners.length-2; i >= 0; i -= 2) |
401 |
|
{ |
402 |
2 |
if (listeners[i] == PageBeginRenderListener.class) |
403 |
|
{ |
404 |
1 |
PageBeginRenderListener l = (PageBeginRenderListener)listeners[i + 1]; |
405 |
|
|
406 |
1 |
if (event == null) |
407 |
1 |
event = new PageEvent(this, _requestCycle); |
408 |
|
|
409 |
1 |
l.pageBeginRender(event); |
410 |
|
} |
411 |
|
} |
412 |
4 |
} |
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
|
418 |
|
protected void firePageEndRender() |
419 |
|
{ |
420 |
6 |
if (_listenerList == null) |
421 |
2 |
return; |
422 |
|
|
423 |
4 |
PageEvent event = null; |
424 |
4 |
Object[] listeners = _listenerList.getListenerList(); |
425 |
|
|
426 |
6 |
for (int i = 0; i < listeners.length; i += 2) |
427 |
|
{ |
428 |
2 |
if (listeners[i] == PageEndRenderListener.class) |
429 |
|
{ |
430 |
1 |
PageEndRenderListener l = (PageEndRenderListener) listeners[i + 1]; |
431 |
|
|
432 |
1 |
if (event == null) |
433 |
1 |
event = new PageEvent(this, _requestCycle); |
434 |
|
|
435 |
1 |
l.pageEndRender(event); |
436 |
|
} |
437 |
|
} |
438 |
4 |
} |
439 |
|
|
440 |
|
|
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
public void removePageDetachListener(PageDetachListener listener) |
445 |
|
{ |
446 |
1 |
removeListener(PageDetachListener.class, listener); |
447 |
1 |
} |
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
public void beginPageRender() |
452 |
|
{ |
453 |
0 |
firePageBeginRender(); |
454 |
0 |
} |
455 |
|
|
456 |
|
|
457 |
|
|
458 |
|
public void endPageRender() |
459 |
|
{ |
460 |
0 |
firePageEndRender(); |
461 |
0 |
} |
462 |
|
|
463 |
|
protected void cleanupAfterRender(IRequestCycle cycle) |
464 |
|
{ |
465 |
0 |
} |
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
public String getPageName() |
470 |
|
{ |
471 |
2 |
return _pageName; |
472 |
|
} |
473 |
|
|
474 |
|
public void addPageValidateListener(PageValidateListener listener) |
475 |
|
{ |
476 |
1 |
addListener(PageValidateListener.class, listener); |
477 |
1 |
} |
478 |
|
|
479 |
|
public void removePageValidateListener(PageValidateListener listener) |
480 |
|
{ |
481 |
1 |
removeListener(PageValidateListener.class, listener); |
482 |
1 |
} |
483 |
|
|
484 |
|
|
485 |
|
public void addPageAttachListener(PageAttachListener listener) |
486 |
|
{ |
487 |
1 |
addListener(PageAttachListener.class, listener); |
488 |
1 |
} |
489 |
|
|
490 |
|
|
491 |
|
public void removePageAttachListener(PageAttachListener listener) |
492 |
|
{ |
493 |
1 |
removeListener(PageAttachListener.class, listener); |
494 |
1 |
} |
495 |
|
|
496 |
|
protected void firePageValidate() |
497 |
|
{ |
498 |
3 |
if (_listenerList == null) |
499 |
1 |
return; |
500 |
|
|
501 |
2 |
PageEvent event = null; |
502 |
2 |
Object[] listeners = _listenerList.getListenerList(); |
503 |
|
|
504 |
3 |
for (int i = 0; i < listeners.length; i += 2) |
505 |
|
{ |
506 |
1 |
if (listeners[i] == PageValidateListener.class) |
507 |
|
{ |
508 |
1 |
PageValidateListener l = (PageValidateListener) listeners[i + 1]; |
509 |
|
|
510 |
1 |
if (event == null) |
511 |
1 |
event = new PageEvent(this, _requestCycle); |
512 |
|
|
513 |
1 |
l.pageValidate(event); |
514 |
|
} |
515 |
|
} |
516 |
2 |
} |
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
|
522 |
|
|
523 |
|
|
524 |
|
protected String getOutputEncoding() |
525 |
|
{ |
526 |
0 |
if (_outputEncoding == null) |
527 |
0 |
_outputEncoding = getEngine().getOutputEncoding(); |
528 |
|
|
529 |
0 |
return _outputEncoding; |
530 |
|
} |
531 |
|
|
532 |
|
public boolean hasFormComponents() |
533 |
|
{ |
534 |
0 |
return _hasForms; |
535 |
|
} |
536 |
|
|
537 |
|
public void setHasFormComponents(boolean value) |
538 |
|
{ |
539 |
0 |
_hasForms = value; |
540 |
0 |
} |
541 |
|
|
542 |
|
public boolean hasWidgets() |
543 |
|
{ |
544 |
0 |
return _hasWidgets; |
545 |
|
} |
546 |
|
|
547 |
|
public void setHasWidgets(boolean value) |
548 |
|
{ |
549 |
0 |
_hasWidgets = value; |
550 |
0 |
} |
551 |
|
} |