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