%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.om.page.impl.PageImpl |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
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 | 0 | super(new PageSecurityConstraintsImpl()); |
56 | 0 | } |
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 | // create initial collection if necessary |
|
68 | 0 | if (menus == null) |
69 | { |
|
70 | 0 | menus = DatabasePageManagerUtils.createList();; |
71 | } |
|
72 | 0 | return menus; |
73 | } |
|
74 | ||
75 | /* (non-Javadoc) |
|
76 | * @see org.apache.jetspeed.om.page.impl.BaseElementImpl#resetCachedSecurityConstraints() |
|
77 | */ |
|
78 | public void resetCachedSecurityConstraints() |
|
79 | { |
|
80 | // propagate to super and fragments |
|
81 | 0 | super.resetCachedSecurityConstraints(); |
82 | 0 | FragmentImpl rootFragment = (FragmentImpl)getRootFragment(); |
83 | 0 | if (rootFragment != null) |
84 | { |
|
85 | 0 | rootFragment.resetCachedSecurityConstraints(); |
86 | } |
|
87 | 0 | } |
88 | ||
89 | /* (non-Javadoc) |
|
90 | * @see org.apache.jetspeed.page.document.impl.NodeImpl#newPageMetadata(java.util.Collection) |
|
91 | */ |
|
92 | public PageMetadataImpl newPageMetadata(Collection fields) |
|
93 | { |
|
94 | 0 | PageMetadataImpl pageMetadata = new PageMetadataImpl(PageMetadataLocalizedFieldImpl.class); |
95 | 0 | pageMetadata.setFields(fields); |
96 | 0 | return pageMetadata; |
97 | } |
|
98 | ||
99 | /* (non-Javadoc) |
|
100 | * @see org.apache.jetspeed.om.page.Page#getSkin() |
|
101 | */ |
|
102 | public String getSkin() |
|
103 | { |
|
104 | 0 | return skin; |
105 | } |
|
106 | ||
107 | /* (non-Javadoc) |
|
108 | * @see org.apache.jetspeed.om.page.Page#setSkin(java.lang.String) |
|
109 | */ |
|
110 | public void setSkin(String skinName) |
|
111 | { |
|
112 | 0 | this.skin = skinName; |
113 | 0 | } |
114 | ||
115 | /* (non-Javadoc) |
|
116 | * @see org.apache.jetspeed.om.page.Page#getEffectiveDefaultDecorator(java.lang.String) |
|
117 | */ |
|
118 | public String getEffectiveDefaultDecorator(String fragmentType) |
|
119 | { |
|
120 | // get locally defined decorator |
|
121 | 0 | String decorator = getDefaultDecorator(fragmentType); |
122 | 0 | if (decorator == null) |
123 | { |
|
124 | // delegate to parent folder |
|
125 | 0 | Folder parentFolder = (Folder)ProxyHelper.getRealObject(getParent()); |
126 | 0 | if (parentFolder != null) |
127 | { |
|
128 | 0 | return parentFolder.getEffectiveDefaultDecorator(fragmentType); |
129 | } |
|
130 | } |
|
131 | 0 | return decorator; |
132 | } |
|
133 | ||
134 | /* (non-Javadoc) |
|
135 | * @see org.apache.jetspeed.om.page.Page#getDefaultDecorator(java.lang.String) |
|
136 | */ |
|
137 | public String getDefaultDecorator(String fragmentType) |
|
138 | { |
|
139 | // retrieve supported decorator types |
|
140 | 0 | if (fragmentType != null) |
141 | { |
|
142 | 0 | if (fragmentType.equals(Fragment.LAYOUT)) |
143 | { |
|
144 | 0 | return defaultLayoutDecorator; |
145 | } |
|
146 | 0 | if (fragmentType.equals(Fragment.PORTLET)) |
147 | { |
|
148 | 0 | return defaultPortletDecorator; |
149 | } |
|
150 | } |
|
151 | 0 | return null; |
152 | } |
|
153 | ||
154 | /* (non-Javadoc) |
|
155 | * @see org.apache.jetspeed.om.page.Page#getDefaultDecorator(java.lang.String,java.lang.String) |
|
156 | */ |
|
157 | public void setDefaultDecorator(String decoratorName, String fragmentType) |
|
158 | { |
|
159 | // save supported decorator types |
|
160 | 0 | if (fragmentType != null) |
161 | { |
|
162 | 0 | if (fragmentType.equals(Fragment.LAYOUT)) |
163 | { |
|
164 | 0 | defaultLayoutDecorator = decoratorName; |
165 | } |
|
166 | 0 | if (fragmentType.equals(Fragment.PORTLET)) |
167 | { |
|
168 | 0 | defaultPortletDecorator = decoratorName; |
169 | } |
|
170 | } |
|
171 | 0 | } |
172 | ||
173 | /* (non-Javadoc) |
|
174 | * @see org.apache.jetspeed.om.page.Page#getRootFragment() |
|
175 | */ |
|
176 | public Fragment getRootFragment() |
|
177 | { |
|
178 | // get singleton fragment; no access checks to |
|
179 | // be made for root fragment |
|
180 | 0 | if ((fragment != null) && !fragment.isEmpty()) |
181 | { |
|
182 | 0 | FragmentImpl rootFragment = (FragmentImpl)fragment.iterator().next(); |
183 | 0 | if (rootFragment.getPage() == null) |
184 | { |
|
185 | // set page implementation in root and children fragments |
|
186 | 0 | rootFragment.setPage(this); |
187 | } |
|
188 | 0 | return rootFragment; |
189 | } |
|
190 | 0 | return null; |
191 | } |
|
192 | ||
193 | /* (non-Javadoc) |
|
194 | * @see org.apache.jetspeed.om.page.Page#setRootFragment(org.apache.jetspeed.om.page.Fragment) |
|
195 | */ |
|
196 | public void setRootFragment(Fragment fragment) |
|
197 | { |
|
198 | // add new or reuse singleton fragment |
|
199 | 0 | if (fragment instanceof FragmentImpl) |
200 | { |
|
201 | // create singleton collection or remove existing |
|
202 | // root fragment and save for reuse |
|
203 | 0 | if (this.fragment == null) |
204 | { |
|
205 | 0 | this.fragment = DatabasePageManagerUtils.createList(); |
206 | } |
|
207 | 0 | else if (!this.fragment.isEmpty()) |
208 | { |
|
209 | 0 | removedFragment = (FragmentImpl)this.fragment.iterator().next(); |
210 | 0 | this.fragment.clear(); |
211 | } |
|
212 | ||
213 | // add new fragment or copy configuration |
|
214 | // from previously removed fragment |
|
215 | 0 | if (removedFragment != null) |
216 | { |
|
217 | // reuse previously removed fragment |
|
218 | 0 | FragmentImpl addFragment = (FragmentImpl)fragment; |
219 | 0 | fragment = removedFragment; |
220 | 0 | removedFragment = null; |
221 | // TODO: move this logic to copy methods on implementations |
|
222 | 0 | fragment.setName(addFragment.getName()); |
223 | 0 | fragment.setTitle(addFragment.getTitle()); |
224 | 0 | fragment.setShortTitle(addFragment.getShortTitle()); |
225 | 0 | fragment.setType(addFragment.getType()); |
226 | 0 | fragment.setSkin(addFragment.getSkin()); |
227 | 0 | fragment.setDecorator(addFragment.getDecorator()); |
228 | 0 | fragment.setState(addFragment.getState()); |
229 | 0 | fragment.setSecurityConstraints(addFragment.getSecurityConstraints()); |
230 | 0 | fragment.getProperties().clear(); |
231 | 0 | fragment.getProperties().putAll(addFragment.getProperties()); |
232 | 0 | fragment.setPreferences(addFragment.getPreferences()); |
233 | 0 | fragment.getFragments().clear(); |
234 | 0 | fragment.getFragments().addAll(addFragment.getFragments()); |
235 | } |
|
236 | 0 | this.fragment.add(fragment); |
237 | ||
238 | // set page implementation in root and children fragments |
|
239 | 0 | ((FragmentImpl)fragment).setPage(this); |
240 | } |
|
241 | 0 | else if (fragment == null) |
242 | { |
|
243 | // delete existing fragment if required, saving |
|
244 | // removed fragment for later reuse |
|
245 | 0 | if ((this.fragment != null) && !class="keyword">this.fragment.isEmpty()) |
246 | { |
|
247 | 0 | removedFragment = (FragmentImpl)this.fragment.iterator().next(); |
248 | 0 | this.fragment.clear(); |
249 | } |
|
250 | } |
|
251 | 0 | } |
252 | ||
253 | /* (non-Javadoc) |
|
254 | * @see org.apache.jetspeed.om.page.Page#getFragmentById(java.lang.String) |
|
255 | */ |
|
256 | public Fragment getFragmentById(String id) |
|
257 | { |
|
258 | // get fragment by id and check access |
|
259 | 0 | FragmentImpl rootFragment = (FragmentImpl)getRootFragment(); |
260 | 0 | if (rootFragment != null) |
261 | { |
|
262 | 0 | Fragment fragment = rootFragment.getFragmentById(id); |
263 | 0 | if (fragment != null) |
264 | { |
|
265 | try |
|
266 | { |
|
267 | 0 | fragment.checkAccess(JetspeedActions.VIEW); |
268 | } |
|
269 | 0 | catch (SecurityException se) |
270 | { |
|
271 | 0 | fragment = null; |
272 | 0 | } |
273 | } |
|
274 | 0 | return fragment; |
275 | } |
|
276 | 0 | return null; |
277 | } |
|
278 | ||
279 | /* (non-Javadoc) |
|
280 | * @see org.apache.jetspeed.om.page.Page#removeFragmentById(java.lang.String) |
|
281 | */ |
|
282 | public Fragment removeFragmentById(String id) |
|
283 | { |
|
284 | // remove fragment by id |
|
285 | 0 | FragmentImpl rootFragment = (FragmentImpl)getRootFragment(); |
286 | 0 | if (rootFragment != null) |
287 | { |
|
288 | 0 | if (rootFragment.getId().equals(id)) |
289 | { |
|
290 | 0 | setRootFragment(null); |
291 | 0 | return rootFragment; |
292 | } |
|
293 | else |
|
294 | { |
|
295 | 0 | return rootFragment.removeFragmentById(id); |
296 | } |
|
297 | } |
|
298 | 0 | return null; |
299 | } |
|
300 | ||
301 | /* (non-Javadoc) |
|
302 | * @see org.apache.jetspeed.om.page.Page#getFragmentsByName(java.lang.String) |
|
303 | */ |
|
304 | public List getFragmentsByName(String name) |
|
305 | { |
|
306 | // get fragments by name and filter by access |
|
307 | 0 | FragmentImpl rootFragment = (FragmentImpl)getRootFragment(); |
308 | 0 | if (rootFragment != null) |
309 | { |
|
310 | // return immutable filtered fragment list |
|
311 | 0 | return rootFragment.filterFragmentsByAccess(rootFragment.getFragmentsByName(name), false); |
312 | } |
|
313 | 0 | return null; |
314 | } |
|
315 | ||
316 | /* (non-Javadoc) |
|
317 | * @see org.apache.jetspeed.om.page.Page#getMenuDefinitions() |
|
318 | */ |
|
319 | public List getMenuDefinitions() |
|
320 | { |
|
321 | // return mutable menu definition list |
|
322 | // by using list wrapper to manage |
|
323 | // element uniqueness |
|
324 | 0 | if (menuDefinitions == null) |
325 | { |
|
326 | 0 | menuDefinitions = new PageMenuDefinitionList(this); |
327 | } |
|
328 | 0 | return menuDefinitions; |
329 | } |
|
330 | ||
331 | /* (non-Javadoc) |
|
332 | * @see org.apache.jetspeed.om.page.Page#newMenuDefinition() |
|
333 | */ |
|
334 | public MenuDefinition newMenuDefinition() |
|
335 | { |
|
336 | 0 | return new PageMenuDefinitionImpl(); |
337 | } |
|
338 | ||
339 | /* (non-Javadoc) |
|
340 | * @see org.apache.jetspeed.om.page.Page#newMenuExcludeDefinition() |
|
341 | */ |
|
342 | public MenuExcludeDefinition newMenuExcludeDefinition() |
|
343 | { |
|
344 | 0 | return new PageMenuExcludeDefinitionImpl(); |
345 | } |
|
346 | ||
347 | /* (non-Javadoc) |
|
348 | * @see org.apache.jetspeed.om.page.Page#newMenuIncludeDefinition() |
|
349 | */ |
|
350 | public MenuIncludeDefinition newMenuIncludeDefinition() |
|
351 | { |
|
352 | 0 | return new PageMenuIncludeDefinitionImpl(); |
353 | } |
|
354 | ||
355 | /* (non-Javadoc) |
|
356 | * @see org.apache.jetspeed.om.page.Page#newMenuOptionsDefinition() |
|
357 | */ |
|
358 | public MenuOptionsDefinition newMenuOptionsDefinition() |
|
359 | { |
|
360 | 0 | return new PageMenuOptionsDefinitionImpl(); |
361 | } |
|
362 | ||
363 | /* (non-Javadoc) |
|
364 | * @see org.apache.jetspeed.om.page.Page#newMenuSeparatorDefinition() |
|
365 | */ |
|
366 | public MenuSeparatorDefinition newMenuSeparatorDefinition() |
|
367 | { |
|
368 | 0 | return new PageMenuSeparatorDefinitionImpl(); |
369 | } |
|
370 | ||
371 | /* (non-Javadoc) |
|
372 | * @see org.apache.jetspeed.om.page.Page#setMenuDefinitions(java.util.List) |
|
373 | */ |
|
374 | public void setMenuDefinitions(List definitions) |
|
375 | { |
|
376 | // set menu definitions by replacing |
|
377 | // existing entries with new elements if |
|
378 | // new collection is specified |
|
379 | 0 | List menuDefinitions = getMenuDefinitions(); |
380 | 0 | if (definitions != menuDefinitions) |
381 | { |
|
382 | // replace all menu definitions |
|
383 | 0 | menuDefinitions.clear(); |
384 | 0 | if (definitions != null) |
385 | { |
|
386 | 0 | menuDefinitions.addAll(definitions); |
387 | } |
|
388 | } |
|
389 | 0 | } |
390 | ||
391 | /* (non-Javadoc) |
|
392 | * @see org.apache.jetspeed.page.document.Node#getType() |
|
393 | */ |
|
394 | public String getType() |
|
395 | { |
|
396 | 0 | return DOCUMENT_TYPE; |
397 | } |
|
398 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |