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