%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.om.page.impl.FragmentImpl |
|
|
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.security.AccessController; |
|
20 | import java.util.Iterator; |
|
21 | import java.util.List; |
|
22 | import java.util.Map; |
|
23 | ||
24 | import org.apache.jetspeed.JetspeedActions; |
|
25 | import org.apache.jetspeed.om.folder.Folder; |
|
26 | import org.apache.jetspeed.om.page.Fragment; |
|
27 | import org.apache.jetspeed.om.page.PageSecurity; |
|
28 | import org.apache.jetspeed.page.impl.DatabasePageManagerUtils; |
|
29 | import org.apache.jetspeed.security.FragmentPermission; |
|
30 | ||
31 | /** |
|
32 | * FragmentImpl |
|
33 | * |
|
34 | * @author <a href="mailto:rwatler@apache.org">Randy Watler</a> |
|
35 | * @version $Id$ |
|
36 | */ |
|
37 | public class FragmentImpl extends BaseElementImpl implements Fragment |
|
38 | { |
|
39 | private List fragments; |
|
40 | private String type; |
|
41 | private String skin; |
|
42 | private String decorator; |
|
43 | private String state; |
|
44 | private String mode; |
|
45 | 0 | private int layoutRowProperty = -1; |
46 | 0 | private int layoutColumnProperty = -1; |
47 | private String layoutSizesProperty; |
|
48 | 0 | private float layoutXProperty = -1.0F; |
49 | 0 | private float layoutYProperty = -1.0F; |
50 | 0 | private float layoutZProperty = -1.0F; |
51 | 0 | private float layoutWidthProperty = -1.0F; |
52 | 0 | private float layoutHeightProperty = -1.0F; |
53 | private String extendedPropertyName1; |
|
54 | private String extendedPropertyValue1; |
|
55 | private String extendedPropertyName2; |
|
56 | private String extendedPropertyValue2; |
|
57 | private List preferences; |
|
58 | ||
59 | private FragmentList fragmentsList; |
|
60 | private FragmentPropertyMap propertiesMap; |
|
61 | private FragmentPreferenceList fragmentPreferences; |
|
62 | private PageImpl page; |
|
63 | ||
64 | public FragmentImpl() |
|
65 | { |
|
66 | 0 | super(new FragmentSecurityConstraintsImpl()); |
67 | 0 | } |
68 | ||
69 | /** |
|
70 | * accessFragments |
|
71 | * |
|
72 | * Access mutable persistent collection member for List wrappers. |
|
73 | * |
|
74 | * @return persistent collection |
|
75 | */ |
|
76 | List accessFragments() |
|
77 | { |
|
78 | // create initial collection if necessary |
|
79 | 0 | if (fragments == null) |
80 | { |
|
81 | 0 | fragments = DatabasePageManagerUtils.createList(); |
82 | } |
|
83 | 0 | return fragments; |
84 | } |
|
85 | ||
86 | /** |
|
87 | * accessPreferences |
|
88 | * |
|
89 | * Access mutable persistent collection member for List wrappers. |
|
90 | * |
|
91 | * @return persistent collection |
|
92 | */ |
|
93 | List accessPreferences() |
|
94 | { |
|
95 | // create initial collection if necessary |
|
96 | 0 | if (preferences == null) |
97 | { |
|
98 | 0 | preferences = DatabasePageManagerUtils.createList(); |
99 | } |
|
100 | 0 | return preferences; |
101 | } |
|
102 | ||
103 | /** |
|
104 | * getPage |
|
105 | * |
|
106 | * Get page implementation that owns fragment. |
|
107 | * |
|
108 | * @return owning page implementation |
|
109 | */ |
|
110 | PageImpl getPage() |
|
111 | { |
|
112 | 0 | return page; |
113 | } |
|
114 | ||
115 | /** |
|
116 | * setPage |
|
117 | * |
|
118 | * Set page implementation that owns fragment and |
|
119 | * propagate to all child fragments. |
|
120 | * |
|
121 | * @param page owning page implementation |
|
122 | */ |
|
123 | void setPage(PageImpl page) |
|
124 | { |
|
125 | // set page implementation |
|
126 | 0 | this.page = page; |
127 | // propagate to children |
|
128 | 0 | if (fragments != null) |
129 | { |
|
130 | 0 | Iterator fragmentsIter = fragments.iterator(); |
131 | 0 | while (fragmentsIter.hasNext()) |
132 | { |
|
133 | 0 | ((FragmentImpl)fragmentsIter.next()).setPage(page); |
134 | } |
|
135 | } |
|
136 | 0 | } |
137 | ||
138 | /** |
|
139 | * getFragmentById |
|
140 | * |
|
141 | * Retrieve fragment with matching id from |
|
142 | * this or child fragments. |
|
143 | * |
|
144 | * @param id fragment id to retrieve. |
|
145 | * @return matched fragment |
|
146 | */ |
|
147 | Fragment getFragmentById(String id) |
|
148 | { |
|
149 | // check for match |
|
150 | 0 | if (getId().equals(id)) |
151 | { |
|
152 | 0 | return this; |
153 | } |
|
154 | // match children |
|
155 | 0 | if (fragments != null) |
156 | { |
|
157 | 0 | Iterator fragmentsIter = fragments.iterator(); |
158 | 0 | while (fragmentsIter.hasNext()) |
159 | { |
|
160 | 0 | Fragment matchedFragment = ((FragmentImpl)fragmentsIter.next()).getFragmentById(id); |
161 | 0 | if (matchedFragment != null) |
162 | { |
|
163 | 0 | return matchedFragment; |
164 | } |
|
165 | 0 | } |
166 | } |
|
167 | 0 | return null; |
168 | } |
|
169 | ||
170 | /** |
|
171 | * removeFragmentById |
|
172 | * |
|
173 | * Remove fragment with matching id from |
|
174 | * child fragments. |
|
175 | * |
|
176 | * @param id fragment id to remove. |
|
177 | * @return removed fragment |
|
178 | */ |
|
179 | Fragment removeFragmentById(String id) |
|
180 | { |
|
181 | // remove from deep children |
|
182 | 0 | if (fragments != null) |
183 | { |
|
184 | 0 | Iterator fragmentsIter = fragments.iterator(); |
185 | 0 | while (fragmentsIter.hasNext()) |
186 | { |
|
187 | 0 | FragmentImpl fragment = (FragmentImpl)fragmentsIter.next(); |
188 | 0 | if (!fragment.getId().equals(id)) |
189 | { |
|
190 | 0 | Fragment removed = fragment.removeFragmentById(id); |
191 | 0 | if (removed != null) |
192 | { |
|
193 | 0 | return removed; |
194 | } |
|
195 | 0 | } |
196 | else |
|
197 | { |
|
198 | 0 | fragmentsIter.remove(); |
199 | 0 | return fragment; |
200 | } |
|
201 | 0 | } |
202 | } |
|
203 | 0 | return null; |
204 | } |
|
205 | ||
206 | /** |
|
207 | * getFragmentsByName |
|
208 | * |
|
209 | * Retrieve fragments with matching name including |
|
210 | * this and child fragments. |
|
211 | * |
|
212 | * @param name fragment name to retrieve. |
|
213 | * @return list of matched fragments |
|
214 | */ |
|
215 | List getFragmentsByName(String name) |
|
216 | { |
|
217 | 0 | List matchedFragments = null; |
218 | // check for match |
|
219 | 0 | if ((getName() != null) && getName().equals(name)) |
220 | { |
|
221 | 0 | if (matchedFragments == null) |
222 | { |
|
223 | 0 | matchedFragments = DatabasePageManagerUtils.createList(); |
224 | } |
|
225 | 0 | matchedFragments.add(this); |
226 | } |
|
227 | // match children |
|
228 | 0 | if (fragments != null) |
229 | { |
|
230 | 0 | Iterator fragmentsIter = fragments.iterator(); |
231 | 0 | while (fragmentsIter.hasNext()) |
232 | { |
|
233 | 0 | List matchedChildFragments = ((FragmentImpl)fragmentsIter.next()).getFragmentsByName(name); |
234 | 0 | if (matchedChildFragments != null) |
235 | { |
|
236 | 0 | if (matchedFragments == null) |
237 | { |
|
238 | 0 | matchedFragments = matchedChildFragments; |
239 | } |
|
240 | else |
|
241 | { |
|
242 | 0 | matchedFragments.addAll(matchedChildFragments); |
243 | } |
|
244 | } |
|
245 | 0 | } |
246 | } |
|
247 | 0 | return matchedFragments; |
248 | } |
|
249 | ||
250 | /** |
|
251 | * getPropertyMemberKeys |
|
252 | * |
|
253 | * Get valid explicit property member keys. |
|
254 | * |
|
255 | * @return list of property member keys with values |
|
256 | */ |
|
257 | List getPropertyMemberKeys() |
|
258 | { |
|
259 | 0 | List keys = DatabasePageManagerUtils.createList(); |
260 | 0 | if (layoutRowProperty >= 0) |
261 | { |
|
262 | 0 | keys.add(ROW_PROPERTY_NAME); |
263 | } |
|
264 | 0 | if (layoutColumnProperty >= 0) |
265 | { |
|
266 | 0 | keys.add(COLUMN_PROPERTY_NAME); |
267 | } |
|
268 | 0 | if (layoutSizesProperty != null) |
269 | { |
|
270 | 0 | keys.add(SIZES_PROPERTY_NAME); |
271 | } |
|
272 | 0 | if (layoutXProperty >= 0.0F) |
273 | { |
|
274 | 0 | keys.add(X_PROPERTY_NAME); |
275 | } |
|
276 | 0 | if (layoutYProperty >= 0.0F) |
277 | { |
|
278 | 0 | keys.add(Y_PROPERTY_NAME); |
279 | } |
|
280 | 0 | if (layoutZProperty >= 0.0F) |
281 | { |
|
282 | 0 | keys.add(Z_PROPERTY_NAME); |
283 | } |
|
284 | 0 | if (layoutWidthProperty >= 0.0F) |
285 | { |
|
286 | 0 | keys.add(WIDTH_PROPERTY_NAME); |
287 | } |
|
288 | 0 | if (layoutHeightProperty >= 0.0F) |
289 | { |
|
290 | 0 | keys.add(HEIGHT_PROPERTY_NAME); |
291 | } |
|
292 | 0 | if ((extendedPropertyName1 != null) && (extendedPropertyValue1 != class="keyword">null)) |
293 | { |
|
294 | 0 | keys.add(extendedPropertyName1); |
295 | } |
|
296 | 0 | if ((extendedPropertyName2 != null) && (extendedPropertyValue2 != class="keyword">null)) |
297 | { |
|
298 | 0 | keys.add(extendedPropertyName2); |
299 | } |
|
300 | 0 | return keys; |
301 | } |
|
302 | ||
303 | /** |
|
304 | * getPropertyMember |
|
305 | * |
|
306 | * Get explicit property member. |
|
307 | * |
|
308 | * @param key property name |
|
309 | * @return property setting |
|
310 | */ |
|
311 | String getPropertyMember(String key) |
|
312 | { |
|
313 | // set fragment explicit property member |
|
314 | 0 | if (key.equals(ROW_PROPERTY_NAME)) |
315 | { |
|
316 | 0 | if (layoutRowProperty >= 0) |
317 | { |
|
318 | 0 | return String.valueOf(layoutRowProperty); |
319 | } |
|
320 | } |
|
321 | 0 | else if (key.equals(COLUMN_PROPERTY_NAME)) |
322 | { |
|
323 | 0 | if (layoutColumnProperty >= 0) |
324 | { |
|
325 | 0 | return String.valueOf(layoutColumnProperty); |
326 | } |
|
327 | } |
|
328 | 0 | else if (key.equals(SIZES_PROPERTY_NAME)) |
329 | { |
|
330 | 0 | return layoutSizesProperty; |
331 | } |
|
332 | 0 | else if (key.equals(X_PROPERTY_NAME)) |
333 | { |
|
334 | 0 | if (layoutXProperty >= 0.0F) |
335 | { |
|
336 | 0 | return String.valueOf(layoutXProperty); |
337 | } |
|
338 | } |
|
339 | 0 | else if (key.equals(Y_PROPERTY_NAME)) |
340 | { |
|
341 | 0 | if (layoutYProperty >= 0.0F) |
342 | { |
|
343 | 0 | return String.valueOf(layoutYProperty); |
344 | } |
|
345 | } |
|
346 | 0 | else if (key.equals(Z_PROPERTY_NAME)) |
347 | { |
|
348 | 0 | if (layoutZProperty >= 0.0F) |
349 | { |
|
350 | 0 | return String.valueOf(layoutZProperty); |
351 | } |
|
352 | } |
|
353 | 0 | else if (key.equals(WIDTH_PROPERTY_NAME)) |
354 | { |
|
355 | 0 | if (layoutWidthProperty >= 0.0F) |
356 | { |
|
357 | 0 | return String.valueOf(layoutWidthProperty); |
358 | } |
|
359 | } |
|
360 | 0 | else if (key.equals(HEIGHT_PROPERTY_NAME)) |
361 | { |
|
362 | 0 | if (layoutHeightProperty >= 0.0F) |
363 | { |
|
364 | 0 | return String.valueOf(layoutHeightProperty); |
365 | } |
|
366 | } |
|
367 | 0 | else if (key.equals(extendedPropertyName1)) |
368 | { |
|
369 | 0 | return extendedPropertyValue1; |
370 | } |
|
371 | 0 | else if (key.equals(extendedPropertyName2)) |
372 | { |
|
373 | 0 | return extendedPropertyValue2; |
374 | } |
|
375 | 0 | return null; |
376 | } |
|
377 | ||
378 | /** |
|
379 | * setPropertyMember |
|
380 | * |
|
381 | * Set explicit property member. |
|
382 | * |
|
383 | * @param key property name |
|
384 | * @param value property setting |
|
385 | */ |
|
386 | void setPropertyMember(String key, String value) |
|
387 | { |
|
388 | // set fragment explicit property member |
|
389 | 0 | if (key.equals(ROW_PROPERTY_NAME)) |
390 | { |
|
391 | 0 | layoutRowProperty = Integer.parseInt(value); |
392 | } |
|
393 | 0 | else if (key.equals(COLUMN_PROPERTY_NAME)) |
394 | { |
|
395 | 0 | layoutColumnProperty = Integer.parseInt(value); |
396 | } |
|
397 | 0 | else if (key.equals(SIZES_PROPERTY_NAME)) |
398 | { |
|
399 | 0 | layoutSizesProperty = value; |
400 | } |
|
401 | 0 | else if (key.equals(X_PROPERTY_NAME)) |
402 | { |
|
403 | 0 | layoutXProperty = Float.parseFloat(value); |
404 | } |
|
405 | 0 | else if (key.equals(Y_PROPERTY_NAME)) |
406 | { |
|
407 | 0 | layoutYProperty = Float.parseFloat(value); |
408 | } |
|
409 | 0 | else if (key.equals(Z_PROPERTY_NAME)) |
410 | { |
|
411 | 0 | layoutZProperty = Float.parseFloat(value); |
412 | } |
|
413 | 0 | else if (key.equals(WIDTH_PROPERTY_NAME)) |
414 | { |
|
415 | 0 | layoutWidthProperty = Float.parseFloat(value); |
416 | } |
|
417 | 0 | else if (key.equals(HEIGHT_PROPERTY_NAME)) |
418 | { |
|
419 | 0 | layoutHeightProperty = Float.parseFloat(value); |
420 | } |
|
421 | 0 | else if (key.equals(extendedPropertyName1)) |
422 | { |
|
423 | 0 | extendedPropertyValue1 = value; |
424 | } |
|
425 | 0 | else if (key.equals(extendedPropertyName2)) |
426 | { |
|
427 | 0 | extendedPropertyValue2 = value; |
428 | } |
|
429 | 0 | else if (extendedPropertyName1 == null) |
430 | { |
|
431 | 0 | extendedPropertyName1 = key; |
432 | 0 | extendedPropertyValue1 = value; |
433 | } |
|
434 | 0 | else if (extendedPropertyName2 == null) |
435 | { |
|
436 | 0 | extendedPropertyName2 = key; |
437 | 0 | extendedPropertyValue2 = value; |
438 | } |
|
439 | else |
|
440 | { |
|
441 | 0 | throw new RuntimeException("Unable to set fragment property " + key + ", extended properties already used."); |
442 | } |
|
443 | 0 | } |
444 | ||
445 | /** |
|
446 | * clearPropertyMember |
|
447 | * |
|
448 | * Clear explicit property member. |
|
449 | * |
|
450 | * @param key property name |
|
451 | */ |
|
452 | void clearPropertyMember(String key) |
|
453 | { |
|
454 | 0 | if (key.equals(ROW_PROPERTY_NAME)) |
455 | { |
|
456 | 0 | layoutRowProperty = -1; |
457 | } |
|
458 | 0 | else if (key.equals(COLUMN_PROPERTY_NAME)) |
459 | { |
|
460 | 0 | layoutColumnProperty = -1; |
461 | } |
|
462 | 0 | else if (key.equals(SIZES_PROPERTY_NAME)) |
463 | { |
|
464 | 0 | layoutSizesProperty = null; |
465 | } |
|
466 | 0 | else if (key.equals(X_PROPERTY_NAME)) |
467 | { |
|
468 | 0 | layoutXProperty = -1.0F; |
469 | } |
|
470 | 0 | else if (key.equals(Y_PROPERTY_NAME)) |
471 | { |
|
472 | 0 | layoutYProperty = -1.0F; |
473 | } |
|
474 | 0 | else if (key.equals(Z_PROPERTY_NAME)) |
475 | { |
|
476 | 0 | layoutZProperty = -1.0F; |
477 | } |
|
478 | 0 | else if (key.equals(WIDTH_PROPERTY_NAME)) |
479 | { |
|
480 | 0 | layoutWidthProperty = -1.0F; |
481 | } |
|
482 | 0 | else if (key.equals(HEIGHT_PROPERTY_NAME)) |
483 | { |
|
484 | 0 | layoutHeightProperty = -1.0F; |
485 | } |
|
486 | 0 | else if (key.equals(extendedPropertyName1)) |
487 | { |
|
488 | 0 | extendedPropertyName1 = null; |
489 | 0 | extendedPropertyValue1 = null; |
490 | } |
|
491 | 0 | else if (key.equals(extendedPropertyName2)) |
492 | { |
|
493 | 0 | extendedPropertyName2 = null; |
494 | 0 | extendedPropertyValue2 = null; |
495 | } |
|
496 | 0 | } |
497 | ||
498 | /* (non-Javadoc) |
|
499 | * @see org.apache.jetspeed.om.page.impl.BaseElementImpl#getEffectivePageSecurity() |
|
500 | */ |
|
501 | public PageSecurity getEffectivePageSecurity() |
|
502 | { |
|
503 | // delegate to page implementation |
|
504 | 0 | if (page != null) |
505 | { |
|
506 | 0 | return page.getEffectivePageSecurity(); |
507 | } |
|
508 | 0 | return null; |
509 | } |
|
510 | ||
511 | /* (non-Javadoc) |
|
512 | * @see org.apache.jetspeed.om.page.impl.BaseElementImpl#getLogicalPermissionPath() |
|
513 | */ |
|
514 | public String getLogicalPermissionPath() |
|
515 | { |
|
516 | // use page implementation path as base and append name |
|
517 | 0 | if ((page != null) && (getName() != class="keyword">null)) |
518 | { |
|
519 | 0 | return page.getLogicalPermissionPath() + Folder.PATH_SEPARATOR + getName(); |
520 | } |
|
521 | 0 | return null; |
522 | } |
|
523 | ||
524 | /* (non-Javadoc) |
|
525 | * @see org.apache.jetspeed.om.page.impl.BaseElementImpl#getPhysicalPermissionPath() |
|
526 | */ |
|
527 | public String getPhysicalPermissionPath() |
|
528 | { |
|
529 | // use page implementation path as base and append name |
|
530 | 0 | if ((page != null) && (getName() != class="keyword">null)) |
531 | { |
|
532 | 0 | return page.getPhysicalPermissionPath() + Folder.PATH_SEPARATOR + getName(); |
533 | } |
|
534 | 0 | return null; |
535 | } |
|
536 | ||
537 | /* (non-Javadoc) |
|
538 | * @see org.apache.jetspeed.om.page.impl.BaseElementImpl#resetCachedSecurityConstraints() |
|
539 | */ |
|
540 | public void resetCachedSecurityConstraints() |
|
541 | { |
|
542 | // propagate to super and sub fragments |
|
543 | 0 | super.resetCachedSecurityConstraints(); |
544 | 0 | if (fragments != null) |
545 | { |
|
546 | 0 | Iterator fragmentsIter = fragments.iterator(); |
547 | 0 | while (fragmentsIter.hasNext()) |
548 | { |
|
549 | 0 | ((FragmentImpl)fragmentsIter.next()).resetCachedSecurityConstraints(); |
550 | } |
|
551 | } |
|
552 | 0 | } |
553 | ||
554 | /* (non-Javadoc) |
|
555 | * @see org.apache.jetspeed.om.page.impl.BaseElementImpl#checkPermissions(java.lang.String, int, boolean, boolean) |
|
556 | */ |
|
557 | public void checkPermissions(String path, int mask, boolean checkNodeOnly, class="keyword">boolean checkParentsOnly) throws SecurityException |
|
558 | { |
|
559 | // always check for granted fragment permissions |
|
560 | 0 | FragmentPermission permission = new FragmentPermission(path, mask); |
561 | 0 | AccessController.checkPermission(permission); |
562 | 0 | } |
563 | ||
564 | /* (non-Javadoc) |
|
565 | * @see org.apache.jetspeed.om.common.SecuredResource#getConstraintsEnabled() |
|
566 | */ |
|
567 | public boolean getConstraintsEnabled() |
|
568 | { |
|
569 | 0 | if (page != null) |
570 | { |
|
571 | 0 | return page.getConstraintsEnabled(); |
572 | } |
|
573 | 0 | return false; |
574 | } |
|
575 | ||
576 | /* (non-Javadoc) |
|
577 | * @see org.apache.jetspeed.om.common.SecuredResource#getPermissionsEnabled() |
|
578 | */ |
|
579 | public boolean getPermissionsEnabled() |
|
580 | { |
|
581 | 0 | if (page != null) |
582 | { |
|
583 | 0 | return page.getPermissionsEnabled(); |
584 | } |
|
585 | 0 | return false; |
586 | } |
|
587 | ||
588 | /* (non-Javadoc) |
|
589 | * @see org.apache.jetspeed.om.page.Fragment#getType() |
|
590 | */ |
|
591 | public String getType() |
|
592 | { |
|
593 | 0 | return type; |
594 | } |
|
595 | ||
596 | /* (non-Javadoc) |
|
597 | * @see org.apache.jetspeed.om.page.Fragment#setType(java.lang.String) |
|
598 | */ |
|
599 | public void setType(String type) |
|
600 | { |
|
601 | 0 | this.type = type; |
602 | 0 | } |
603 | ||
604 | /* (non-Javadoc) |
|
605 | * @see org.apache.jetspeed.om.page.Fragment#getSkin() |
|
606 | */ |
|
607 | public String getSkin() |
|
608 | { |
|
609 | 0 | return skin; |
610 | } |
|
611 | ||
612 | /* (non-Javadoc) |
|
613 | * @see org.apache.jetspeed.om.page.Fragment#setSkin(java.lang.String) |
|
614 | */ |
|
615 | public void setSkin(String skinName) |
|
616 | { |
|
617 | 0 | this.skin = skinName; |
618 | 0 | } |
619 | ||
620 | /* (non-Javadoc) |
|
621 | * @see org.apache.jetspeed.om.page.Fragment#getDecorator() |
|
622 | */ |
|
623 | public String getDecorator() |
|
624 | { |
|
625 | 0 | return decorator; |
626 | } |
|
627 | ||
628 | /* (non-Javadoc) |
|
629 | * @see org.apache.jetspeed.om.page.Fragment#setDecorator(java.lang.String) |
|
630 | */ |
|
631 | public void setDecorator(String decoratorName) |
|
632 | { |
|
633 | 0 | this.decorator = decoratorName; |
634 | 0 | } |
635 | ||
636 | /* (non-Javadoc) |
|
637 | * @see org.apache.jetspeed.om.page.Fragment#getState() |
|
638 | */ |
|
639 | public String getState() |
|
640 | { |
|
641 | 0 | return state; |
642 | } |
|
643 | ||
644 | /* (non-Javadoc) |
|
645 | * @see org.apache.jetspeed.om.page.Fragment#setState(java.lang.String) |
|
646 | */ |
|
647 | public void setState(String state) |
|
648 | { |
|
649 | 0 | this.state = state; |
650 | 0 | } |
651 | ||
652 | /* (non-Javadoc) |
|
653 | * @see org.apache.jetspeed.om.page.Fragment#getMode() |
|
654 | */ |
|
655 | public String getMode() |
|
656 | { |
|
657 | 0 | return mode; |
658 | } |
|
659 | ||
660 | /* (non-Javadoc) |
|
661 | * @see org.apache.jetspeed.om.page.Fragment#setMode(java.lang.String) |
|
662 | */ |
|
663 | public void setMode(String mode) |
|
664 | { |
|
665 | 0 | this.mode = mode; |
666 | 0 | } |
667 | ||
668 | /* (non-Javadoc) |
|
669 | * @see org.apache.jetspeed.om.page.Fragment#getFragments() |
|
670 | */ |
|
671 | public List getFragments() |
|
672 | { |
|
673 | // create and return mutable fragments collection |
|
674 | // filtered by view access |
|
675 | 0 | if (fragmentsList == null) |
676 | { |
|
677 | 0 | fragmentsList = new FragmentList(this); |
678 | } |
|
679 | 0 | return filterFragmentsByAccess(fragmentsList, true); |
680 | } |
|
681 | ||
682 | /* (non-Javadoc) |
|
683 | * @see org.apache.jetspeed.om.page.Fragment#getProperty(java.lang.String) |
|
684 | */ |
|
685 | public String getProperty(String propName) |
|
686 | { |
|
687 | 0 | return (String)getProperties().get(propName); |
688 | } |
|
689 | ||
690 | /* (non-Javadoc) |
|
691 | * @see org.apache.jetspeed.om.page.Fragment#getIntProperty(java.lang.String) |
|
692 | */ |
|
693 | public int getIntProperty(String propName) |
|
694 | { |
|
695 | 0 | String propValue = (String)getProperties().get(propName); |
696 | 0 | if (propValue != null) |
697 | { |
|
698 | 0 | return Integer.parseInt(propValue); |
699 | } |
|
700 | 0 | return -1; |
701 | } |
|
702 | ||
703 | /* (non-Javadoc) |
|
704 | * @see org.apache.jetspeed.om.page.Fragment#getFloatProperty(java.lang.String) |
|
705 | */ |
|
706 | public float getFloatProperty(String propName) |
|
707 | { |
|
708 | 0 | String propValue = (String)getProperties().get(propName); |
709 | 0 | if (propValue != null) |
710 | { |
|
711 | 0 | return Float.parseFloat(propValue); |
712 | } |
|
713 | 0 | return -1.0F; |
714 | } |
|
715 | ||
716 | /* (non-Javadoc) |
|
717 | * @see org.apache.jetspeed.om.page.Fragment#getProperties() |
|
718 | */ |
|
719 | public Map getProperties() |
|
720 | { |
|
721 | // initialize and return writable properties map |
|
722 | 0 | if (propertiesMap == null) |
723 | { |
|
724 | 0 | propertiesMap = new FragmentPropertyMap(this); |
725 | } |
|
726 | 0 | return propertiesMap; |
727 | } |
|
728 | ||
729 | /* (non-Javadoc) |
|
730 | * @see org.apache.jetspeed.om.page.Fragment#getLayoutRow() |
|
731 | */ |
|
732 | public int getLayoutRow() |
|
733 | { |
|
734 | // get standard int property |
|
735 | 0 | return getIntProperty(ROW_PROPERTY_NAME); |
736 | } |
|
737 | ||
738 | /* (non-Javadoc) |
|
739 | * @see org.apache.jetspeed.om.page.Fragment#setLayoutRow(int) |
|
740 | */ |
|
741 | public void setLayoutRow(int row) |
|
742 | { |
|
743 | // set standard int property |
|
744 | 0 | if (row >= 0) |
745 | { |
|
746 | 0 | getProperties().put(ROW_PROPERTY_NAME, String.valueOf(row)); |
747 | } |
|
748 | else |
|
749 | { |
|
750 | 0 | getProperties().remove(ROW_PROPERTY_NAME); |
751 | } |
|
752 | 0 | } |
753 | ||
754 | /* (non-Javadoc) |
|
755 | * @see org.apache.jetspeed.om.page.Fragment#getLayoutColumn() |
|
756 | */ |
|
757 | public int getLayoutColumn() |
|
758 | { |
|
759 | // get standard int property |
|
760 | 0 | return getIntProperty(COLUMN_PROPERTY_NAME); |
761 | } |
|
762 | ||
763 | /* (non-Javadoc) |
|
764 | * @see org.apache.jetspeed.om.page.Fragment#setLayoutColumn(int) |
|
765 | */ |
|
766 | public void setLayoutColumn(int column) |
|
767 | { |
|
768 | // set standard int property |
|
769 | 0 | if (column >= 0) |
770 | { |
|
771 | 0 | getProperties().put(COLUMN_PROPERTY_NAME, String.valueOf(column)); |
772 | } |
|
773 | else |
|
774 | { |
|
775 | 0 | getProperties().remove(COLUMN_PROPERTY_NAME); |
776 | } |
|
777 | 0 | } |
778 | ||
779 | /* (non-Javadoc) |
|
780 | * @see org.apache.jetspeed.om.page.Fragment#getLayoutSizes() |
|
781 | */ |
|
782 | public String getLayoutSizes() |
|
783 | { |
|
784 | // get standard string property |
|
785 | 0 | return getProperty(SIZES_PROPERTY_NAME); |
786 | } |
|
787 | ||
788 | /* (non-Javadoc) |
|
789 | * @see org.apache.jetspeed.om.page.Fragment#setLayoutSizes(java.lang.String) |
|
790 | */ |
|
791 | public void setLayoutSizes(String sizes) |
|
792 | { |
|
793 | // set standard string property |
|
794 | 0 | if (sizes != null) |
795 | { |
|
796 | 0 | getProperties().put(SIZES_PROPERTY_NAME, sizes); |
797 | } |
|
798 | else |
|
799 | { |
|
800 | 0 | getProperties().remove(SIZES_PROPERTY_NAME); |
801 | } |
|
802 | 0 | } |
803 | ||
804 | /* (non-Javadoc) |
|
805 | * @see org.apache.jetspeed.om.page.Fragment#getLayoutX() |
|
806 | */ |
|
807 | public float getLayoutX() |
|
808 | { |
|
809 | // get standard float property |
|
810 | 0 | return getFloatProperty(X_PROPERTY_NAME); |
811 | } |
|
812 | ||
813 | /* (non-Javadoc) |
|
814 | * @see org.apache.jetspeed.om.page.Fragment#setLayoutX(float) |
|
815 | */ |
|
816 | public void setLayoutX(float x) |
|
817 | { |
|
818 | // set standard float property |
|
819 | 0 | if (x >= 0.0F) |
820 | { |
|
821 | 0 | getProperties().put(X_PROPERTY_NAME, String.valueOf(x)); |
822 | } |
|
823 | else |
|
824 | { |
|
825 | 0 | getProperties().remove(X_PROPERTY_NAME); |
826 | } |
|
827 | 0 | } |
828 | ||
829 | /* (non-Javadoc) |
|
830 | * @see org.apache.jetspeed.om.page.Fragment#getLayoutY() |
|
831 | */ |
|
832 | public float getLayoutY() |
|
833 | { |
|
834 | // get standard float property |
|
835 | 0 | return getFloatProperty(Y_PROPERTY_NAME); |
836 | } |
|
837 | ||
838 | /* (non-Javadoc) |
|
839 | * @see org.apache.jetspeed.om.page.Fragment#setLayoutY(float) |
|
840 | */ |
|
841 | public void setLayoutY(float y) |
|
842 | { |
|
843 | // set standard float property |
|
844 | 0 | if (y >= 0.0F) |
845 | { |
|
846 | 0 | getProperties().put(Y_PROPERTY_NAME, String.valueOf(y)); |
847 | } |
|
848 | else |
|
849 | { |
|
850 | 0 | getProperties().remove(Y_PROPERTY_NAME); |
851 | } |
|
852 | 0 | } |
853 | ||
854 | /* (non-Javadoc) |
|
855 | * @see org.apache.jetspeed.om.page.Fragment#getLayoutZ() |
|
856 | */ |
|
857 | public float getLayoutZ() |
|
858 | { |
|
859 | // get standard float property |
|
860 | 0 | return getFloatProperty(Z_PROPERTY_NAME); |
861 | } |
|
862 | ||
863 | /* (non-Javadoc) |
|
864 | * @see org.apache.jetspeed.om.page.Fragment#setLayoutZ(float) |
|
865 | */ |
|
866 | public void setLayoutZ(float z) |
|
867 | { |
|
868 | // set standard float property |
|
869 | 0 | if (z >= 0.0F) |
870 | { |
|
871 | 0 | getProperties().put(Z_PROPERTY_NAME, String.valueOf(z)); |
872 | } |
|
873 | else |
|
874 | { |
|
875 | 0 | getProperties().remove(Z_PROPERTY_NAME); |
876 | } |
|
877 | 0 | } |
878 | ||
879 | /* (non-Javadoc) |
|
880 | * @see org.apache.jetspeed.om.page.Fragment#getLayoutWidth() |
|
881 | */ |
|
882 | public float getLayoutWidth() |
|
883 | { |
|
884 | // get standard float property |
|
885 | 0 | return getFloatProperty(WIDTH_PROPERTY_NAME); |
886 | } |
|
887 | ||
888 | /* (non-Javadoc) |
|
889 | * @see org.apache.jetspeed.om.page.Fragment#setLayoutWidth(float) |
|
890 | */ |
|
891 | public void setLayoutWidth(float width) |
|
892 | { |
|
893 | // set standard float property |
|
894 | 0 | if (width >= 0.0F) |
895 | { |
|
896 | 0 | getProperties().put(WIDTH_PROPERTY_NAME, String.valueOf(width)); |
897 | } |
|
898 | else |
|
899 | { |
|
900 | 0 | getProperties().remove(WIDTH_PROPERTY_NAME); |
901 | } |
|
902 | 0 | } |
903 | ||
904 | /* (non-Javadoc) |
|
905 | * @see org.apache.jetspeed.om.page.Fragment#getLayoutHeight() |
|
906 | */ |
|
907 | public float getLayoutHeight() |
|
908 | { |
|
909 | // get standard float property |
|
910 | 0 | return getFloatProperty(HEIGHT_PROPERTY_NAME); |
911 | } |
|
912 | ||
913 | /* (non-Javadoc) |
|
914 | * @see org.apache.jetspeed.om.page.Fragment#setLayoutHeight(float) |
|
915 | */ |
|
916 | public void setLayoutHeight(float height) |
|
917 | { |
|
918 | // set standard float property |
|
919 | 0 | if (height >= 0.0F) |
920 | { |
|
921 | 0 | getProperties().put(HEIGHT_PROPERTY_NAME, String.valueOf(height)); |
922 | } |
|
923 | else |
|
924 | { |
|
925 | 0 | getProperties().remove(HEIGHT_PROPERTY_NAME); |
926 | } |
|
927 | 0 | } |
928 | ||
929 | /* (non-Javadoc) |
|
930 | * @see org.apache.jetspeed.om.page.Fragment#isReference() |
|
931 | */ |
|
932 | public boolean isReference() |
|
933 | { |
|
934 | 0 | return false; // NYI |
935 | } |
|
936 | ||
937 | /* (non-Javadoc) |
|
938 | * @see org.apache.jetspeed.om.page.Fragment#getPreferences() |
|
939 | */ |
|
940 | public List getPreferences() |
|
941 | { |
|
942 | // return mutable preferences list |
|
943 | // by using list wrapper to manage |
|
944 | // element uniqueness |
|
945 | 0 | if (fragmentPreferences == null) |
946 | { |
|
947 | 0 | fragmentPreferences = new FragmentPreferenceList(this); |
948 | } |
|
949 | 0 | return fragmentPreferences; |
950 | } |
|
951 | ||
952 | /* (non-Javadoc) |
|
953 | * @see org.apache.jetspeed.om.page.Fragment#setPreferences(java.util.List) |
|
954 | */ |
|
955 | public void setPreferences(List preferences) |
|
956 | { |
|
957 | // set preferences by replacing existing |
|
958 | // entries with new elements if new collection |
|
959 | // is specified |
|
960 | 0 | List fragmentPreferences = getPreferences(); |
961 | 0 | if (preferences != fragmentPreferences) |
962 | { |
|
963 | // replace all preferences |
|
964 | 0 | fragmentPreferences.clear(); |
965 | 0 | if (preferences != null) |
966 | { |
|
967 | 0 | fragmentPreferences.addAll(preferences); |
968 | } |
|
969 | } |
|
970 | 0 | } |
971 | ||
972 | /** |
|
973 | * filterFragmentsByAccess |
|
974 | * |
|
975 | * Filter fragments list for view access. |
|
976 | * |
|
977 | * @param nodes list containing fragments to check |
|
978 | * @param mutable make returned list mutable |
|
979 | * @return original list if all elements viewable, a filtered |
|
980 | * partial list, or null if all filtered for view access |
|
981 | */ |
|
982 | List filterFragmentsByAccess(List fragments, boolean mutable) |
|
983 | { |
|
984 | 0 | if ((fragments != null) && !fragments.isEmpty()) |
985 | { |
|
986 | // check permissions and constraints, filter fragments as required |
|
987 | 0 | List filteredFragments = null; |
988 | 0 | Iterator checkAccessIter = fragments.iterator(); |
989 | 0 | while (checkAccessIter.hasNext()) |
990 | { |
|
991 | 0 | Fragment fragment = (Fragment)checkAccessIter.next(); |
992 | try |
|
993 | { |
|
994 | // check access |
|
995 | 0 | fragment.checkAccess(JetspeedActions.VIEW); |
996 | ||
997 | // add to filteredFragments fragments if copying |
|
998 | 0 | if (filteredFragments != null) |
999 | { |
|
1000 | // permitted, add to filteredFragments fragments |
|
1001 | 0 | filteredFragments.add(fragment); |
1002 | } |
|
1003 | } |
|
1004 | 0 | catch (SecurityException se) |
1005 | { |
|
1006 | // create filteredFragments fragments if not already copying |
|
1007 | 0 | if (filteredFragments == null) |
1008 | { |
|
1009 | // not permitted, copy previously permitted fragments |
|
1010 | // to new filteredFragments node set with same comparator |
|
1011 | 0 | filteredFragments = DatabasePageManagerUtils.createList(); |
1012 | 0 | Iterator copyIter = fragments.iterator(); |
1013 | 0 | while (copyIter.hasNext()) |
1014 | { |
|
1015 | 0 | Fragment copyFragment = (Fragment)copyIter.next(); |
1016 | 0 | if (copyFragment != fragment) |
1017 | { |
|
1018 | 0 | filteredFragments.add(copyFragment); |
1019 | } |
|
1020 | else |
|
1021 | { |
|
1022 | break; |
|
1023 | } |
|
1024 | 0 | } |
1025 | } |
|
1026 | 0 | } |
1027 | 0 | } |
1028 | ||
1029 | // return filteredFragments fragments if generated |
|
1030 | 0 | if (filteredFragments != null) |
1031 | { |
|
1032 | 0 | if (!filteredFragments.isEmpty()) |
1033 | { |
|
1034 | 0 | if (mutable) |
1035 | { |
|
1036 | 0 | return new FilteredFragmentList(this, filteredFragments); |
1037 | } |
|
1038 | else |
|
1039 | { |
|
1040 | 0 | return filteredFragments; |
1041 | } |
|
1042 | } |
|
1043 | else |
|
1044 | { |
|
1045 | 0 | return new FilteredFragmentList(this, filteredFragments); |
1046 | } |
|
1047 | } |
|
1048 | } |
|
1049 | 0 | return fragments; |
1050 | } |
|
1051 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |