1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.page;
18
19 import java.io.Serializable;
20 import java.util.Collection;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.ListIterator;
24 import java.util.Map;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.jetspeed.aggregator.PortletContent;
29 import org.apache.jetspeed.decoration.Decoration;
30 import org.apache.jetspeed.om.common.SecurityConstraint;
31 import org.apache.jetspeed.om.common.SecurityConstraints;
32 import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
33
34 public class ContentFragmentImpl implements ContentFragment
35 {
36
37
38 private final Fragment fragment;
39 private StringBuffer overridenContent;
40 private PortletContent portletContent;
41 private List contentFragments;
42 private static final Log log = LogFactory.getLog(ContentFragmentImpl.class);
43 private final Map cachedFragments;
44 private Decoration decoration;
45
46
47 public ContentFragmentImpl(Fragment fragment, Map cachedFagments)
48 {
49 this.fragment = fragment;
50 this.cachedFragments = cachedFagments;
51 }
52
53
54
55
56 public List getContentFragments()
57 {
58 if(contentFragments == null)
59 {
60 contentFragments = new ContentFragmentList();
61 }
62 return contentFragments;
63 }
64
65
66
67
68 public List getFragments()
69 {
70 return getContentFragments();
71 }
72
73
74
75
76 public String getOverriddenContent()
77 {
78 return overridenContent != null ? overridenContent.toString() : null;
79 }
80
81
82
83
84 public String getRenderedContent() throws IllegalStateException
85 {
86 if(overridenContent != null)
87 {
88 return overridenContent.toString();
89 }
90
91
92 if (portletContent != null)
93 {
94
95
96 synchronized (portletContent)
97 {
98 if (portletContent.isComplete())
99 {
100 return portletContent.getContent();
101 }
102 else
103 {
104 try
105 {
106 log.debug("Waiting on content for Fragment " + getId());
107 portletContent.wait();
108 return portletContent.getContent();
109 }
110 catch (InterruptedException e)
111 {
112 return e.getMessage();
113 }
114 finally
115 {
116 log.debug("Been notified that Faragment " + getId() + " is complete");
117 }
118 }
119 }
120 }
121 else
122 {
123 throw new IllegalStateException("You cannot invoke getRenderedContent() until the content has been set.");
124 }
125 }
126
127
128
129
130 public void overrideRenderedContent(String contnent)
131 {
132 if ( contnent != null )
133 {
134 if(overridenContent == null)
135 {
136 overridenContent = new StringBuffer();
137 }
138
139 if (!contnent.equals(overridenContent.toString()))
140 {
141 overridenContent.append(contnent);
142 }
143 }
144
145 }
146
147
148
149
150 public void setPortletContent(PortletContent portletContent)
151 {
152 this.portletContent = portletContent;
153 }
154
155
156
157
158 public String getDecorator()
159 {
160
161 return fragment.getDecorator();
162 }
163
164
165
166
167 public String getName()
168 {
169
170 return fragment.getName();
171 }
172
173
174
175
176 public Map getProperties()
177 {
178
179 return fragment.getProperties();
180 }
181
182
183
184
185 public String getProperty(String propName)
186 {
187
188 return fragment.getProperty(propName);
189 }
190
191
192
193
194 public int getIntProperty(String propName)
195 {
196
197 return fragment.getIntProperty(propName);
198 }
199
200
201
202
203 public float getFloatProperty(String propName)
204 {
205
206 return fragment.getFloatProperty(propName);
207 }
208
209
210
211
212 public String getSkin()
213 {
214
215 return fragment.getSkin();
216 }
217
218
219
220
221 public String getState()
222 {
223
224 return fragment.getState();
225 }
226
227
228
229
230 public String getMode()
231 {
232
233 return fragment.getMode();
234 }
235
236
237
238
239 public String getType()
240 {
241
242 return fragment.getType();
243 }
244
245
246
247
248 public boolean isReference()
249 {
250
251 return fragment.isReference();
252 }
253
254
255
256
257 public void setDecorator(String decoratorName)
258 {
259
260 fragment.setDecorator(decoratorName);
261 }
262
263
264
265
266 public void setName(String name)
267 {
268
269 fragment.setName(name);
270 }
271
272
273
274
275 public int getLayoutRow()
276 {
277 return fragment.getLayoutRow();
278 }
279
280
281
282
283 public int getLayoutColumn()
284 {
285 return fragment.getLayoutColumn();
286 }
287
288
289
290
291 public String getLayoutSizes()
292 {
293 return fragment.getLayoutSizes();
294 }
295
296
297
298
299 public float getLayoutX()
300 {
301 return fragment.getLayoutX();
302 }
303
304
305
306
307 public float getLayoutY()
308 {
309 return fragment.getLayoutY();
310 }
311
312
313
314
315 public float getLayoutZ()
316 {
317 return fragment.getLayoutZ();
318 }
319
320
321
322
323 public float getLayoutWidth()
324 {
325 return fragment.getLayoutWidth();
326 }
327
328
329
330
331 public float getLayoutHeight()
332 {
333 return fragment.getLayoutHeight();
334 }
335
336
337
338
339 public void setLayoutRow(int row)
340 {
341 fragment.setLayoutRow(row);
342 }
343
344
345
346
347 public void setLayoutColumn(int column)
348 {
349 fragment.setLayoutColumn(column);
350 }
351
352
353
354
355 public void setLayoutSizes(String sizes)
356 {
357 fragment.setLayoutSizes(sizes);
358 }
359
360
361
362
363 public void setLayoutX(float x)
364 {
365 fragment.setLayoutX(x);
366 }
367
368
369
370
371 public void setLayoutY(float y)
372 {
373 fragment.setLayoutY(y);
374 }
375
376
377
378
379 public void setLayoutZ(float z)
380 {
381 fragment.setLayoutZ(z);
382 }
383
384
385
386
387 public void setLayoutWidth(float width)
388 {
389 fragment.setLayoutWidth(width);
390 }
391
392
393
394
395 public void setLayoutHeight(float height)
396 {
397 fragment.setLayoutHeight(height);
398 }
399
400
401
402
403 public void setSkin(String skinName)
404 {
405
406 fragment.setSkin(skinName);
407 }
408
409
410
411
412 public void setState(String state)
413 {
414
415 fragment.setState(state);
416 }
417
418
419
420
421 public void setMode(String mode)
422 {
423
424 fragment.setMode(mode);
425 }
426
427
428
429
430 public void setType(String type)
431 {
432
433 fragment.setType(type);
434 }
435
436
437
438
439 public String getId()
440 {
441
442 return fragment.getId();
443 }
444
445
446
447
448 public String getShortTitle()
449 {
450
451 return fragment.getShortTitle();
452 }
453
454
455
456
457 public String getTitle()
458 {
459
460 return fragment.getTitle();
461 }
462
463
464
465
466 public void setShortTitle(String title)
467 {
468
469 fragment.setShortTitle(title);
470 }
471
472
473
474
475 public void setTitle(String title)
476 {
477
478 fragment.setTitle(title);
479 }
480
481
482
483
484 public void checkAccess(String actions) throws SecurityException
485 {
486
487 fragment.checkAccess(actions);
488 }
489
490
491
492
493 public void checkConstraints(String actions) throws SecurityException
494 {
495
496 fragment.checkConstraints(actions);
497 }
498
499
500
501
502 public void checkPermissions(int mask) throws SecurityException
503 {
504
505 fragment.checkPermissions(mask);
506 }
507
508
509
510
511 public boolean getConstraintsEnabled()
512 {
513
514 return fragment.getConstraintsEnabled();
515 }
516
517
518
519
520 public boolean getPermissionsEnabled()
521 {
522
523 return fragment.getPermissionsEnabled();
524 }
525
526
527
528
529 public SecurityConstraints getSecurityConstraints()
530 {
531
532 return fragment.getSecurityConstraints();
533 }
534
535
536
537
538 public SecurityConstraints newSecurityConstraints()
539 {
540
541 return fragment.newSecurityConstraints();
542 }
543
544
545
546
547 public SecurityConstraint newSecurityConstraint()
548 {
549
550 return fragment.newSecurityConstraint();
551 }
552
553
554
555
556 public void setSecurityConstraints(SecurityConstraints constraints)
557 {
558 fragment.setSecurityConstraints(constraints);
559 }
560
561
562 /***
563 * Checks the ContentFragment cache for a ContentFragment
564 * that matches the <code>Id</code> of this fragment. If
565 * one is found, it returned. If no matches are found, a new
566 * <code>ContentFragment</code> represnentive of the {@link Fragment}
567 * argument is subsequently created, stored into the cahce and returned.
568 *
569 * @param f
570 * @return ContentFrament
571 */
572 protected ContentFragment getContentFragment(Fragment f)
573 {
574 ContentFragment cf;
575 if(cachedFragments.containsKey(f.getId()))
576 {
577 cf = (ContentFragment) cachedFragments.get(f.getId());
578 }
579 else
580 {
581 cf = new ContentFragmentImpl(f, cachedFragments);
582 cachedFragments.put(f.getId(), cf);
583 }
584 return cf;
585 }
586
587
588 protected final class ContentFragmentList implements List, Serializable
589 {
590 private List baseList = fragment.getFragments();
591
592
593
594
595 public void add(int index, Object element)
596 {
597 if (element instanceof ContentFragmentImpl)
598 element = ((ContentFragmentImpl)element).fragment;
599 baseList.add(index, element);
600 }
601
602
603
604
605 public boolean add(Object o)
606 {
607 if (o instanceof ContentFragmentImpl)
608 o = ((ContentFragmentImpl)o).fragment;
609 return baseList.add(o);
610 }
611
612
613
614
615 public boolean addAll(int index, Collection c)
616 {
617
618 return baseList.addAll(index, c);
619 }
620
621
622
623
624 public boolean addAll(Collection c)
625 {
626
627 return baseList.addAll(c);
628 }
629
630
631
632
633 public void clear()
634 {
635
636 baseList.clear();
637 }
638
639
640
641
642 public boolean contains(Object o)
643 {
644
645 return baseList.contains(o);
646 }
647
648
649
650
651 public boolean containsAll(Collection c)
652 {
653
654 return baseList.containsAll(c);
655 }
656
657
658
659
660 public boolean equals(Object o)
661 {
662
663 return baseList.equals(o);
664 }
665
666
667
668
669 public Object get(int index)
670 {
671 Fragment f= (Fragment) baseList.get(index);
672 return getContentFragment(f);
673 }
674
675
676
677
678 public int hashCode()
679 {
680
681 return baseList.hashCode();
682 }
683
684
685
686
687 public int indexOf(Object o)
688 {
689
690 return baseList.indexOf(o);
691 }
692
693
694
695
696 public boolean isEmpty()
697 {
698
699 return baseList.isEmpty();
700 }
701
702
703
704
705 public Iterator iterator()
706 {
707 return duplicateList().iterator();
708 }
709
710
711
712
713 public int lastIndexOf(Object o)
714 {
715
716 return baseList.lastIndexOf(o);
717 }
718
719
720
721
722 public ListIterator listIterator()
723 {
724 return duplicateList().listIterator();
725 }
726
727
728
729
730 public ListIterator listIterator(int index)
731 {
732 return duplicateList().listIterator(index);
733 }
734
735
736
737
738 public Object remove(int index)
739 {
740
741 return baseList.remove(index);
742 }
743
744
745
746
747 public boolean remove(Object o)
748 {
749
750 return baseList.remove(o);
751 }
752
753
754
755
756 public boolean removeAll(Collection c)
757 {
758
759 return baseList.removeAll(c);
760 }
761
762
763
764
765 public boolean retainAll(Collection c)
766 {
767
768 return baseList.retainAll(c);
769 }
770
771
772
773
774 public Object set(int index, Object element)
775 {
776
777 return baseList.set(index, element);
778 }
779
780
781
782
783 public int size()
784 {
785
786 return baseList.size();
787 }
788
789
790
791
792 public List subList(int fromIndex, int toIndex)
793 {
794 return duplicateList().subList(fromIndex, toIndex);
795 }
796
797
798
799
800
801
802 public Object[] toArray()
803 {
804 return duplicateList().toArray();
805 }
806
807
808
809
810 public Object[] toArray(Object[] a)
811 {
812 return duplicateList().toArray(a);
813 }
814
815 private List duplicateList()
816 {
817 List rFragList = DatabasePageManagerUtils.createList();
818 for(int i=0; i < baseList.size(); i++)
819 {
820 Fragment f = (Fragment)baseList.get(i);
821 ContentFragment cf = getContentFragment(f);
822 rFragList.add(cf);
823 }
824 return rFragList;
825 }
826
827
828
829 }
830
831
832
833
834 public List getPreferences()
835 {
836 return fragment.getPreferences();
837 }
838
839 public Decoration getDecoration()
840 {
841 return decoration;
842 }
843
844
845
846
847 public void setPreferences(List preferences)
848 {
849 fragment.setPreferences(preferences);
850 }
851
852
853 public void setDecoration(Decoration decoration)
854 {
855 this.decoration = decoration;
856
857 }
858
859 }