Source Code Cross Referenced for FolderImpl.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » om » folder » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » jetspeed 2.1.3 » org.apache.jetspeed.om.folder.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.om.folder.impl;
018:
019:        import java.security.AccessController;
020:        import java.util.Collection;
021:        import java.util.Comparator;
022:        import java.util.Iterator;
023:        import java.util.List;
024:
025:        import org.apache.jetspeed.Jetspeed;
026:        import org.apache.jetspeed.JetspeedActions;
027:        import org.apache.jetspeed.om.folder.Folder;
028:        import org.apache.jetspeed.om.folder.FolderNotFoundException;
029:        import org.apache.jetspeed.om.folder.MenuDefinition;
030:        import org.apache.jetspeed.om.folder.MenuExcludeDefinition;
031:        import org.apache.jetspeed.om.folder.MenuIncludeDefinition;
032:        import org.apache.jetspeed.om.folder.MenuOptionsDefinition;
033:        import org.apache.jetspeed.om.folder.MenuSeparatorDefinition;
034:        import org.apache.jetspeed.om.page.Fragment;
035:        import org.apache.jetspeed.om.page.Link;
036:        import org.apache.jetspeed.om.page.Page;
037:        import org.apache.jetspeed.om.page.PageMetadataImpl;
038:        import org.apache.jetspeed.om.page.PageSecurity;
039:        import org.apache.jetspeed.om.page.impl.LinkImpl;
040:        import org.apache.jetspeed.om.page.impl.PageImpl;
041:        import org.apache.jetspeed.om.page.impl.PageSecurityImpl;
042:        import org.apache.jetspeed.page.PageManager;
043:        import org.apache.jetspeed.page.PageNotFoundException;
044:        import org.apache.jetspeed.page.document.DocumentException;
045:        import org.apache.jetspeed.page.document.DocumentNotFoundException;
046:        import org.apache.jetspeed.page.document.Node;
047:        import org.apache.jetspeed.page.document.NodeException;
048:        import org.apache.jetspeed.page.document.NodeNotFoundException;
049:        import org.apache.jetspeed.page.document.NodeSet;
050:        import org.apache.jetspeed.page.document.impl.NodeImpl;
051:        import org.apache.jetspeed.page.document.impl.NodeSetImpl;
052:        import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
053:        import org.apache.jetspeed.security.FolderPermission;
054:        import org.apache.ojb.broker.core.proxy.ProxyHelper;
055:
056:        /**
057:         * FolderImpl
058:         *
059:         * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
060:         * @version $Id$
061:         */
062:        public class FolderImpl extends NodeImpl implements  Folder {
063:            private String defaultPage;
064:            private String skin;
065:            private String defaultLayoutDecorator;
066:            private String defaultPortletDecorator;
067:            private List orders;
068:            private List menus;
069:
070:            private PageManager pageManager;
071:            private List folders;
072:            private boolean foldersCached;
073:            private List pages;
074:            private boolean pagesCached;
075:            private List links;
076:            private boolean linksCached;
077:            private PageSecurityImpl pageSecurity;
078:            private boolean pageSecurityCached;
079:            private List all;
080:            private boolean allCached;
081:            private FolderOrderList documentOrder;
082:            private boolean documentOrderComparatorValid;
083:            private Comparator documentOrderComparator;
084:            private NodeSet foldersNodeSet;
085:            private NodeSet pagesNodeSet;
086:            private NodeSet linksNodeSet;
087:            private NodeSet allNodeSet;
088:            private FolderMenuDefinitionList menuDefinitions;
089:
090:            public FolderImpl() {
091:                super (new FolderSecurityConstraintsImpl());
092:            }
093:
094:            /**
095:             * accessFolderOrders
096:             *
097:             * Access mutable persistent collection member for List wrappers.
098:             *
099:             * @return persistent collection
100:             */
101:            List accessFolderOrders() {
102:                // create initial collection if necessary
103:                if (orders == null) {
104:                    orders = DatabasePageManagerUtils.createList();
105:                }
106:                return orders;
107:            }
108:
109:            /**
110:             * accessMenus
111:             *
112:             * Access mutable persistent collection member for List wrappers.
113:             *
114:             * @return persistent collection
115:             */
116:            List accessMenus() {
117:                // create initial collection if necessary
118:                if (menus == null) {
119:                    menus = DatabasePageManagerUtils.createList();
120:                }
121:                return menus;
122:            }
123:
124:            /**
125:             * setPageManager
126:             *
127:             * Infuses PageManager for use by this folder instance.
128:             *
129:             * @param pageManager page manager that manages this folder instance
130:             */
131:            public void setPageManager(PageManager pageManager) {
132:                this .pageManager = pageManager;
133:            }
134:
135:            /**
136:             * accessFolders
137:             *
138:             * Access folders transient cache collection for use by PageManager.
139:             *
140:             * @return folders collection
141:             */
142:            public List accessFolders() {
143:                // create initial collection if necessary
144:                if (folders == null) {
145:                    folders = DatabasePageManagerUtils.createList();
146:                }
147:                return folders;
148:            }
149:
150:            /**
151:             * resetFolders
152:             *
153:             * Reset folders transient caches for use by PageManager.
154:             *
155:             * @param cached set cached state for folders
156:             */
157:            public void resetFolders(boolean cached) {
158:                // save cached state
159:                foldersCached = cached;
160:                allCached = false;
161:
162:                // update node caches
163:                if (!cached) {
164:                    accessFolders().clear();
165:                }
166:                accessAll().clear();
167:
168:                // reset cached node sets
169:                foldersNodeSet = null;
170:                allNodeSet = null;
171:            }
172:
173:            /**
174:             * accessPages
175:             *
176:             * Access pages transient cache collection for use by PageManager.
177:             *
178:             * @return pages collection
179:             */
180:            public List accessPages() {
181:                // create initial collection if necessary
182:                if (pages == null) {
183:                    pages = DatabasePageManagerUtils.createList();
184:                }
185:                return pages;
186:            }
187:
188:            /**
189:             * resetPages
190:             *
191:             * Reset pages transient caches for use by PageManager.
192:             *
193:             * @param cached set cached state for pages
194:             */
195:            public void resetPages(boolean cached) {
196:                // save cached state
197:                pagesCached = cached;
198:                allCached = false;
199:
200:                // update node caches
201:                if (!cached) {
202:                    accessPages().clear();
203:                }
204:                accessAll().clear();
205:
206:                // reset cached node sets
207:                pagesNodeSet = null;
208:                allNodeSet = null;
209:            }
210:
211:            /**
212:             * accessLinks
213:             *
214:             * Access links transient cache collection for use by PageManager.
215:             *
216:             * @return links collection
217:             */
218:            public List accessLinks() {
219:                // create initial collection if necessary
220:                if (links == null) {
221:                    links = DatabasePageManagerUtils.createList();
222:                }
223:                return links;
224:            }
225:
226:            /**
227:             * resetLinks
228:             *
229:             * Reset links transient caches for use by PageManager.
230:             *
231:             * @param cached set cached state for links
232:             */
233:            public void resetLinks(boolean cached) {
234:                // save cached state
235:                linksCached = cached;
236:                allCached = false;
237:
238:                // update node caches
239:                if (!cached) {
240:                    accessLinks().clear();
241:                }
242:                accessAll().clear();
243:
244:                // reset cached node sets
245:                linksNodeSet = null;
246:                allNodeSet = null;
247:            }
248:
249:            /**
250:             * accessPageSecurity
251:             *
252:             * Access pageSecurity cached instance for use by PageManager.
253:             *
254:             * @return pageSecurity instance
255:             */
256:            public PageSecurityImpl accessPageSecurity() {
257:                return pageSecurity;
258:            }
259:
260:            /**
261:             * resetPageSecurity
262:             *
263:             * Reset pageSecurity transient cache instance for use by PageManager.
264:             *
265:             * @param newPageSecurty cached page security instance.
266:             * @param cached set cached state for page security
267:             */
268:            public void resetPageSecurity(PageSecurityImpl newPageSecurity,
269:                    boolean cached) {
270:                // save cached state
271:                pageSecurity = newPageSecurity;
272:                pageSecurityCached = cached;
273:                allCached = false;
274:
275:                // update node caches
276:                accessAll().clear();
277:
278:                // reset cached node sets
279:                allNodeSet = null;
280:            }
281:
282:            /**
283:             * accessAll
284:             *
285:             * Access all transient cache collection for use by PageManager.
286:             *
287:             * @return all collection
288:             */
289:            public List accessAll() {
290:                // create initial collection if necessary
291:                if (all == null) {
292:                    all = DatabasePageManagerUtils.createList();
293:                }
294:                return all;
295:            }
296:
297:            /**
298:             * resetAll
299:             *
300:             * Reset all transient caches for use by PageManager.
301:             *
302:             * @param cached set cached state for all
303:             */
304:            public void resetAll(boolean cached) {
305:                // save cached state
306:                allCached = cached;
307:                foldersCached = cached;
308:                pagesCached = cached;
309:                linksCached = cached;
310:                pageSecurityCached = cached;
311:
312:                // update node caches
313:                accessFolders().clear();
314:                accessPages().clear();
315:                accessLinks().clear();
316:                pageSecurity = null;
317:                if (cached) {
318:                    // populate node caches
319:                    synchronized (all) {
320:                        Iterator nodeIter = accessAll().iterator();
321:                        while (nodeIter.hasNext()) {
322:                            Node node = (Node) nodeIter.next();
323:                            if (node instanceof  PageImpl) {
324:                                pages.add(node);
325:                            } else if (node instanceof  FolderImpl) {
326:                                folders.add(node);
327:                            } else if (node instanceof  LinkImpl) {
328:                                links.add(node);
329:                            } else if (node instanceof  PageSecurityImpl) {
330:                                pageSecurity = (PageSecurityImpl) node;
331:                            }
332:                        }
333:                    }
334:                } else {
335:                    accessAll().clear();
336:                }
337:
338:                // reset cached node sets
339:                allNodeSet = null;
340:                foldersNodeSet = null;
341:                pagesNodeSet = null;
342:                linksNodeSet = null;
343:            }
344:
345:            /**
346:             * createDocumentOrderComparator
347:             *
348:             * @return document order comparator
349:             */
350:            private Comparator createDocumentOrderComparator() {
351:                if (!documentOrderComparatorValid) {
352:                    documentOrderComparatorValid = true;
353:                    // return null if no document order exists;
354:                    // (null implies natural ordering by name)
355:                    final List documentOrder = getDocumentOrder();
356:                    if ((documentOrder == null) || documentOrder.isEmpty()) {
357:                        return null;
358:                    }
359:                    // create new document order comparator
360:                    documentOrderComparator = new Comparator() {
361:                        /* (non-Javadoc)
362:                         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
363:                         */
364:                        public int compare(Object o1, Object o2) {
365:                            // Compare node names using document order;
366:                            // use indicies as names if found in document
367:                            // order to force explicitly ordered items
368:                            // ahead of unordered items
369:                            String name1 = (String) o1;
370:                            int index1 = documentOrder.indexOf(name1);
371:                            if (index1 >= 0) {
372:                                // use order index as name1
373:                                name1 = String.valueOf(index1);
374:                            }
375:                            String name2 = (String) o2;
376:                            int index2 = documentOrder.indexOf(name2);
377:                            if (index2 >= 0) {
378:                                // use order index as name2
379:                                name2 = String.valueOf(index2);
380:                                if (index1 >= 0) {
381:                                    // pad order indicies for numeric string compare
382:                                    while (name1.length() != name2.length()) {
383:                                        if (name1.length() < name2.length()) {
384:                                            name1 = "0" + name1;
385:                                        } else {
386:                                            name2 = "0" + name2;
387:                                        }
388:                                    }
389:                                }
390:                            }
391:                            // compare names and/or indicies
392:                            return name1.compareTo(name2);
393:                        }
394:                    };
395:                }
396:                return documentOrderComparator;
397:            }
398:
399:            /**
400:             * clearDocumentOrderComparator
401:             */
402:            void clearDocumentOrderComparator() {
403:                // clear node set ordering
404:                documentOrderComparatorValid = false;
405:                documentOrderComparator = null;
406:                // clear previously cached node sets
407:                allNodeSet = null;
408:                foldersNodeSet = null;
409:                pagesNodeSet = null;
410:            }
411:
412:            /* (non-Javadoc)
413:             * @see org.apache.jetspeed.page.document.impl.NodeImpl#newPageMetadata(java.util.Collection)
414:             */
415:            public PageMetadataImpl newPageMetadata(Collection fields) {
416:                PageMetadataImpl pageMetadata = new PageMetadataImpl(
417:                        FolderMetadataLocalizedFieldImpl.class);
418:                pageMetadata.setFields(fields);
419:                return pageMetadata;
420:            }
421:
422:            /* (non-Javadoc)
423:             * @see org.apache.jetspeed.om.page.impl.BaseElementImpl#getEffectivePageSecurity()
424:             */
425:            public PageSecurity getEffectivePageSecurity() {
426:                // return page security instance if available
427:                if (!pageSecurityCached) {
428:                    // use PageManager to get and cache page security
429:                    // instance for this folder
430:                    try {
431:                        return getPageManager().getPageSecurity(this );
432:                    } catch (NodeException ne) {
433:                    } catch (NodeNotFoundException nnfe) {
434:                    }
435:                } else if (pageSecurity != null) {
436:                    return pageSecurity;
437:                }
438:
439:                // delegate to real parent folder implementation
440:                FolderImpl parentFolderImpl = (FolderImpl) ProxyHelper
441:                        .getRealObject(getParent());
442:                if (parentFolderImpl != null) {
443:                    return parentFolderImpl.getEffectivePageSecurity();
444:                }
445:                return null;
446:            }
447:
448:            /* (non-Javadoc)
449:             * @see org.apache.jetspeed.om.page.impl.BaseElementImpl#checkPermissions(java.lang.String, int, boolean, boolean)
450:             */
451:            public void checkPermissions(String path, int mask,
452:                    boolean checkNodeOnly, boolean checkParentsOnly)
453:                    throws SecurityException {
454:                // check granted folder permissions unless the check is
455:                // to be skipped due to explicity granted access
456:                if (!checkParentsOnly) {
457:                    FolderPermission permission = new FolderPermission(path,
458:                            mask);
459:                    AccessController.checkPermission(permission);
460:                }
461:
462:                // if not checking node only, recursively check
463:                // all parent permissions in hierarchy
464:                if (!checkNodeOnly) {
465:                    FolderImpl parentFolderImpl = (FolderImpl) ProxyHelper
466:                            .getRealObject(getParent());
467:                    if (parentFolderImpl != null) {
468:                        parentFolderImpl.checkPermissions(mask, false, false);
469:                    }
470:                }
471:            }
472:
473:            /* (non-Javadoc)
474:             * @see org.apache.jetspeed.om.page.BaseElement#getTitle()
475:             */
476:            public String getTitle() {
477:                // default title to folder name
478:                String title = super .getTitle();
479:                if (title == null) {
480:                    title = defaultTitleFromName();
481:                    setTitle(title);
482:                }
483:                return title;
484:            }
485:
486:            /* (non-Javadoc)
487:             * @see org.apache.jetspeed.om.folder.Folder#getSkin()
488:             */
489:            public String getSkin() {
490:                return skin;
491:            }
492:
493:            /* (non-Javadoc)
494:             * @see org.apache.jetspeed.om.folder.Folder#setSkin(java.lang.String)
495:             */
496:            public void setSkin(String skinName) {
497:                this .skin = skinName;
498:            }
499:
500:            /* (non-Javadoc)
501:             * @see org.apache.jetspeed.om.folder.Folder#getEffectiveDefaultDecorator(java.lang.String)
502:             */
503:            public String getEffectiveDefaultDecorator(String fragmentType) {
504:                // get locally defined decorator
505:                String decorator = getDefaultDecorator(fragmentType);
506:                if (decorator == null) {
507:                    // delegate to parent folder
508:                    Folder parentFolder = (Folder) ProxyHelper
509:                            .getRealObject(getParent());
510:                    if (parentFolder != null) {
511:                        return parentFolder
512:                                .getEffectiveDefaultDecorator(fragmentType);
513:                    }
514:                }
515:                return decorator;
516:            }
517:
518:            /* (non-Javadoc)
519:             * @see org.apache.jetspeed.om.folder.Folder#getDefaultDecorator(java.lang.String)
520:             */
521:            public String getDefaultDecorator(String fragmentType) {
522:                // retrieve supported decorator types
523:                if (fragmentType != null) {
524:                    if (fragmentType.equals(Fragment.LAYOUT)) {
525:                        return defaultLayoutDecorator;
526:                    }
527:                    if (fragmentType.equals(Fragment.PORTLET)) {
528:                        return defaultPortletDecorator;
529:                    }
530:                }
531:                return null;
532:            }
533:
534:            /* (non-Javadoc)
535:             * @see org.apache.jetspeed.om.folder.Folder#getDefaultDecorator(java.lang.String,java.lang.String)
536:             */
537:            public void setDefaultDecorator(String decoratorName,
538:                    String fragmentType) {
539:                // save supported decorator types
540:                if (fragmentType != null) {
541:                    if (fragmentType.equals(Fragment.LAYOUT)) {
542:                        defaultLayoutDecorator = decoratorName;
543:                    }
544:                    if (fragmentType.equals(Fragment.PORTLET)) {
545:                        defaultPortletDecorator = decoratorName;
546:                    }
547:                }
548:            }
549:
550:            /* (non-Javadoc)
551:             * @see org.apache.jetspeed.om.folder.Folder#getDocumentOrder()
552:             */
553:            public List getDocumentOrder() {
554:                // return mutable document order list
555:                // by using list wrapper to manage sort
556:                // order and element uniqueness
557:                if (documentOrder == null) {
558:                    documentOrder = new FolderOrderList(this );
559:                }
560:                return documentOrder;
561:            }
562:
563:            /* (non-Javadoc)
564:             * @see org.apache.jetspeed.om.folder.Folder#setDocumentOrder(java.util.List)
565:             */
566:            public void setDocumentOrder(List docNames) {
567:                // set document order using ordered document
568:                // names by replacing existing entries with
569:                // new elements if new collection is specified
570:                List documentOrder = getDocumentOrder();
571:                if (docNames != documentOrder) {
572:                    // replace all document order names
573:                    documentOrder.clear();
574:                    if (docNames != null) {
575:                        documentOrder.addAll(docNames);
576:                    }
577:                }
578:            }
579:
580:            /* (non-Javadoc)
581:             * @see org.apache.jetspeed.om.folder.Folder#getDefaultPage()
582:             */
583:            public String getDefaultPage() {
584:                return defaultPage;
585:            }
586:
587:            /* (non-Javadoc)
588:             * @see org.apache.jetspeed.om.folder.Folder#setDefaultPage(java.lang.String)
589:             */
590:            public void setDefaultPage(String defaultPage) {
591:                this .defaultPage = defaultPage;
592:            }
593:
594:            /* (non-Javadoc)
595:             * @see org.apache.jetspeed.om.folder.Folder#getFolders()
596:             */
597:            public NodeSet getFolders() throws DocumentException {
598:                // get folders collection
599:                if (!foldersCached) {
600:                    // use PageManager to get and cache folders
601:                    // collection for this folder
602:                    return getPageManager().getFolders(this );
603:                }
604:
605:                // return nodes with view access
606:                return filterNodeSetByAccess(getFoldersNodeSet());
607:            }
608:
609:            /* (non-Javadoc)
610:             * @see org.apache.jetspeed.om.folder.Folder#getFolder(java.lang.String)
611:             */
612:            public Folder getFolder(String name)
613:                    throws FolderNotFoundException, DocumentException {
614:                // get folder instance if folders collection not available
615:                if (!foldersCached) {
616:                    // use PageManager to get folder instance without
617:                    // caching the folders collection for this folder
618:                    return getPageManager().getFolder(this , name);
619:                }
620:
621:                // select folder by name from cached folders collection
622:                Folder folder = (Folder) getFoldersNodeSet().get(name);
623:                if (folder == null) {
624:                    throw new FolderNotFoundException("Folder not found: "
625:                            + name);
626:                }
627:
628:                // check for view access on folder
629:                folder.checkAccess(JetspeedActions.VIEW);
630:
631:                return folder;
632:            }
633:
634:            /* (non-Javadoc)
635:             * @see org.apache.jetspeed.om.folder.Folder#getPages()
636:             */
637:            public NodeSet getPages() throws NodeException {
638:                // get pages collection
639:                if (!pagesCached) {
640:                    // use PageManager to get and cache pages
641:                    // collection for this folder
642:                    return getPageManager().getPages(this );
643:                }
644:
645:                // return nodes with view access
646:                return filterNodeSetByAccess(getPagesNodeSet());
647:            }
648:
649:            /* (non-Javadoc)
650:             * @see org.apache.jetspeed.om.folder.Folder#getPage(java.lang.String)
651:             */
652:            public Page getPage(String name) throws PageNotFoundException,
653:                    NodeException {
654:                // get page instance if pages collection not available
655:                if (!pagesCached) {
656:                    // use PageManager to get page instance without
657:                    // caching the pages collection for this folder
658:                    return getPageManager().getPage(this , name);
659:                }
660:
661:                // select page by name from cached pages collection
662:                Page page = (Page) getPagesNodeSet().get(name);
663:                if (page == null) {
664:                    throw new PageNotFoundException("Page not found: " + name);
665:                }
666:
667:                // check for view access on page
668:                page.checkAccess(JetspeedActions.VIEW);
669:
670:                return page;
671:            }
672:
673:            /* (non-Javadoc)
674:             * @see org.apache.jetspeed.om.folder.Folder#getLinks()
675:             */
676:            public NodeSet getLinks() throws NodeException {
677:                // get links collection
678:                if (!linksCached) {
679:                    // use PageManager to get and cache links
680:                    // collection for this folder
681:                    return getPageManager().getLinks(this );
682:                }
683:
684:                // return nodes with view access
685:                return filterNodeSetByAccess(getLinksNodeSet());
686:            }
687:
688:            /* (non-Javadoc)
689:             * @see org.apache.jetspeed.om.folder.Folder#getLink(java.lang.String)
690:             */
691:            public Link getLink(String name) throws DocumentNotFoundException,
692:                    NodeException {
693:                // get link instance if links collection not available
694:                if (!linksCached) {
695:                    // use PageManager to get link instance without
696:                    // caching the links collection for this folder
697:                    return getPageManager().getLink(this , name);
698:                }
699:
700:                // select link by name from cached links collection
701:                Link link = (Link) getLinksNodeSet().get(name);
702:                if (link == null) {
703:                    throw new DocumentNotFoundException("Link not found: "
704:                            + name);
705:                }
706:
707:                // check for view access on link
708:                link.checkAccess(JetspeedActions.VIEW);
709:
710:                return link;
711:            }
712:
713:            /* (non-Javadoc)
714:             * @see org.apache.jetspeed.om.folder.Folder#getPageSecurity()
715:             */
716:            public PageSecurity getPageSecurity()
717:                    throws DocumentNotFoundException, NodeException {
718:                // get page security instance
719:                if (!pageSecurityCached) {
720:                    // use PageManager to get and cache page security
721:                    // instance for this folder
722:                    return getPageManager().getPageSecurity(this );
723:                }
724:                if (pageSecurity == null) {
725:                    throw new DocumentNotFoundException(
726:                            "Page security document not found");
727:                }
728:
729:                // check for view access on document
730:                pageSecurity.checkAccess(JetspeedActions.VIEW);
731:
732:                return pageSecurity;
733:            }
734:
735:            /* (non-Javadoc)
736:             * @see org.apache.jetspeed.om.folder.Folder#getAll()
737:             */
738:            public NodeSet getAll() throws DocumentException {
739:                // get all nodes collection
740:                if (!allCached) {
741:                    // use PageManager to get and cache all nodes
742:                    // collection for this folder
743:                    return getPageManager().getAll(this );
744:                }
745:
746:                // return nodes with view access
747:                return filterNodeSetByAccess(getAllNodeSet());
748:            }
749:
750:            /* (non-Javadoc)
751:             * @see org.apache.jetspeed.om.folder.Folder#getMenuDefinitions()
752:             */
753:            public List getMenuDefinitions() {
754:                // return mutable menu definition list
755:                // by using list wrapper to manage
756:                // element uniqueness
757:                if (menuDefinitions == null) {
758:                    menuDefinitions = new FolderMenuDefinitionList(this );
759:                }
760:                return menuDefinitions;
761:            }
762:
763:            /* (non-Javadoc)
764:             * @see org.apache.jetspeed.om.folder.Folder#newMenuDefinition()
765:             */
766:            public MenuDefinition newMenuDefinition() {
767:                return new FolderMenuDefinitionImpl();
768:            }
769:
770:            /* (non-Javadoc)
771:             * @see org.apache.jetspeed.om.folder.Folder#newMenuExcludeDefinition()
772:             */
773:            public MenuExcludeDefinition newMenuExcludeDefinition() {
774:                return new FolderMenuExcludeDefinitionImpl();
775:            }
776:
777:            /* (non-Javadoc)
778:             * @see org.apache.jetspeed.om.folder.Folder#newMenuIncludeDefinition()
779:             */
780:            public MenuIncludeDefinition newMenuIncludeDefinition() {
781:                return new FolderMenuIncludeDefinitionImpl();
782:            }
783:
784:            /* (non-Javadoc)
785:             * @see org.apache.jetspeed.om.folder.Folder#newMenuOptionsDefinition()
786:             */
787:            public MenuOptionsDefinition newMenuOptionsDefinition() {
788:                return new FolderMenuOptionsDefinitionImpl();
789:            }
790:
791:            /* (non-Javadoc)
792:             * @see org.apache.jetspeed.om.folder.Folder#newMenuSeparatorDefinition()
793:             */
794:            public MenuSeparatorDefinition newMenuSeparatorDefinition() {
795:                return new FolderMenuSeparatorDefinitionImpl();
796:            }
797:
798:            /* (non-Javadoc)
799:             * @see org.apache.jetspeed.om.folder.Folder#setMenuDefinitions(java.util.List)
800:             */
801:            public void setMenuDefinitions(List definitions) {
802:                // set menu definitions by replacing
803:                // existing entries with new elements if
804:                // new collection is specified
805:                List menuDefinitions = getMenuDefinitions();
806:                if (definitions != menuDefinitions) {
807:                    // replace all menu definitions
808:                    menuDefinitions.clear();
809:                    if (definitions != null) {
810:                        menuDefinitions.addAll(definitions);
811:                    }
812:                }
813:            }
814:
815:            /* (non-Javadoc)
816:             * @see org.apache.jetspeed.om.folder.Folder#isReserved()
817:             */
818:            public boolean isReserved() {
819:                // folders are always concrete in this implementation
820:                return false;
821:            }
822:
823:            /* (non-Javadoc)
824:             * @see org.apache.jetspeed.om.folder.Folder#getReservedType()
825:             */
826:            public int getReservedType() {
827:                // folders are always concrete in this implementation
828:                return RESERVED_FOLDER_NONE;
829:            }
830:
831:            /* (non-Javadoc)
832:             * @see org.apache.jetspeed.page.document.Node#getType()
833:             */
834:            public String getType() {
835:                return FOLDER_TYPE;
836:            }
837:
838:            /**
839:             * getFoldersNodeSet
840:             *
841:             * Latently create and access folders node set.
842:             *
843:             * @return folders node set
844:             */
845:            private NodeSet getFoldersNodeSet() {
846:                if (foldersNodeSet == null) {
847:                    if ((folders != null) && !folders.isEmpty()) {
848:                        foldersNodeSet = new NodeSetImpl(folders,
849:                                createDocumentOrderComparator());
850:                    } else {
851:                        foldersNodeSet = NodeSetImpl.EMPTY_NODE_SET;
852:                    }
853:                }
854:                return foldersNodeSet;
855:            }
856:
857:            /**
858:             * getPagesNodeSet
859:             *
860:             * Latently create and access pages node set.
861:             *
862:             * @return folders node set
863:             */
864:            private NodeSet getPagesNodeSet() throws NodeException {
865:                if (pagesNodeSet == null) {
866:                    if ((pages != null) && !pages.isEmpty()) {
867:                        pagesNodeSet = new NodeSetImpl(pages,
868:                                createDocumentOrderComparator());
869:                    } else {
870:                        pagesNodeSet = NodeSetImpl.EMPTY_NODE_SET;
871:                    }
872:                }
873:                return pagesNodeSet;
874:            }
875:
876:            /**
877:             * getLinksNodeSet
878:             *
879:             * Latently create and access links node set.
880:             *
881:             * @return folders node set
882:             */
883:            private NodeSet getLinksNodeSet() throws NodeException {
884:                if (linksNodeSet == null) {
885:                    if ((links != null) && !links.isEmpty()) {
886:                        linksNodeSet = new NodeSetImpl(links,
887:                                createDocumentOrderComparator());
888:                    } else {
889:                        linksNodeSet = NodeSetImpl.EMPTY_NODE_SET;
890:                    }
891:                }
892:                return linksNodeSet;
893:            }
894:
895:            /**
896:             * getAllNodeSet
897:             *
898:             * Latently create and access all nodes node set.
899:             *
900:             * @return all nodes node set
901:             */
902:            private NodeSet getAllNodeSet() {
903:                if (allNodeSet == null) {
904:                    if ((all != null) && !all.isEmpty()) {
905:                        List allCopy = new java.util.ArrayList();
906:                        synchronized (all) {
907:                            allCopy.addAll(all);
908:                        }
909:                        allNodeSet = new NodeSetImpl(allCopy,
910:                                createDocumentOrderComparator());
911:                    } else {
912:                        allNodeSet = NodeSetImpl.EMPTY_NODE_SET;
913:                    }
914:                }
915:                return allNodeSet;
916:            }
917:
918:            /**
919:             * filterNodeSetByAccess
920:             *
921:             * Filter node set elements for view access.
922:             *
923:             * @param nodes node set containing nodes to check
924:             * @return checked subset of nodes
925:             */
926:            static NodeSet filterNodeSetByAccess(NodeSet nodes) {
927:                if ((nodes != null) && !nodes.isEmpty()) {
928:                    // check permissions and constraints, filter nodes as required
929:                    NodeSetImpl filteredNodes = null;
930:                    Iterator checkAccessIter = nodes.iterator();
931:                    while (checkAccessIter.hasNext()) {
932:                        Node node = (Node) checkAccessIter.next();
933:                        try {
934:                            // check access
935:                            node.checkAccess(JetspeedActions.VIEW);
936:
937:                            // add to filteredNodes nodes if copying
938:                            if (filteredNodes != null) {
939:                                // permitted, add to filteredNodes nodes
940:                                filteredNodes.add(node);
941:                            }
942:                        } catch (SecurityException se) {
943:                            // create filteredNodes nodes if not already copying
944:                            if (filteredNodes == null) {
945:                                // not permitted, copy previously permitted nodes
946:                                // to new filteredNodes node set with same comparator
947:                                filteredNodes = new NodeSetImpl(nodes);
948:                                Iterator copyIter = nodes.iterator();
949:                                while (copyIter.hasNext()) {
950:                                    Node copyNode = (Node) copyIter.next();
951:                                    if (copyNode != node) {
952:                                        filteredNodes.add(copyNode);
953:                                    } else {
954:                                        break;
955:                                    }
956:                                }
957:                            }
958:                        }
959:                    }
960:
961:                    // return filteredNodes nodes if generated
962:                    if (filteredNodes != null) {
963:                        return filteredNodes;
964:                    }
965:                }
966:                return nodes;
967:            }
968:
969:            public PageManager getPageManager() {
970:                if (pageManager == null) {
971:                    pageManager = (PageManager) Jetspeed.getComponentManager()
972:                            .getComponent("PageManager");
973:                }
974:                return pageManager;
975:            }
976:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.