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