1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.page.impl;
18
19 import java.util.Collection;
20 import java.util.List;
21
22 import org.apache.jetspeed.JetspeedActions;
23 import org.apache.jetspeed.om.folder.Folder;
24 import org.apache.jetspeed.om.folder.MenuDefinition;
25 import org.apache.jetspeed.om.folder.MenuExcludeDefinition;
26 import org.apache.jetspeed.om.folder.MenuIncludeDefinition;
27 import org.apache.jetspeed.om.folder.MenuOptionsDefinition;
28 import org.apache.jetspeed.om.folder.MenuSeparatorDefinition;
29 import org.apache.jetspeed.om.page.Fragment;
30 import org.apache.jetspeed.om.page.Page;
31 import org.apache.jetspeed.om.page.PageMetadataImpl;
32 import org.apache.jetspeed.page.document.impl.DocumentImpl;
33 import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
34 import org.apache.ojb.broker.core.proxy.ProxyHelper;
35
36 /***
37 * PageImpl
38 *
39 * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
40 * @version $Id$
41 */
42 public class PageImpl extends DocumentImpl implements Page
43 {
44 private Collection fragment;
45 private String skin;
46 private String defaultLayoutDecorator;
47 private String defaultPortletDecorator;
48 private List menus;
49
50 private PageMenuDefinitionList menuDefinitions;
51 private FragmentImpl removedFragment;
52
53 public PageImpl()
54 {
55 super(new PageSecurityConstraintsImpl());
56 }
57
58 /***
59 * accessMenus
60 *
61 * Access mutable persistent collection member for List wrappers.
62 *
63 * @return persistent collection
64 */
65 List accessMenus()
66 {
67
68 if (menus == null)
69 {
70 menus = DatabasePageManagerUtils.createList();;
71 }
72 return menus;
73 }
74
75
76
77
78 public void resetCachedSecurityConstraints()
79 {
80
81 super.resetCachedSecurityConstraints();
82 FragmentImpl rootFragment = (FragmentImpl)getRootFragment();
83 if (rootFragment != null)
84 {
85 rootFragment.resetCachedSecurityConstraints();
86 }
87 }
88
89
90
91
92 public PageMetadataImpl newPageMetadata(Collection fields)
93 {
94 PageMetadataImpl pageMetadata = new PageMetadataImpl(PageMetadataLocalizedFieldImpl.class);
95 pageMetadata.setFields(fields);
96 return pageMetadata;
97 }
98
99
100
101
102 public String getSkin()
103 {
104 return skin;
105 }
106
107
108
109
110 public void setSkin(String skinName)
111 {
112 this.skin = skinName;
113 }
114
115
116
117
118 public String getEffectiveDefaultDecorator(String fragmentType)
119 {
120
121 String decorator = getDefaultDecorator(fragmentType);
122 if (decorator == null)
123 {
124
125 Folder parentFolder = (Folder)ProxyHelper.getRealObject(getParent());
126 if (parentFolder != null)
127 {
128 return parentFolder.getEffectiveDefaultDecorator(fragmentType);
129 }
130 }
131 return decorator;
132 }
133
134
135
136
137 public String getDefaultDecorator(String fragmentType)
138 {
139
140 if (fragmentType != null)
141 {
142 if (fragmentType.equals(Fragment.LAYOUT))
143 {
144 return defaultLayoutDecorator;
145 }
146 if (fragmentType.equals(Fragment.PORTLET))
147 {
148 return defaultPortletDecorator;
149 }
150 }
151 return null;
152 }
153
154
155
156
157 public void setDefaultDecorator(String decoratorName, String fragmentType)
158 {
159
160 if (fragmentType != null)
161 {
162 if (fragmentType.equals(Fragment.LAYOUT))
163 {
164 defaultLayoutDecorator = decoratorName;
165 }
166 if (fragmentType.equals(Fragment.PORTLET))
167 {
168 defaultPortletDecorator = decoratorName;
169 }
170 }
171 }
172
173
174
175
176 public Fragment getRootFragment()
177 {
178
179
180 if ((fragment != null) && !fragment.isEmpty())
181 {
182 FragmentImpl rootFragment = (FragmentImpl)fragment.iterator().next();
183 if (rootFragment.getPage() == null)
184 {
185
186 rootFragment.setPage(this);
187 }
188 return rootFragment;
189 }
190 return null;
191 }
192
193
194
195
196 public void setRootFragment(Fragment fragment)
197 {
198
199 if (fragment instanceof FragmentImpl)
200 {
201
202
203 if (this.fragment == null)
204 {
205 this.fragment = DatabasePageManagerUtils.createList();
206 }
207 else if (!this.fragment.isEmpty())
208 {
209 removedFragment = (FragmentImpl)this.fragment.iterator().next();
210 this.fragment.clear();
211 }
212
213
214
215 if (removedFragment != null)
216 {
217
218 FragmentImpl addFragment = (FragmentImpl)fragment;
219 fragment = removedFragment;
220 removedFragment = null;
221
222 fragment.setName(addFragment.getName());
223 fragment.setTitle(addFragment.getTitle());
224 fragment.setShortTitle(addFragment.getShortTitle());
225 fragment.setType(addFragment.getType());
226 fragment.setSkin(addFragment.getSkin());
227 fragment.setDecorator(addFragment.getDecorator());
228 fragment.setState(addFragment.getState());
229 fragment.setSecurityConstraints(addFragment.getSecurityConstraints());
230 fragment.getProperties().clear();
231 fragment.getProperties().putAll(addFragment.getProperties());
232 fragment.setPreferences(addFragment.getPreferences());
233 fragment.getFragments().clear();
234 fragment.getFragments().addAll(addFragment.getFragments());
235 }
236 this.fragment.add(fragment);
237
238
239 ((FragmentImpl)fragment).setPage(this);
240 }
241 else if (fragment == null)
242 {
243
244
245 if ((this.fragment != null) && !this.fragment.isEmpty())
246 {
247 removedFragment = (FragmentImpl)this.fragment.iterator().next();
248 this.fragment.clear();
249 }
250 }
251 }
252
253
254
255
256 public Fragment getFragmentById(String id)
257 {
258
259 FragmentImpl rootFragment = (FragmentImpl)getRootFragment();
260 if (rootFragment != null)
261 {
262 Fragment fragment = rootFragment.getFragmentById(id);
263 if (fragment != null)
264 {
265 try
266 {
267 fragment.checkAccess(JetspeedActions.VIEW);
268 }
269 catch (SecurityException se)
270 {
271 fragment = null;
272 }
273 }
274 return fragment;
275 }
276 return null;
277 }
278
279
280
281
282 public Fragment removeFragmentById(String id)
283 {
284
285 FragmentImpl rootFragment = (FragmentImpl)getRootFragment();
286 if (rootFragment != null)
287 {
288 if (rootFragment.getId().equals(id))
289 {
290 setRootFragment(null);
291 return rootFragment;
292 }
293 else
294 {
295 return rootFragment.removeFragmentById(id);
296 }
297 }
298 return null;
299 }
300
301
302
303
304 public List getFragmentsByName(String name)
305 {
306
307 FragmentImpl rootFragment = (FragmentImpl)getRootFragment();
308 if (rootFragment != null)
309 {
310
311 return rootFragment.filterFragmentsByAccess(rootFragment.getFragmentsByName(name), false);
312 }
313 return null;
314 }
315
316
317
318
319 public List getMenuDefinitions()
320 {
321
322
323
324 if (menuDefinitions == null)
325 {
326 menuDefinitions = new PageMenuDefinitionList(this);
327 }
328 return menuDefinitions;
329 }
330
331
332
333
334 public MenuDefinition newMenuDefinition()
335 {
336 return new PageMenuDefinitionImpl();
337 }
338
339
340
341
342 public MenuExcludeDefinition newMenuExcludeDefinition()
343 {
344 return new PageMenuExcludeDefinitionImpl();
345 }
346
347
348
349
350 public MenuIncludeDefinition newMenuIncludeDefinition()
351 {
352 return new PageMenuIncludeDefinitionImpl();
353 }
354
355
356
357
358 public MenuOptionsDefinition newMenuOptionsDefinition()
359 {
360 return new PageMenuOptionsDefinitionImpl();
361 }
362
363
364
365
366 public MenuSeparatorDefinition newMenuSeparatorDefinition()
367 {
368 return new PageMenuSeparatorDefinitionImpl();
369 }
370
371
372
373
374 public void setMenuDefinitions(List definitions)
375 {
376
377
378
379 List menuDefinitions = getMenuDefinitions();
380 if (definitions != menuDefinitions)
381 {
382
383 menuDefinitions.clear();
384 if (definitions != null)
385 {
386 menuDefinitions.addAll(definitions);
387 }
388 }
389 }
390
391
392
393
394 public String getType()
395 {
396 return DOCUMENT_TYPE;
397 }
398 }