1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.decoration; |
18 |
|
|
19 |
|
import java.io.Serializable; |
20 |
|
import java.util.ArrayList; |
21 |
|
import java.util.Collection; |
22 |
|
import java.util.Collections; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.Iterator; |
25 |
|
import java.util.LinkedHashSet; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Map; |
28 |
|
import java.util.Set; |
29 |
|
|
30 |
|
import org.apache.jetspeed.om.page.ContentPage; |
31 |
|
import org.apache.jetspeed.om.page.Fragment; |
32 |
|
import org.apache.jetspeed.om.page.Page; |
33 |
|
import org.apache.jetspeed.request.RequestContext; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
public class PageTheme implements Theme, Serializable |
43 |
|
{ |
44 |
|
private transient Page page; |
45 |
|
private transient DecorationFactory decorationFactory; |
46 |
|
private transient RequestContext requestContext; |
47 |
|
private final Set styleSheets; |
48 |
|
private final LayoutDecoration layoutDecoration; |
49 |
|
private final Map fragmentDecorations; |
50 |
|
private final Collection portletDecorationNames; |
51 |
0 |
private boolean invalidated = false; |
52 |
|
|
53 |
|
public PageTheme(Page page, DecorationFactory decorationFactory, RequestContext requestContext) |
54 |
0 |
{ |
55 |
0 |
this.page = page; |
56 |
0 |
this.decorationFactory = decorationFactory; |
57 |
0 |
this.requestContext = requestContext; |
58 |
0 |
this.styleSheets = new LinkedHashSet(); |
59 |
0 |
this.fragmentDecorations = new HashMap(); |
60 |
|
|
61 |
0 |
boolean isDesktopEnabled = decorationFactory.isDesktopEnabled( requestContext ); |
62 |
0 |
HashMap portletDecorationNames = new HashMap(); |
63 |
0 |
this.layoutDecoration = (LayoutDecoration)setupFragmentDecorations( page.getRootFragment(), true, portletDecorationNames, isDesktopEnabled ); |
64 |
|
|
65 |
0 |
if ( isDesktopEnabled ) |
66 |
|
{ |
67 |
0 |
String defaultDesktopPortletDecoration = decorationFactory.getDefaultDesktopPortletDecoration(); |
68 |
0 |
if ( defaultDesktopPortletDecoration != null && defaultDesktopPortletDecoration.length() > 0 ) |
69 |
|
{ |
70 |
0 |
if ( portletDecorationNames.get( defaultDesktopPortletDecoration ) == null ) |
71 |
|
{ |
72 |
0 |
portletDecorationNames.put( defaultDesktopPortletDecoration, defaultDesktopPortletDecoration ); |
73 |
|
} |
74 |
|
} |
75 |
|
} |
76 |
0 |
this.portletDecorationNames = Collections.unmodifiableCollection( new ArrayList( portletDecorationNames.keySet() ) ); |
77 |
0 |
} |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
private Decoration setupFragmentDecorations( Fragment fragment, boolean isRootLayout, HashMap portletDecorationNames, class="keyword">boolean isDesktopEnabled ) |
89 |
|
{ |
90 |
|
|
91 |
0 |
Decoration decoration = decorationFactory.getDecoration( page, fragment, requestContext ); |
92 |
|
|
93 |
0 |
fragmentDecorations.put( fragment.getId(), decoration ); |
94 |
0 |
boolean isPortlet = ( ! isRootLayout && fragment.getType().equals( Fragment.PORTLET ) ); |
95 |
|
|
96 |
0 |
if ( isPortlet || isRootLayout ) |
97 |
|
{ |
98 |
0 |
String commonStyleSheet = decoration.getStyleSheet(); |
99 |
0 |
if ( commonStyleSheet != null ) |
100 |
|
{ |
101 |
0 |
styleSheets.add( commonStyleSheet ); |
102 |
|
} |
103 |
0 |
if ( isDesktopEnabled ) |
104 |
|
{ |
105 |
0 |
String desktopStyleSheet = decoration.getStyleSheetDesktop(); |
106 |
0 |
if ( desktopStyleSheet != null ) |
107 |
|
{ |
108 |
0 |
styleSheets.add( desktopStyleSheet ); |
109 |
|
} |
110 |
0 |
} |
111 |
|
else |
112 |
|
{ |
113 |
0 |
String portalStyleSheet = decoration.getStyleSheetPortal(); |
114 |
0 |
if ( portalStyleSheet != null ) |
115 |
|
{ |
116 |
0 |
styleSheets.add( portalStyleSheet ); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
0 |
if ( isPortlet ) |
121 |
|
{ |
122 |
0 |
portletDecorationNames.put( decoration.getName(), decoration.getName() ); |
123 |
|
} |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
0 |
List fragments = fragment.getFragments(); |
128 |
0 |
if ( ( fragments != null ) && ! fragments.isEmpty() ) |
129 |
|
{ |
130 |
0 |
Iterator fragmentsIter = fragments.iterator(); |
131 |
0 |
while ( fragmentsIter.hasNext() ) |
132 |
|
{ |
133 |
0 |
setupFragmentDecorations( (Fragment)fragmentsIter.next(), false, portletDecorationNames, isDesktopEnabled ); |
134 |
|
} |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
0 |
return decoration; |
139 |
|
} |
140 |
|
|
141 |
|
public Set getStyleSheets() |
142 |
|
{ |
143 |
0 |
return styleSheets; |
144 |
|
} |
145 |
|
|
146 |
|
public Decoration getDecoration( Fragment fragment ) |
147 |
|
{ |
148 |
0 |
return (Decoration) fragmentDecorations.get( fragment.getId() ); |
149 |
|
} |
150 |
|
|
151 |
|
public Collection getPortletDecorationNames() |
152 |
|
{ |
153 |
0 |
return portletDecorationNames; |
154 |
|
} |
155 |
|
|
156 |
|
public LayoutDecoration getPageLayoutDecoration() |
157 |
|
{ |
158 |
0 |
return layoutDecoration; |
159 |
|
} |
160 |
|
|
161 |
|
public void init(Page page, DecorationFactory decoration, RequestContext context) |
162 |
|
{ |
163 |
0 |
this.page = page; |
164 |
0 |
this.decorationFactory = decoration; |
165 |
0 |
this.requestContext = context; |
166 |
0 |
} |
167 |
|
|
168 |
|
public Page getPage() |
169 |
|
{ |
170 |
0 |
return page; |
171 |
|
} |
172 |
|
|
173 |
|
public ContentPage getContentPage() |
174 |
|
{ |
175 |
0 |
return (ContentPage)page; |
176 |
|
} |
177 |
|
|
178 |
|
public boolean isInvalidated() |
179 |
|
{ |
180 |
0 |
return this.invalidated; |
181 |
|
} |
182 |
|
|
183 |
|
public void setInvalidated(boolean flag) |
184 |
|
{ |
185 |
0 |
this.invalidated = flag; |
186 |
0 |
} |
187 |
|
} |