%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.om.page.psml.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 | ||
18 | package org.apache.jetspeed.om.page.psml; |
|
19 | ||
20 | import java.util.HashMap; |
|
21 | import java.util.Iterator; |
|
22 | import java.util.List; |
|
23 | import java.util.Map; |
|
24 | import java.util.Stack; |
|
25 | ||
26 | import org.apache.jetspeed.om.folder.Folder; |
|
27 | import org.apache.jetspeed.om.folder.MenuDefinition; |
|
28 | import org.apache.jetspeed.om.folder.MenuExcludeDefinition; |
|
29 | import org.apache.jetspeed.om.folder.MenuIncludeDefinition; |
|
30 | import org.apache.jetspeed.om.folder.MenuOptionsDefinition; |
|
31 | import org.apache.jetspeed.om.folder.MenuSeparatorDefinition; |
|
32 | import org.apache.jetspeed.om.folder.psml.MenuDefinitionImpl; |
|
33 | import org.apache.jetspeed.om.folder.psml.MenuExcludeDefinitionImpl; |
|
34 | import org.apache.jetspeed.om.folder.psml.MenuIncludeDefinitionImpl; |
|
35 | import org.apache.jetspeed.om.folder.psml.MenuOptionsDefinitionImpl; |
|
36 | import org.apache.jetspeed.om.folder.psml.MenuSeparatorDefinitionImpl; |
|
37 | import org.apache.jetspeed.om.page.Fragment; |
|
38 | import org.apache.jetspeed.om.page.Page; |
|
39 | import org.apache.jetspeed.page.impl.DatabasePageManagerUtils; |
|
40 | ||
41 | /** |
|
42 | * @version $Id: PageImpl.java 550655 2007-06-26 01:41:35Z taylor $ |
|
43 | */ |
|
44 | public class PageImpl extends DocumentImpl implements Page |
|
45 | { |
|
46 | 0 | private DefaultsImpl defaults = new DefaultsImpl(); |
47 | ||
48 | 0 | private Fragment root = null; |
49 | ||
50 | private int hashCode; |
|
51 | ||
52 | /** |
|
53 | * menuDefinitions - menu definitions for page |
|
54 | */ |
|
55 | private List menuDefinitions; |
|
56 | ||
57 | public PageImpl() |
|
58 | { |
|
59 | // empty constructor |
|
60 | 0 | super(); |
61 | 0 | } |
62 | ||
63 | /** |
|
64 | * <p> |
|
65 | * setId |
|
66 | * </p> |
|
67 | * |
|
68 | * @see org.apache.jetspeed.om.page.psml.AbstractBaseElement#setId(java.lang.String) |
|
69 | * @param id |
|
70 | */ |
|
71 | public void setId( String id ) |
|
72 | { |
|
73 | // Cheaper to generate the hash code now then every call to hashCode() |
|
74 | 0 | hashCode = (Page.class.getName()+":"+id).hashCode(); |
75 | 0 | super.setId(id); |
76 | 0 | } |
77 | ||
78 | /** |
|
79 | * <p> |
|
80 | * equals |
|
81 | * </p> |
|
82 | * |
|
83 | * @see java.lang.Object#equals(java.lang.Object) |
|
84 | * @param obj |
|
85 | * @return |
|
86 | */ |
|
87 | public boolean equals( Object obj ) |
|
88 | { |
|
89 | 0 | if (obj instanceof Page) |
90 | { |
|
91 | 0 | Page page = (Page) obj; |
92 | 0 | return page != null && page.getId() != class="keyword">null && |
93 | this.getId() != null && class="keyword">this.getId().equals(page.getId()); |
|
94 | } |
|
95 | else |
|
96 | { |
|
97 | 0 | return false; |
98 | } |
|
99 | ||
100 | } |
|
101 | ||
102 | /** |
|
103 | * <p> |
|
104 | * hashCode |
|
105 | * </p> |
|
106 | * |
|
107 | * @see java.lang.Object#hashCode() |
|
108 | * @return |
|
109 | */ |
|
110 | public int hashCode() |
|
111 | { |
|
112 | 0 | return hashCode; |
113 | } |
|
114 | ||
115 | public String getSkin() |
|
116 | { |
|
117 | 0 | return defaults.getSkin(); |
118 | } |
|
119 | ||
120 | public void setSkin( String skinName ) |
|
121 | { |
|
122 | 0 | defaults.setSkin(skinName); |
123 | 0 | } |
124 | ||
125 | /* (non-Javadoc) |
|
126 | * @see org.apache.jetspeed.om.page.Page#getEffectiveDefaultDecorator(java.lang.String) |
|
127 | */ |
|
128 | public String getEffectiveDefaultDecorator(String fragmentType) |
|
129 | { |
|
130 | // get locally defined decorator |
|
131 | 0 | String decorator = getDefaultDecorator(fragmentType); |
132 | 0 | if (decorator == null) |
133 | { |
|
134 | // delegate to parent folder |
|
135 | 0 | Folder parentFolder = (Folder)getParent(); |
136 | 0 | if (parentFolder != null) |
137 | { |
|
138 | 0 | return parentFolder.getEffectiveDefaultDecorator(fragmentType); |
139 | } |
|
140 | } |
|
141 | 0 | return decorator; |
142 | } |
|
143 | ||
144 | public String getDefaultDecorator( String fragmentType ) |
|
145 | { |
|
146 | 0 | return defaults.getDecorator(fragmentType); |
147 | } |
|
148 | ||
149 | public void setDefaultDecorator( String decoratorName, String fragmentType ) |
|
150 | { |
|
151 | 0 | defaults.setDecorator(fragmentType, decoratorName); |
152 | 0 | } |
153 | ||
154 | public Fragment getRootFragment() |
|
155 | { |
|
156 | 0 | return this.root; |
157 | } |
|
158 | ||
159 | public void setRootFragment( Fragment root ) |
|
160 | { |
|
161 | 0 | this.root = root; |
162 | 0 | if (root instanceof FragmentImpl) |
163 | { |
|
164 | 0 | ((FragmentImpl)root).setPage(this); |
165 | } |
|
166 | 0 | } |
167 | ||
168 | public Fragment getFragmentById( String id ) |
|
169 | { |
|
170 | 0 | Stack stack = new Stack(); |
171 | 0 | if (getRootFragment() != null) |
172 | { |
|
173 | 0 | stack.push(getRootFragment()); |
174 | } |
|
175 | ||
176 | 0 | Fragment f = (Fragment) stack.pop(); |
177 | ||
178 | 0 | while ((f != null) && (!(f.getId().equals(id)))) |
179 | { |
|
180 | 0 | Iterator i = f.getFragments().iterator(); |
181 | ||
182 | 0 | while (i.hasNext()) |
183 | { |
|
184 | 0 | stack.push(i.next()); |
185 | } |
|
186 | ||
187 | 0 | if (stack.size() > 0) |
188 | { |
|
189 | 0 | f = (Fragment) stack.pop(); |
190 | } |
|
191 | else |
|
192 | { |
|
193 | 0 | f = null; |
194 | } |
|
195 | 0 | } |
196 | ||
197 | 0 | return f; |
198 | } |
|
199 | ||
200 | public Fragment removeFragmentById( String id ) |
|
201 | { |
|
202 | // find fragment by id, tracking fragment parent |
|
203 | 0 | Map parents = new HashMap(); |
204 | 0 | Stack stack = new Stack(); |
205 | 0 | if (getRootFragment() != null) |
206 | { |
|
207 | 0 | stack.push(getRootFragment()); |
208 | } |
|
209 | 0 | Fragment f = (Fragment) stack.pop(); |
210 | 0 | while ((f != null) && (!(f.getId().equals(id)))) |
211 | { |
|
212 | 0 | Iterator i = f.getFragments().iterator(); |
213 | ||
214 | 0 | while (i.hasNext()) |
215 | { |
|
216 | 0 | Fragment child = (Fragment)i.next(); |
217 | 0 | stack.push(child); |
218 | 0 | parents.put(child, f); |
219 | 0 | } |
220 | ||
221 | 0 | if (stack.size() > 0) |
222 | { |
|
223 | 0 | f = (Fragment) stack.pop(); |
224 | } |
|
225 | else |
|
226 | { |
|
227 | 0 | f = null; |
228 | } |
|
229 | 0 | } |
230 | ||
231 | // remove fragment from parent/page root |
|
232 | 0 | if (f != null) |
233 | { |
|
234 | 0 | Fragment parent = (Fragment)parents.get(f); |
235 | 0 | if (parent != null) |
236 | { |
|
237 | 0 | if (parent.getFragments().remove(f)) |
238 | { |
|
239 | 0 | return f; |
240 | } |
|
241 | } |
|
242 | else |
|
243 | { |
|
244 | 0 | if (f == root) |
245 | { |
|
246 | 0 | root = null; |
247 | 0 | return f; |
248 | } |
|
249 | } |
|
250 | } |
|
251 | ||
252 | // not found or removed |
|
253 | 0 | return null; |
254 | } |
|
255 | ||
256 | public List getFragmentsByName( String name ) |
|
257 | { |
|
258 | 0 | List fragments = DatabasePageManagerUtils.createList(); |
259 | ||
260 | 0 | Stack stack = new Stack(); |
261 | 0 | if (getRootFragment() != null) |
262 | { |
|
263 | 0 | stack.push(getRootFragment()); |
264 | } |
|
265 | ||
266 | 0 | Fragment f = (Fragment) stack.pop(); |
267 | ||
268 | 0 | while (f != null) |
269 | { |
|
270 | 0 | if ((f.getName() != null) && f.getName().equals(name)) |
271 | { |
|
272 | 0 | fragments.add(f); |
273 | } |
|
274 | ||
275 | 0 | Iterator i = f.getFragments().iterator(); |
276 | ||
277 | 0 | while (i.hasNext()) |
278 | { |
|
279 | 0 | stack.push(i.next()); |
280 | } |
|
281 | ||
282 | 0 | if (stack.size() > 0) |
283 | { |
|
284 | 0 | f = (Fragment) stack.pop(); |
285 | } |
|
286 | else |
|
287 | { |
|
288 | 0 | f = null; |
289 | } |
|
290 | 0 | } |
291 | ||
292 | 0 | return fragments; |
293 | } |
|
294 | ||
295 | public DefaultsImpl getDefaults() |
|
296 | { |
|
297 | 0 | return this.defaults; |
298 | } |
|
299 | ||
300 | public void setDefaults( DefaultsImpl defaults ) |
|
301 | { |
|
302 | 0 | this.defaults = defaults; |
303 | 0 | } |
304 | ||
305 | /** |
|
306 | * <p> |
|
307 | * getType |
|
308 | * </p> |
|
309 | * |
|
310 | * @see org.apache.jetspeed.om.page.Document#getType() |
|
311 | * @return |
|
312 | */ |
|
313 | public String getType() |
|
314 | { |
|
315 | 0 | return DOCUMENT_TYPE; |
316 | } |
|
317 | ||
318 | /** |
|
319 | * getMenuDefinitions - get list of menu definitions |
|
320 | * |
|
321 | * @return definition list |
|
322 | */ |
|
323 | public List getMenuDefinitions() |
|
324 | { |
|
325 | 0 | return menuDefinitions; |
326 | } |
|
327 | ||
328 | /** |
|
329 | * newMenuDefinition - creates a new empty menu definition |
|
330 | * |
|
331 | * @return a newly created MenuDefinition object for use in Page |
|
332 | */ |
|
333 | public MenuDefinition newMenuDefinition() |
|
334 | { |
|
335 | 0 | return new MenuDefinitionImpl(); |
336 | } |
|
337 | ||
338 | /** |
|
339 | * newMenuExcludeDefinition - creates a new empty menu exclude definition |
|
340 | * |
|
341 | * @return a newly created MenuExcludeDefinition object for use in Page |
|
342 | */ |
|
343 | public MenuExcludeDefinition newMenuExcludeDefinition() |
|
344 | { |
|
345 | 0 | return new MenuExcludeDefinitionImpl(); |
346 | } |
|
347 | ||
348 | /** |
|
349 | * newMenuIncludeDefinition - creates a new empty menu include definition |
|
350 | * |
|
351 | * @return a newly created MenuIncludeDefinition object for use in Page |
|
352 | */ |
|
353 | public MenuIncludeDefinition newMenuIncludeDefinition() |
|
354 | { |
|
355 | 0 | return new MenuIncludeDefinitionImpl(); |
356 | } |
|
357 | ||
358 | /** |
|
359 | * newMenuOptionsDefinition - creates a new empty menu options definition |
|
360 | * |
|
361 | * @return a newly created MenuOptionsDefinition object for use in Page |
|
362 | */ |
|
363 | public MenuOptionsDefinition newMenuOptionsDefinition() |
|
364 | { |
|
365 | 0 | return new MenuOptionsDefinitionImpl(); |
366 | } |
|
367 | ||
368 | /** |
|
369 | * newMenuSeparatorDefinition - creates a new empty menu separator definition |
|
370 | * |
|
371 | * @return a newly created MenuSeparatorDefinition object for use in Page |
|
372 | */ |
|
373 | public MenuSeparatorDefinition newMenuSeparatorDefinition() |
|
374 | { |
|
375 | 0 | return new MenuSeparatorDefinitionImpl(); |
376 | } |
|
377 | ||
378 | /** |
|
379 | * setMenuDefinitions - set list of menu definitions |
|
380 | * |
|
381 | * @param definitions definition list |
|
382 | */ |
|
383 | public void setMenuDefinitions(List definitions) |
|
384 | { |
|
385 | 0 | menuDefinitions = definitions; |
386 | 0 | } |
387 | ||
388 | /** |
|
389 | * unmarshalled - notification that this instance has been |
|
390 | * loaded from the persistent store |
|
391 | */ |
|
392 | public void unmarshalled() |
|
393 | { |
|
394 | // notify super class implementation |
|
395 | 0 | super.unmarshalled(); |
396 | ||
397 | // propagate unmarshalled notification |
|
398 | // to all menu definitions |
|
399 | 0 | if (menuDefinitions != null) |
400 | { |
|
401 | 0 | Iterator menuIter = menuDefinitions.iterator(); |
402 | 0 | while (menuIter.hasNext()) |
403 | { |
|
404 | 0 | ((MenuDefinitionImpl)menuIter.next()).unmarshalled(); |
405 | } |
|
406 | } |
|
407 | ||
408 | // propagate unmarshalled notification |
|
409 | // to root fragment |
|
410 | 0 | if (root != null) |
411 | { |
|
412 | 0 | ((FragmentImpl)root).unmarshalled(); |
413 | } |
|
414 | ||
415 | // default title of pages to name |
|
416 | 0 | if (getTitle() == null) |
417 | { |
|
418 | 0 | setTitle(getTitleName()); |
419 | } |
|
420 | 0 | } |
421 | ||
422 | /** |
|
423 | * marshalling - notification that this instance is to |
|
424 | * be saved to the persistent store |
|
425 | */ |
|
426 | public void marshalling() |
|
427 | { |
|
428 | // propagate marshalling notification |
|
429 | // to root fragment |
|
430 | 0 | if (root != null) |
431 | { |
|
432 | 0 | ((FragmentImpl)root).marshalling(); |
433 | } |
|
434 | ||
435 | // propagate marshalling notification |
|
436 | // to all menu definitions |
|
437 | 0 | if (menuDefinitions != null) |
438 | { |
|
439 | 0 | Iterator menuIter = menuDefinitions.iterator(); |
440 | 0 | while (menuIter.hasNext()) |
441 | { |
|
442 | 0 | ((MenuDefinitionImpl)menuIter.next()).marshalling(); |
443 | } |
|
444 | } |
|
445 | ||
446 | // notify super class implementation |
|
447 | 0 | super.marshalling(); |
448 | 0 | } |
449 | } |
|
450 |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |