Source Code Cross Referenced for CastorXmlPageManager.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » page » psml » 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.page.psml 
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:
018:        package org.apache.jetspeed.page.psml;
019:
020:        import java.io.FileNotFoundException;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.Map;
024:
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:        import org.apache.jetspeed.JetspeedActions;
028:        import org.apache.jetspeed.cache.file.FileCache;
029:        import org.apache.jetspeed.cache.file.FileCacheEntry;
030:        import org.apache.jetspeed.cache.file.FileCacheEventListener;
031:        import org.apache.jetspeed.idgenerator.IdGenerator;
032:        import org.apache.jetspeed.om.folder.Folder;
033:        import org.apache.jetspeed.om.folder.FolderNotFoundException;
034:        import org.apache.jetspeed.om.folder.InvalidFolderException;
035:        import org.apache.jetspeed.om.folder.psml.FolderImpl;
036:        import org.apache.jetspeed.om.folder.psml.MenuDefinitionImpl;
037:        import org.apache.jetspeed.om.folder.psml.MenuExcludeDefinitionImpl;
038:        import org.apache.jetspeed.om.folder.psml.MenuIncludeDefinitionImpl;
039:        import org.apache.jetspeed.om.folder.psml.MenuOptionsDefinitionImpl;
040:        import org.apache.jetspeed.om.folder.psml.MenuSeparatorDefinitionImpl;
041:        import org.apache.jetspeed.om.page.ContentPage;
042:        import org.apache.jetspeed.om.page.ContentPageImpl;
043:        import org.apache.jetspeed.om.page.Fragment;
044:        import org.apache.jetspeed.om.page.Link;
045:        import org.apache.jetspeed.om.page.Page;
046:        import org.apache.jetspeed.om.page.PageSecurity;
047:        import org.apache.jetspeed.om.page.SecurityConstraintImpl;
048:        import org.apache.jetspeed.om.page.SecurityConstraintsDef;
049:        import org.apache.jetspeed.om.page.psml.FragmentImpl;
050:        import org.apache.jetspeed.om.page.psml.FragmentPreferenceImpl;
051:        import org.apache.jetspeed.om.page.psml.LinkImpl;
052:        import org.apache.jetspeed.om.page.psml.PageImpl;
053:        import org.apache.jetspeed.om.page.psml.PageSecurityImpl;
054:        import org.apache.jetspeed.om.page.psml.SecurityConstraintsDefImpl;
055:        import org.apache.jetspeed.om.page.psml.SecurityConstraintsImpl;
056:        import org.apache.jetspeed.page.AbstractPageManager;
057:        import org.apache.jetspeed.page.FolderNotUpdatedException;
058:        import org.apache.jetspeed.page.PageManager;
059:        import org.apache.jetspeed.page.PageManagerSecurityUtils;
060:        import org.apache.jetspeed.page.PageNotFoundException;
061:        import org.apache.jetspeed.page.document.DocumentException;
062:        import org.apache.jetspeed.page.document.DocumentHandlerFactory;
063:        import org.apache.jetspeed.page.document.DocumentNotFoundException;
064:        import org.apache.jetspeed.page.document.FailedToDeleteDocumentException;
065:        import org.apache.jetspeed.page.document.FailedToUpdateDocumentException;
066:        import org.apache.jetspeed.page.document.FolderHandler;
067:        import org.apache.jetspeed.page.document.Node;
068:        import org.apache.jetspeed.page.document.NodeException;
069:        import org.apache.jetspeed.page.document.NodeSet;
070:        import org.apache.jetspeed.page.document.UnsupportedDocumentTypeException;
071:        import org.apache.jetspeed.page.document.psml.NodeSetImpl;
072:
073:        /**
074:         * This service is responsible for loading and saving PSML pages serialized to
075:         * disk
076:         * 
077:         * @author <a href="mailto:raphael@apache.org">Rapha�l Luta </a>
078:         * @author <a href="mailto:weaver@apache.org">Scott T Weaver </a>
079:         * @version $Id: CastorXmlPageManager.java 516448 2007-03-09 16:25:47Z ate $
080:         */
081:        public class CastorXmlPageManager extends AbstractPageManager implements 
082:                PageManager, FileCacheEventListener {
083:            private final static Log log = LogFactory
084:                    .getLog(CastorXmlPageManager.class);
085:
086:            private static Map modelClasses = new HashMap();
087:            static {
088:                modelClasses.put("FragmentImpl", FragmentImpl.class);
089:                modelClasses.put("PageImpl", PageImpl.class);
090:                modelClasses.put("FolderImpl", FolderImpl.class);
091:                modelClasses.put("LinkImpl", LinkImpl.class);
092:                modelClasses.put("PageSecurityImpl", PageSecurityImpl.class);
093:                modelClasses.put("FolderMenuDefinitionImpl",
094:                        MenuDefinitionImpl.class);
095:                modelClasses.put("FolderMenuExcludeDefinitionImpl",
096:                        MenuExcludeDefinitionImpl.class);
097:                modelClasses.put("FolderMenuIncludeDefinitionImpl",
098:                        MenuIncludeDefinitionImpl.class);
099:                modelClasses.put("FolderMenuOptionsDefinitionImpl",
100:                        MenuOptionsDefinitionImpl.class);
101:                modelClasses.put("FolderMenuSeparatorDefinitionImpl",
102:                        MenuSeparatorDefinitionImpl.class);
103:                modelClasses.put("PageMenuDefinitionImpl",
104:                        MenuDefinitionImpl.class);
105:                modelClasses.put("PageMenuExcludeDefinitionImpl",
106:                        MenuExcludeDefinitionImpl.class);
107:                modelClasses.put("PageMenuIncludeDefinitionImpl",
108:                        MenuIncludeDefinitionImpl.class);
109:                modelClasses.put("PageMenuOptionsDefinitionImpl",
110:                        MenuOptionsDefinitionImpl.class);
111:                modelClasses.put("PageMenuSeparatorDefinitionImpl",
112:                        MenuSeparatorDefinitionImpl.class);
113:                modelClasses.put("SecurityConstraintsImpl",
114:                        SecurityConstraintsImpl.class);
115:                modelClasses.put("FolderSecurityConstraintImpl",
116:                        SecurityConstraintImpl.class);
117:                modelClasses.put("PageSecurityConstraintImpl",
118:                        SecurityConstraintImpl.class);
119:                modelClasses.put("FragmentSecurityConstraintImpl",
120:                        SecurityConstraintImpl.class);
121:                modelClasses.put("LinkSecurityConstraintImpl",
122:                        SecurityConstraintImpl.class);
123:                modelClasses.put("PageSecuritySecurityConstraintImpl",
124:                        SecurityConstraintImpl.class);
125:                modelClasses.put("SecurityConstraintsDefImpl",
126:                        SecurityConstraintsDefImpl.class);
127:                modelClasses.put("FragmentPreferenceImpl",
128:                        FragmentPreferenceImpl.class);
129:            }
130:
131:            private IdGenerator generator = null;
132:            private DocumentHandlerFactory handlerFactory;
133:            private FolderHandler folderHandler;
134:            private FileCache fileCache;
135:
136:            public CastorXmlPageManager(IdGenerator generator,
137:                    DocumentHandlerFactory handlerFactory,
138:                    FolderHandler folderHandler, FileCache fileCache,
139:                    boolean permissionsEnabled, boolean constraintsEnabled)
140:                    throws FileNotFoundException {
141:                super (permissionsEnabled, constraintsEnabled, modelClasses);
142:                this .generator = generator;
143:                handlerFactory.setPermissionsEnabled(permissionsEnabled);
144:                handlerFactory.setConstraintsEnabled(constraintsEnabled);
145:                this .handlerFactory = handlerFactory;
146:                this .folderHandler = folderHandler;
147:                this .fileCache = fileCache;
148:                this .fileCache.addListener(this );
149:            }
150:
151:            /**
152:             * <p>
153:             * newFragment
154:             * </p>
155:             * 
156:             * @see org.apache.jetspeed.page.PageManager#newFragment()
157:             * @return fragment
158:             */
159:            public Fragment newFragment() {
160:                // FragmentImpl requires generated ids
161:                FragmentImpl fragment = (FragmentImpl) super .newFragment();
162:                fragment.setId(generator.getNextPeid());
163:                return fragment;
164:            }
165:
166:            public Fragment newPortletFragment() {
167:                // FragmentImpl requires generated ids
168:                FragmentImpl fragment = (FragmentImpl) super .newFragment();
169:                fragment.setType(Fragment.PORTLET);
170:                fragment.setId(generator.getNextPeid());
171:                return fragment;
172:            }
173:
174:            /**
175:             * <p>
176:             * getPage
177:             * </p>
178:             * 
179:             * @see org.apache.jetspeed.page.PageManager#getPage(java.lang.String)
180:             * @param path
181:             * @return page
182:             * @throws PageNotFoundException
183:             * @throws NodeException
184:             * @throws FolderNotFoundException
185:             */
186:            public Page getPage(String path) throws PageNotFoundException,
187:                    NodeException {
188:                // get page via folder, (access checked in Folder.getPage())
189:                try {
190:                    FolderImpl folder = getNodeFolder(path);
191:                    return folder.getPage(getNodeName(path));
192:                } catch (FolderNotFoundException fnfe) {
193:                    throw new PageNotFoundException(fnfe.getMessage());
194:                }
195:            }
196:
197:            /**
198:             * <p>
199:             * updatePage
200:             * </p>
201:             * 
202:             * @see org.apache.jetspeed.services.page.PageManagerService#updatePage(org.apache.jetspeed.om.page.Page)
203:             */
204:            public void updatePage(Page page) throws NodeException {
205:                // unwrap page to be registered
206:                if (page instanceof  ContentPageImpl) {
207:                    page = ((ContentPageImpl) page).getPage();
208:                }
209:
210:                // make sure path and related members are set
211:                if (page.getPath() != null) {
212:                    if (!page.getPath().equals(page.getId())) {
213:                        log.error("Page paths and ids must match!");
214:                        return;
215:                    }
216:                } else {
217:                    log.error("Page paths and ids must be set!");
218:                    return;
219:                }
220:
221:                try {
222:                    // set parent
223:                    boolean newPage = false;
224:                    FolderImpl parentFolder = getNodeFolder(page.getPath());
225:                    if (page.getParent() == null) {
226:                        page.setParent(parentFolder);
227:                        newPage = true;
228:                    }
229:
230:                    // enable permissions/constraints
231:                    PageImpl pageImpl = (PageImpl) page;
232:                    pageImpl.setPermissionsEnabled(handlerFactory
233:                            .getPermissionsEnabled());
234:                    pageImpl.setConstraintsEnabled(handlerFactory
235:                            .getConstraintsEnabled());
236:
237:                    // check for edit access
238:                    page.checkAccess(JetspeedActions.EDIT);
239:
240:                    // update page
241:                    handlerFactory.getDocumentHandler(Page.DOCUMENT_TYPE)
242:                            .updateDocument(page);
243:
244:                    // update parent folder
245:                    if (parentFolder != null) {
246:                        NodeSetImpl parentAllNodes = (NodeSetImpl) parentFolder
247:                                .getAllNodes();
248:                        if (!parentAllNodes.contains(page)) {
249:                            // add new page
250:                            parentAllNodes.add(page);
251:                            newPage = true;
252:                        } else if (parentAllNodes.get(page.getPath()) != page) {
253:                            // remove stale page and add updated page
254:                            parentAllNodes.remove(page);
255:                            parentAllNodes.add(page);
256:                        }
257:                    }
258:
259:                    // notify page manager listeners
260:                    if (newPage) {
261:                        notifyNewNode(page);
262:                    } else {
263:                        notifyUpdatedNode(page);
264:                    }
265:                } catch (FolderNotFoundException fnfe) {
266:                    throw new NodeException(fnfe.getMessage());
267:                }
268:            }
269:
270:            /**
271:             * <p>
272:             * removePage
273:             * </p>
274:             * 
275:             * @see org.apache.jetspeed.services.page.PageManagerService#removePage(org.apache.jetspeed.om.page.Page)
276:             */
277:            public void removePage(Page page) throws NodeException {
278:                // unwrap page to be removed
279:                if (page instanceof  ContentPageImpl) {
280:                    page = ((ContentPageImpl) page).getPage();
281:                }
282:
283:                // check for edit access
284:                page.checkAccess(JetspeedActions.EDIT);
285:
286:                try {
287:                    FolderImpl folder = getNodeFolder(page.getPath());
288:
289:                    // remove page
290:                    handlerFactory.getDocumentHandler(Page.DOCUMENT_TYPE)
291:                            .removeDocument(page);
292:
293:                    // update folder
294:                    ((NodeSetImpl) folder.getAllNodes()).remove(page);
295:
296:                    // notify page manager listeners
297:                    notifyRemovedNode(page);
298:                } catch (FolderNotFoundException fnfe) {
299:                    throw new NodeException(fnfe.getMessage());
300:                } catch (DocumentNotFoundException dnfe) {
301:                    throw new NodeException(dnfe.getMessage());
302:                }
303:            }
304:
305:            /**
306:             * <p>
307:             * getLink
308:             * </p>
309:             * 
310:             * @see org.apache.jetspeed.page.PageManager#getLink(java.lang.String)
311:             * @param path
312:             * @return link
313:             * @throws DocumentNotFoundException
314:             * @throws UnsupportedDocumentTypeException
315:             * @throws NodeException
316:             */
317:            public Link getLink(String path) throws DocumentNotFoundException,
318:                    UnsupportedDocumentTypeException, NodeException {
319:                // get link via folder, (access checked in Folder.getLink())
320:                try {
321:                    FolderImpl folder = getNodeFolder(path);
322:                    return folder.getLink(getNodeName(path));
323:                } catch (FolderNotFoundException fnfe) {
324:                    throw new DocumentNotFoundException(fnfe.getMessage());
325:                }
326:            }
327:
328:            /**
329:             * <p>
330:             * updateLink
331:             * </p>
332:             * 
333:             * @see org.apache.jetspeed.services.page.PageManagerService#updateLink(org.apache.jetspeed.om.page.Link)
334:             */
335:            public void updateLink(Link link) throws NodeException {
336:                // make sure path and related members are set
337:                if (link.getPath() != null) {
338:                    if (!link.getPath().equals(link.getId())) {
339:                        log.error("Link paths and ids must match!");
340:                        return;
341:                    }
342:                } else {
343:                    log.error("Link paths and ids must be set!");
344:                    return;
345:                }
346:
347:                try {
348:                    // set parent
349:                    boolean newLink = false;
350:                    FolderImpl parentFolder = getNodeFolder(link.getPath());
351:                    if (link.getParent() == null) {
352:                        link.setParent(parentFolder);
353:                        newLink = true;
354:                    }
355:
356:                    // enable permissions/constraints
357:                    LinkImpl linkImpl = (LinkImpl) link;
358:                    linkImpl.setPermissionsEnabled(handlerFactory
359:                            .getPermissionsEnabled());
360:                    linkImpl.setConstraintsEnabled(handlerFactory
361:                            .getConstraintsEnabled());
362:
363:                    // check for edit access
364:                    link.checkAccess(JetspeedActions.EDIT);
365:
366:                    // update link
367:                    handlerFactory.getDocumentHandler(Link.DOCUMENT_TYPE)
368:                            .updateDocument(link);
369:
370:                    // update parent folder
371:                    if (parentFolder != null) {
372:                        NodeSetImpl parentAllNodes = (NodeSetImpl) parentFolder
373:                                .getAllNodes();
374:                        if (!parentAllNodes.contains(link)) {
375:                            // add new link
376:                            parentAllNodes.add(link);
377:                            newLink = true;
378:                        } else if (parentAllNodes.get(link.getPath()) != link) {
379:                            // remove stale link and add updated link
380:                            parentAllNodes.remove(link);
381:                            parentAllNodes.add(link);
382:                        }
383:                    }
384:
385:                    // notify page manager listeners
386:                    if (newLink) {
387:                        notifyNewNode(link);
388:                    } else {
389:                        notifyUpdatedNode(link);
390:                    }
391:                } catch (FolderNotFoundException fnfe) {
392:                    throw new NodeException(fnfe.getMessage());
393:                }
394:            }
395:
396:            /**
397:             * <p>
398:             * removeLink
399:             * </p>
400:             * 
401:             * @see org.apache.jetspeed.services.page.PageManagerService#removeLink(org.apache.jetspeed.om.page.Link)
402:             */
403:            public void removeLink(Link link) throws NodeException {
404:                // check for edit access
405:                link.checkAccess(JetspeedActions.EDIT);
406:
407:                try {
408:                    FolderImpl folder = getNodeFolder(link.getPath());
409:
410:                    // remove link
411:                    handlerFactory.getDocumentHandler(Link.DOCUMENT_TYPE)
412:                            .removeDocument(link);
413:
414:                    // update folder
415:                    ((NodeSetImpl) folder.getAllNodes()).remove(link);
416:
417:                    // notify page manager listeners
418:                    notifyRemovedNode(link);
419:                } catch (FolderNotFoundException fnfe) {
420:                    throw new NodeException(fnfe.getMessage());
421:                } catch (DocumentNotFoundException dnfe) {
422:                    throw new NodeException(dnfe.getMessage());
423:                }
424:            }
425:
426:            public boolean checkConstraint(String securityConstraintName,
427:                    String actions) {
428:                try {
429:                    PageSecurity security = this .getPageSecurity();
430:                    SecurityConstraintsDef def = security
431:                            .getSecurityConstraintsDef(securityConstraintName);
432:                    if (def != null) {
433:                        return PageManagerSecurityUtils.checkConstraint(def,
434:                                actions);
435:                    }
436:                } catch (Exception e) {
437:                    log.error(e.getMessage(), e);
438:                }
439:                return false;
440:            }
441:
442:            /**
443:             * <p>
444:             * getPageSecurity
445:             * </p>
446:             * 
447:             * @see org.apache.jetspeed.page.PageManager#getPageSecurity()
448:             * @return page security instance
449:             * @throws DocumentNotFoundException
450:             * @throws UnsupportedDocumentTypeException
451:             * @throws NodeException
452:             */
453:            public PageSecurity getPageSecurity()
454:                    throws DocumentNotFoundException,
455:                    UnsupportedDocumentTypeException, NodeException {
456:                // get page security via folder, (always allow access)
457:                try {
458:                    FolderImpl folder = getNodeFolder(Folder.PATH_SEPARATOR);
459:                    return folder.getPageSecurity();
460:                } catch (FolderNotFoundException fnfe) {
461:                    throw new DocumentNotFoundException(fnfe.getMessage());
462:                }
463:            }
464:
465:            /* (non-Javadoc)
466:             * @see org.apache.jetspeed.page.PageManager#updatePageSecurity(org.apache.jetspeed.om.page.PageSecurity)
467:             */
468:            public void updatePageSecurity(PageSecurity pageSecurity)
469:                    throws NodeException, FailedToUpdateDocumentException {
470:                // validate path... must exist in root folder and
471:                // make sure path and related members are set
472:                if (pageSecurity.getPath() != null) {
473:                    if (!pageSecurity.getPath().equals(
474:                            Folder.PATH_SEPARATOR + PageSecurity.DOCUMENT_TYPE)) {
475:                        log.error("PageSecurity path must be: "
476:                                + Folder.PATH_SEPARATOR
477:                                + PageSecurity.DOCUMENT_TYPE);
478:                        return;
479:                    }
480:                    if (!pageSecurity.getPath().equals(pageSecurity.getId())) {
481:                        log.error("PageSecurity paths and ids must match!");
482:                        return;
483:                    }
484:                } else {
485:                    log.error("PageSecurity paths and ids must be set!");
486:                    return;
487:                }
488:
489:                try {
490:                    // set parent
491:                    boolean newPageSecurity = false;
492:                    FolderImpl parentFolder = getNodeFolder(Folder.PATH_SEPARATOR);
493:                    if (pageSecurity.getParent() == null) {
494:                        pageSecurity.setParent(parentFolder);
495:                        newPageSecurity = true;
496:                    }
497:
498:                    // enable permissions/constraints
499:                    PageSecurityImpl pageSecurityImpl = (PageSecurityImpl) pageSecurity;
500:                    pageSecurityImpl.setPermissionsEnabled(handlerFactory
501:                            .getPermissionsEnabled());
502:                    pageSecurityImpl.setConstraintsEnabled(handlerFactory
503:                            .getConstraintsEnabled());
504:
505:                    // check for edit access
506:                    pageSecurity.checkAccess(JetspeedActions.EDIT);
507:
508:                    // update pageSecurity
509:                    handlerFactory.getDocumentHandler(
510:                            PageSecurity.DOCUMENT_TYPE).updateDocument(
511:                            pageSecurity);
512:
513:                    // update parent folder
514:                    if (parentFolder != null) {
515:                        NodeSetImpl parentAllNodes = (NodeSetImpl) parentFolder
516:                                .getAllNodes();
517:                        if (!parentAllNodes.contains(pageSecurity)) {
518:                            // add new page security
519:                            parentAllNodes.add(pageSecurity);
520:                            newPageSecurity = true;
521:                        } else if (parentAllNodes.get(pageSecurity.getPath()) != pageSecurity) {
522:                            // remove stale page security and add updated page security
523:                            parentAllNodes.remove(pageSecurity);
524:                            parentAllNodes.add(pageSecurity);
525:                        }
526:                    }
527:
528:                    // notify page manager listeners
529:                    if (newPageSecurity) {
530:                        notifyNewNode(pageSecurity);
531:                    } else {
532:                        notifyUpdatedNode(pageSecurity);
533:                    }
534:                } catch (FolderNotFoundException fnfe) {
535:                    throw new NodeException(fnfe.getMessage());
536:                }
537:            }
538:
539:            /* (non-Javadoc)
540:             * @see org.apache.jetspeed.page.PageManager#removePageSecurity(org.apache.jetspeed.om.page.PageSecurity)
541:             */
542:            public void removePageSecurity(PageSecurity pageSecurity)
543:                    throws NodeException, FailedToDeleteDocumentException {
544:                // check for edit access
545:                pageSecurity.checkAccess(JetspeedActions.EDIT);
546:
547:                try {
548:                    FolderImpl folder = getNodeFolder(Folder.PATH_SEPARATOR);
549:
550:                    // remove page security
551:                    handlerFactory.getDocumentHandler(
552:                            PageSecurity.DOCUMENT_TYPE).removeDocument(
553:                            pageSecurity);
554:
555:                    // update folder
556:                    ((NodeSetImpl) folder.getAllNodes()).remove(pageSecurity);
557:
558:                    // notify page manager listeners
559:                    notifyRemovedNode(pageSecurity);
560:                } catch (FolderNotFoundException fnfe) {
561:                    throw new NodeException(fnfe.getMessage());
562:                } catch (DocumentNotFoundException dnfe) {
563:                    throw new NodeException(dnfe.getMessage());
564:                }
565:            }
566:
567:            /**
568:             * <p>
569:             * getFolder
570:             * </p>
571:             * 
572:             * @see org.apache.jetspeed.page.PageManager#getFolder(java.lang.String)
573:             * @param folderPath
574:             * @return folder instance
575:             * @throws FolderNotFoundException
576:             * @throws NodeException
577:             * @throws InvalidFolderException
578:             */
579:            public Folder getFolder(String folderPath)
580:                    throws FolderNotFoundException, InvalidFolderException,
581:                    NodeException {
582:                // get folder and check access before returning
583:                Folder folder = folderHandler.getFolder(folderPath);
584:                folder.checkAccess(JetspeedActions.VIEW);
585:                return folder;
586:            }
587:
588:            /* (non-Javadoc)
589:             * @see org.apache.jetspeed.page.PageManager#getFolders(org.apache.jetspeed.om.folder.Folder)
590:             */
591:            public NodeSet getFolders(Folder folder) throws DocumentException {
592:                // delegate back to folder instance
593:                return folder.getFolders();
594:            }
595:
596:            /* (non-Javadoc)
597:             * @see org.apache.jetspeed.page.PageManager#getFolder(org.apache.jetspeed.om.folder.Folder,java.lang.String)
598:             */
599:            public Folder getFolder(Folder folder, String name)
600:                    throws FolderNotFoundException, DocumentException {
601:                // delegate back to folder instance
602:                return folder.getFolder(name);
603:            }
604:
605:            /* (non-Javadoc)
606:             * @see org.apache.jetspeed.page.PageManager#getPages(org.apache.jetspeed.om.folder.Folder)
607:             */
608:            public NodeSet getPages(Folder folder) throws NodeException {
609:                // delegate back to folder instance
610:                return folder.getPages();
611:            }
612:
613:            /* (non-Javadoc)
614:             * @see org.apache.jetspeed.page.PageManager#getPage(org.apache.jetspeed.om.folder.Folder,java.lang.String)
615:             */
616:            public Page getPage(Folder folder, String name)
617:                    throws PageNotFoundException, NodeException {
618:                // delegate back to folder instance
619:                return folder.getPage(name);
620:            }
621:
622:            /* (non-Javadoc)
623:             * @see org.apache.jetspeed.page.PageManager#getLinks(org.apache.jetspeed.om.folder.Folder)
624:             */
625:            public NodeSet getLinks(Folder folder) throws NodeException {
626:                // delegate back to folder instance
627:                return folder.getLinks();
628:            }
629:
630:            /* (non-Javadoc)
631:             * @see org.apache.jetspeed.page.PageManager#getLink(org.apache.jetspeed.om.folder.Folder,java.lang.String)
632:             */
633:            public Link getLink(Folder folder, String name)
634:                    throws DocumentNotFoundException, NodeException {
635:                // delegate back to folder instance
636:                return folder.getLink(name);
637:            }
638:
639:            /* (non-Javadoc)
640:             * @see org.apache.jetspeed.page.PageManager#getPageSecurity(org.apache.jetspeed.om.folder.Folder)
641:             */
642:            public PageSecurity getPageSecurity(Folder folder)
643:                    throws DocumentNotFoundException, NodeException {
644:                // delegate back to folder instance
645:                return folder.getPageSecurity();
646:            }
647:
648:            /* (non-Javadoc)
649:             * @see org.apache.jetspeed.page.PageManager#getAll(org.apache.jetspeed.om.folder.Folder)
650:             */
651:            public NodeSet getAll(Folder folder) throws DocumentException {
652:                // delegate back to folder instance
653:                return folder.getAll();
654:            }
655:
656:            /**
657:             * <p>
658:             * updateFolder
659:             * </p>
660:             * 
661:             * @see org.apache.jetspeed.services.page.PageManagerService#updateFolder(org.apache.jetspeed.om.folder.Folder)
662:             */
663:            public void updateFolder(Folder folder) throws NodeException,
664:                    FolderNotUpdatedException {
665:                // shallow update by default
666:                updateFolder(folder, false);
667:            }
668:
669:            /* (non-Javadoc)
670:             * @see org.apache.jetspeed.page.PageManager#updateFolder(org.apache.jetspeed.om.folder.Folder,boolean)
671:             */
672:            public void updateFolder(Folder folder, boolean deep)
673:                    throws NodeException, FolderNotUpdatedException {
674:                // make sure path and related members are set
675:                if (folder.getPath() != null) {
676:                    if (!folder.getPath().equals(folder.getId())) {
677:                        log.error("Folder paths and ids must match!");
678:                        return;
679:                    }
680:                } else {
681:                    log.error("Folder paths and ids must be set!");
682:                    return;
683:                }
684:
685:                try {
686:                    // set parent
687:                    boolean newFolder = false;
688:                    FolderImpl parentFolder = null;
689:                    if (!folder.getPath().equals(Folder.PATH_SEPARATOR)) {
690:                        parentFolder = getNodeFolder(folder.getPath());
691:                        if (folder.getParent() == null) {
692:                            folder.setParent(parentFolder);
693:                            newFolder = true;
694:                        }
695:                    } else {
696:                        folder.setParent(null);
697:                    }
698:
699:                    // enable permissions/constraints and configure
700:                    // folder handler before access is checked
701:                    FolderImpl folderImpl = (FolderImpl) folder;
702:                    folderImpl.setPermissionsEnabled(handlerFactory
703:                            .getPermissionsEnabled());
704:                    folderImpl.setConstraintsEnabled(handlerFactory
705:                            .getConstraintsEnabled());
706:                    folderImpl.setFolderHandler(folderHandler);
707:
708:                    // check for edit access
709:                    folder.checkAccess(JetspeedActions.EDIT);
710:
711:                    // update folder
712:                    folderHandler.updateFolder(folder);
713:
714:                    // update parent folder
715:                    if (parentFolder != null) {
716:                        NodeSetImpl parentAllNodes = (NodeSetImpl) parentFolder
717:                                .getAllNodes();
718:                        if (!parentAllNodes.contains(folder)) {
719:                            // add new folder
720:                            parentAllNodes.add(folder);
721:                            newFolder = true;
722:                        } else if (parentAllNodes.get(folder.getPath()) != folder) {
723:                            // remove stale folder and add updated folder
724:                            parentAllNodes.remove(folder);
725:                            parentAllNodes.add(folder);
726:                        }
727:                    }
728:
729:                    // update deep recursively if specified
730:                    if (deep) {
731:                        // update recursively, (breadth first)
732:                        updateFolderNodes(folderImpl);
733:                    }
734:
735:                    // notify page manager listeners
736:                    if (newFolder) {
737:                        notifyNewNode(folder);
738:                    } else {
739:                        notifyUpdatedNode(folder);
740:                    }
741:                } catch (FolderNotFoundException fnfe) {
742:                    throw new NodeException(fnfe.getMessage());
743:                }
744:            }
745:
746:            /**
747:             * updateFolderNodes - recusively update all folder nodes
748:             *
749:             * @param folderImpl folder whose nodes are to be updated
750:             * @param throws FolderNotUpdatedException
751:             */
752:            private void updateFolderNodes(FolderImpl folderImpl)
753:                    throws FolderNotUpdatedException {
754:                try {
755:                    // update folder documents
756:                    NodeSet nodes = folderImpl.getAllNodes();
757:                    Iterator nodesIter = nodes.iterator();
758:                    while (nodesIter.hasNext()) {
759:                        Node node = (Node) nodesIter.next();
760:                        if (node instanceof  Page) {
761:                            updatePage((Page) node);
762:                        } else if (node instanceof  Link) {
763:                            updateLink((Link) node);
764:                        } else if (node instanceof  PageSecurity) {
765:                            updatePageSecurity((PageSecurity) node);
766:                        }
767:                    }
768:
769:                    // update folders last: breadth first recursion
770:                    nodesIter = nodes.iterator();
771:                    while (nodesIter.hasNext()) {
772:                        Node node = (Node) nodesIter.next();
773:                        if (node instanceof  Folder) {
774:                            updateFolder((Folder) node, true);
775:                        }
776:                    }
777:                } catch (FolderNotUpdatedException fnue) {
778:                    throw fnue;
779:                } catch (SecurityException se) {
780:                    throw se;
781:                } catch (Exception e) {
782:                    throw new FolderNotUpdatedException("Folder "
783:                            + folderImpl.getPath() + " not updated.", e);
784:                }
785:            }
786:
787:            /**
788:             * <p>
789:             * removeFolder
790:             * </p>
791:             * 
792:             * @see org.apache.jetspeed.services.page.PageManagerService#removeFolder(org.apache.jetspeed.om.folder.Folder)
793:             */
794:            public void removeFolder(Folder folder) throws NodeException {
795:                // check for edit access
796:                folder.checkAccess(JetspeedActions.EDIT);
797:
798:                try {
799:                    FolderImpl parentFolder = null;
800:                    if (!folder.getPath().equals(Folder.PATH_SEPARATOR)) {
801:                        parentFolder = getNodeFolder(folder.getPath());
802:                    }
803:
804:                    // remove folder
805:                    folderHandler.removeFolder(folder);
806:
807:                    // update parent folder
808:                    if (parentFolder != null) {
809:                        ((NodeSetImpl) parentFolder.getAllNodes())
810:                                .remove(folder);
811:                    }
812:
813:                    // notify page manager listeners
814:                    notifyRemovedNode(folder);
815:                } catch (FolderNotFoundException fnfe) {
816:                    throw new NodeException(fnfe.getMessage());
817:                }
818:            }
819:
820:            /* (non-Javadoc)
821:             * @see org.apache.jetspeed.page.PageManager#reset()
822:             */
823:            public void reset() {
824:                // propagate to super
825:                super .reset();
826:
827:                // evict all from file cache to force subsequent
828:                // refreshs from persistent store
829:                fileCache.evictAll();
830:            }
831:
832:            /**
833:             * <p>
834:             * getNodeFolder - get folder implementation associated with specifed path
835:             * </p>
836:             * 
837:             * @param nodePath
838:             * @return folder impl instance
839:             * @throws NodeException
840:             * @throws InvalidFolderException
841:             * @throws FolderNotFoundException
842:             */
843:            private FolderImpl getNodeFolder(String nodePath)
844:                    throws NodeException, InvalidFolderException,
845:                    FolderNotFoundException {
846:                int folderIndex = nodePath.lastIndexOf(Folder.PATH_SEPARATOR);
847:                if (folderIndex > 0) {
848:                    return (FolderImpl) folderHandler.getFolder(nodePath
849:                            .substring(0, folderIndex));
850:                }
851:                return (FolderImpl) folderHandler
852:                        .getFolder(Folder.PATH_SEPARATOR);
853:            }
854:
855:            /**
856:             * <p>
857:             * getNodeFolder - get name of node from specified path
858:             * </p>
859:             * 
860:             * @param nodePath
861:             * @return name of node
862:             */
863:            private String getNodeName(String nodePath) {
864:                int folderIndex = nodePath.lastIndexOf(Folder.PATH_SEPARATOR);
865:                if (folderIndex > -1) {
866:                    return nodePath.substring(folderIndex + 1);
867:                }
868:                return nodePath;
869:            }
870:
871:            /**
872:             * <p>
873:             * refresh file cache entry
874:             * </p>
875:             * 
876:             * @see org.apache.jetspeed.cache.file.FileCacheEventListener#refresh(org.apache.jetspeed.cache.file.FileCacheEntry)
877:             * @param entry
878:             * @throws Exception
879:             */
880:            public void refresh(FileCacheEntry entry) throws Exception {
881:                // file cache managed component refreshed:
882:                // notify page manager listeners
883:                Node refreshedNode = null;
884:                if (entry.getDocument() instanceof  Node) {
885:                    refreshedNode = (Node) entry.getDocument();
886:                }
887:                if (entry.getFile().exists()) {
888:                    notifyUpdatedNode(refreshedNode);
889:                } else {
890:                    notifyRemovedNode(refreshedNode);
891:                }
892:            }
893:
894:            /**
895:             * <p>
896:             * evict file cache entry
897:             * </p>
898:             * 
899:             * @see org.apache.jetspeed.cache.file.FileCacheEventListener#evict(org.apache.jetspeed.cache.file.FileCacheEntry)
900:             * @param entry
901:             * @throws Exception
902:             */
903:            public void evict(FileCacheEntry entry) throws Exception {
904:                // file cache managed component evicted:
905:                // no notifications required since eviction
906:                // is normal cache operation and does not
907:                // indicate a change in the nodes managed by
908:                // this page manager
909:            }
910:
911:            /* (non-Javadoc)
912:             * @see org.apache.jetspeed.page.PageManager#getContentPage(java.lang.String)
913:             */
914:            public ContentPage getContentPage(String path)
915:                    throws PageNotFoundException, NodeException {
916:                return new ContentPageImpl(getPage(path));
917:            }
918:
919:            public Page copy(Page source) {
920:                return null;
921:            }
922:
923:            public int addPages(Page[] pages) throws NodeException {
924:                this .updatePage(pages[0]);
925:                this .updatePage(pages[1]);
926:                throw new NodeException("Its gonna blow captain!");
927:            }
928:
929:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.