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