KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > cms > manager > CmsManagerSlideImpl


1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2001 The Apache Software Foundation. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  * if any, must include the following acknowledgment:
21  * "This product includes software developed by the
22  * Apache Software Foundation (http://www.apache.org/)."
23  * Alternately, this acknowledgment may appear in the software itself,
24  * if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "Apache" and "Apache Software Foundation" and
27  * "Apache Jetspeed" must not be used to endorse or promote products
28  * derived from this software without prior written permission. For
29  * written permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache",
32  * "Apache Jetspeed", nor may "Apache" appear in their name, without
33  * prior written permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation. For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  */

54
55 package org.apache.jetspeed.services.cms.manager;
56 /**
57  * Slide implementation for the CmsManager
58  *
59  * @author <a HREF="mailto:christophe.lombart@skynet.be">Christophe Lombart</a>
60  *
61  */

62
63 // Java 2 SDK
64
import java.util.*;
65 import java.io.FileWriter JavaDoc;
66 import java.io.FileInputStream JavaDoc;
67 import java.util.Vector JavaDoc;
68
69 // Turbine
70
import org.apache.turbine.services.TurbineServices;
71 import org.apache.turbine.services.resources.TurbineResources;
72 import org.apache.turbine.util.upload.FileItem;
73 import org.apache.turbine.util.Log;
74
75 // Slide
76

77 import org.apache.slide.structure.*;
78 import org.apache.slide.content.*;
79 import org.apache.slide.common.*;
80 import org.apache.slide.lock.*;
81 import org.apache.slide.security.*;
82 import org.apache.slide.authenticate.CredentialsToken;
83 import org.apache.slide.authenticate.SecurityToken;
84 import org.apache.slide.security.AccessDeniedException;
85
86 // Jetspeed
87
import org.apache.jetspeed.om.cms.*;
88 import org.apache.jetspeed.om.cms.slide.SlideResource;
89 import org.apache.jetspeed.services.cms.repository.slide.Utility;
90 import org.apache.jetspeed.services.cms.CmsService;
91 import org.apache.jetspeed.services.cms.JetspeedCMSException;
92 import org.apache.jetspeed.services.rundata.JetspeedRunDataService;
93 import org.apache.jetspeed.services.rundata.JetspeedRunData;
94 import org.apache.turbine.services.rundata.RunDataService;
95
96 public class CmsManagerSlideImpl implements CmsManager
97 {
98
99     private NamespaceAccessToken token = null;
100     private Structure structure = null;
101     private Security security = null;
102     private Content content = null;
103     private Lock lock = null;
104     private static String JavaDoc PROPERTY_CLASS_NAME = "resourceClassName";
105     String JavaDoc nameSpace = null;
106
107     /**
108     * Initialise the CmsManager.
109     * @param nameSpace used assigned to the CmsManager. This namespace can be
110     * used to read parameters assigned to this namespace in the JR.prop
111     */

112     public void init (String JavaDoc namespace)
113             throws JetspeedCMSException
114     {
115         try
116         {
117             String JavaDoc domainFile =TurbineResources.getString("services.CmsService.CmsManager." + namespace + ".domainfile");
118             Domain.init(new FileInputStream JavaDoc(domainFile));
119         }
120         catch (Exception JavaDoc e)
121         {
122             throw new JetspeedCMSException();
123         }
124
125         token = Domain.accessNamespace(new SecurityToken(new String JavaDoc()), namespace);
126
127         structure = token.getStructureHelper();
128         security = token.getSecurityHelper();
129         content = token.getContentHelper();
130         lock = token.getLockHelper();
131         this.nameSpace = namespace;
132     }
133
134     /**
135     * Export the CMS repository into an xml file
136     * @param userNode User reference
137     * @param xmlFileName output file
138     */

139
140     public void exportRepository (String JavaDoc xmlFileName)
141            throws JetspeedCMSException
142     {
143         try
144         {
145             String JavaDoc userNode = this.getSlideUserNode();
146             SlideToken slideToken = this.getSlideToken ( userNode );
147             token.exportData(slideToken, new FileWriter JavaDoc( xmlFileName ));
148         }
149         catch (Exception JavaDoc e)
150         {
151             throw new JetspeedCMSException("Impossible to export the content respository");
152         }
153     }
154
155     /**
156     * Populate a catalog structure from the repository
157     *
158     * @param userNode User reference
159     * @param Catalog object to populate
160     */

161     public void populateCatalog (Catalog catalog)
162            throws JetspeedCMSException
163     {
164         this.populateCatalog(catalog, true, true, -1);
165     }
166
167     /**
168     * Populate a catalog structure from the repository
169     *
170     * @param userNode User reference
171     * @param catalog object to populate
172     * @param withSubCatalog - retrieve or not sub-catalogs
173     * @param withContent - retrieve or not child ContentItems
174     */

175     public void populateCatalog (Catalog catalog,
176                                  boolean withSubCatalog, boolean withContent)
177            throws JetspeedCMSException
178     {
179         this.populateCatalog(catalog, withSubCatalog,
180                              withContent, -1);
181                              
182     }
183
184     /**
185     * Populate a catalog structure from the repository
186     *
187     * @param userNode User reference
188     * @param catalog object to populate
189     * @param withSubCatalog - retrieve or not sub-catalogs
190     * @param withContent - retrieve or not child ContentItems
191     * @param numberOfLevels - number of tree level to populate
192     */

193     public void populateCatalog (Catalog catalog,
194                                  boolean withSubCatalog, boolean withContent,
195                                  int numberOfLevels )
196            throws JetspeedCMSException
197     {
198         try
199         {
200             String JavaDoc userNode = this.getSlideUserNode();
201             int tmpLevel = numberOfLevels ;
202             SlideToken slideToken = this.getSlideToken ( userNode );
203             ObjectNode objectNode = structure.retrieve(slideToken, catalog.getUri(), true);
204
205             // ----------------- Get catalog children
206
//Enumeration childrenUri = structure.getChildren(slideToken,objectNode);
207
Enumeration childrenUri = objectNode.enumerateChildren();
208             //Enumeration childrenUri = objectNode.getChildren();
209

210             this.getChildren(userNode, childrenUri, catalog,
211                              withSubCatalog, withContent, numberOfLevels);
212
213             // ----------------- Get links
214
Enumeration linksUri = objectNode.enumerateLinks();
215             this.getChildren(userNode, linksUri, catalog,
216                              withSubCatalog, withContent, tmpLevel);
217         }
218         catch (Exception JavaDoc e)
219         {
220             throw new JetspeedCMSException("Impossible to get catalog information");
221         }
222     }
223
224     /**
225     * Get all children from a specific parent uri
226     *
227     * @param userNode User reference
228     * @param parentUri uri used to get children
229     */

230     public Vector JavaDoc getUriList (String JavaDoc parentUri)
231            throws JetspeedCMSException
232     {
233         try
234         {
235             
236             String JavaDoc userNode = this.getSlideUserNode();
237             Vector JavaDoc uriList = new Vector JavaDoc();
238
239             // Add the parent uri
240
uriList.add(parentUri);
241             //System.out.println("URI : " + parentUri);
242

243             // Retrieve children
244
SlideToken slideToken = this.getSlideToken ( userNode );
245             ObjectNode objectNode = structure.retrieve(slideToken, parentUri);
246             Enumeration children = objectNode.enumerateChildren();
247
248             // Add children to the vector
249
while (children.hasMoreElements())
250             {
251                 String JavaDoc uriChild = (String JavaDoc) children.nextElement();
252                 Vector JavaDoc v = this.getUriList(uriChild);
253                 uriList.addAll(v);
254             }
255
256             return uriList;
257         }
258         catch (Exception JavaDoc e)
259         {
260            throw new JetspeedCMSException("Impossible to get the uri List");
261         }
262     }
263
264
265     /**
266     * Get a resource object (Catalog or ContentItem) from the repository
267     * based on a uri.
268     * @param userNode User reference
269     * @param uri
270     * @return resource that match to this uri
271     */

272     public Resource getResource (String JavaDoc uri )
273            throws JetspeedCMSException
274     {
275
276         SlideResource resource = null;
277
278         try
279         {
280             String JavaDoc userNode = this.getSlideUserNode();
281             
282             // Get the last NodeRevisionDescriptor
283
SlideToken slideToken = this.getSlideToken( userNode );
284
285             // uri parameter can be point to a linkNode => retrieve its target
286
// objectnode
287
ObjectNode objectNode = structure.retrieve(slideToken, uri, true);
288
289             // Get the last Node revision descriptor
290
NodeRevisionDescriptors revisionDescriptors =
291                  content.retrieve(slideToken, objectNode.getUri());
292             NodeRevisionDescriptor revisionDescriptor =
293                  content.retrieve(slideToken, revisionDescriptors);
294
295             // Check if the resource is a Catalog or an ContentItem
296
// (based on the property class name) & an create an object for this resource
297
NodeProperty p = revisionDescriptor.getProperty(PROPERTY_CLASS_NAME);
298             String JavaDoc className = (String JavaDoc) p.getValue();
299             resource = (SlideResource) Class.forName( className ).newInstance();
300             resource.setUri(uri);
301             // Populate the resource properties
302
resource.setDescriptor(revisionDescriptor);
303
304             // populate Security info
305
resource.setPermissions(this.getSecurity(uri));
306             return resource;
307         }
308         catch (AccessDeniedException e)
309         {
310             JetspeedCMSException e1 = new JetspeedCMSException("Impossible to get the content resource");
311             e1.setIsAccessDenied(true);
312             throw e1;
313         }
314         catch (NullPointerException JavaDoc e)
315         {
316             // Trigger when the objectNode has not the correct properties
317
// eg. : for a User or Action node in Slide. These type of node are mapped to Catalog
318

319             Catalog catalog = (Catalog) CmsFactory.getCmsOmInstance("Catalog");
320             catalog.setUri(uri);
321             catalog.setLogicalName(uri);
322             catalog.setTitle(uri);
323             return catalog;
324         }
325         catch (RevisionDescriptorNotFoundException e)
326         {
327             // if no revision descriptor => create an empty catalog object which
328
// contains the uri data, a default title and a default logical name
329
// This case arrives when the descriptor stores are not init by the
330
// method Slide.createResource(...)
331
// For example, after reading domain.xml, Slide will add all
332
// namespace defined in the "scoop" xml tag in the target store
333
// But in our case, we need different properties defined via the
334
// NodeRevisionDescriptor like the title, logical name, ...
335

336             if (uri.equals(TurbineResources.getString("services.CmsService.catalog.root.uri")))
337             {
338                 Catalog catalog = (Catalog) CmsFactory.getCmsOmInstance("Catalog");
339                 catalog.setUri(uri);
340                 catalog.setLogicalName(TurbineResources.getString("services.CmsService.catalog.root.logicalname"));
341                 catalog.setTitle(TurbineResources.getString("services.CmsService.catalog.root.title"));
342                 return catalog;
343             }
344             else
345             {
346                 // getResource called for a user/action ...
347
Catalog catalog = (Catalog) CmsFactory.getCmsOmInstance("Catalog");
348                 catalog.setUri(uri);
349                 catalog.setLogicalName(uri);
350                 catalog.setTitle(uri);
351                 return catalog;
352                 //e.printStackTrace();
353
//return null;
354
}
355         }
356         catch ( Exception JavaDoc e)
357         {
358             throw new JetspeedCMSException("Impossible to get the content resource");
359         }
360     }
361
362     /**
363     * Get all catalogs defined between 2 uri (from - to)
364     *
365     * @param userNode User reference
366     * @param fromuri : first element of the interval
367     * @param toUri : last element of the interval
368     * @return catalogs found between both uri
369     */

370     public Vector JavaDoc getCatalogs(String JavaDoc fromUri, String JavaDoc toUri)
371            throws JetspeedCMSException
372     {
373
374         Vector JavaDoc catalogs = new Vector JavaDoc();
375         String JavaDoc currentUri = toUri;
376
377         while ( true )
378         {
379             try
380             {
381                 Catalog catalog = (Catalog) this.getResource(currentUri);
382                 catalogs.insertElementAt(catalog, 0);
383
384                 if ((currentUri.equals(fromUri)) ||
385                     (catalog.getParentUri() == null) ||
386                     (catalog.getParentUri().equals("")) )
387                 {
388                     break;
389                 }
390
391                 currentUri = catalog.getParentUri();
392             }
393             catch (JetspeedCMSException e)
394             {
395                 // If the exception is accessDenied : continue the loop for other catalog
396
// else throw the exception
397
if (!e.isAccessDenied())
398                 {
399                     throw new JetspeedCMSException("Impossible to get the complete catalog path");
400                 }
401             }
402         }
403
404         return catalogs;
405     }
406
407     /**
408     * Get Security information assigned to an uri
409     * @param userNode User reference
410     * @param uri for which the security info is asked
411     */

412     public Vector JavaDoc getSecurity (String JavaDoc uri )
413            throws JetspeedCMSException
414     {
415         try
416         {
417             String JavaDoc userNode = this.getSlideUserNode();
418             
419             // Get the SlideToken in function of a SubjectNode string
420
SlideToken slideToken = this.getSlideToken( userNode );
421             // Retrieve security info
422
Enumeration e = security.enumeratePermissions(slideToken, uri);
423             Vector JavaDoc permissions = new Vector JavaDoc();
424
425             while (e.hasMoreElements())
426             {
427                 org.apache.slide.security.NodePermission node =
428                     (org.apache.slide.security.NodePermission) e.nextElement();
429                 Permission p = (Permission) CmsFactory.getCmsOmInstance("Permission");
430                 p.setAction(node.getActionUri());
431                 p.setActor(node.getSubjectUri());
432                 p.setInheritable(node.isInheritable());
433                 p.setNegative(node.isNegative());
434                 permissions.add(p);
435             }
436
437             return permissions;
438         }
439         catch (Exception JavaDoc e)
440         {
441             throw new JetspeedCMSException("Impossible to get the security information " + uri);
442         }
443     }
444
445     /**
446     * Grant permission to an uri
447     * @param userNode User reference
448     * @param uri on which permission has to be set
449     * @param userUri User uri reference
450     * @param actionUri Action used in the permission (read, modify, write, ...)
451     * @param inheritable true if the permission has to be apply on child uri
452     * @param negative true if the permission is negative
453     */

454     public void grantPermission (String JavaDoc objectUri , String JavaDoc userUri,
455                                  String JavaDoc actionUri, boolean inheritable,
456                                  boolean negative)
457            throws JetspeedCMSException
458     {
459
460         try
461         {
462
463             String JavaDoc userNode = this.getSlideUserNode();
464             // Get the SlideToken in function of a SubjectNode string
465
SlideToken slideToken = this.getSlideToken( userNode );
466
467             // uri parameter can be point to a linkNode => retrieve its target
468
// objectnode
469
ObjectNode objectNode = structure.retrieve(slideToken, objectUri, true);
470
471             // uri parameter can be point to a linkNode => retrieve its target
472
// objectnode
473
SubjectNode subjectNode = (SubjectNode) structure.retrieve(slideToken, userUri, true);
474
475             // Retrieve the Action Node
476
ActionNode actionNode = (ActionNode) structure.retrieve(slideToken, actionUri);
477
478             // Grant the permission
479
NodePermission perm = new NodePermission(objectNode, subjectNode,
480                                                       actionNode, inheritable,
481                                                       negative);
482             security.grantPermission(slideToken, perm);
483
484
485         }
486         catch ( Exception JavaDoc e)
487         {
488             throw new JetspeedCMSException("Impossible to grant the permission");
489         }
490     }
491
492     /**
493     * Create a new resource in the repository
494     * @param userNode User reference
495     * @param resource object describing the new resource
496     */

497     public void createResource (Resource resource)
498            throws JetspeedCMSException
499     {
500         try
501         {
502
503             String JavaDoc userNode = this.getSlideUserNode();
504             
505             // Get the SlideToken in function of a SubjectNode string
506
SlideToken slideToken = this.getSlideToken( userNode );
507
508             // Create the new resource ( Slide subjectNode )
509
SubjectNode subject = new SubjectNode();
510             structure.create(slideToken, subject, resource.getUri());
511
512             // ---- Create the new content revision descriptor
513
NodeRevisionDescriptor descriptor = (( SlideResource )resource).getDesciptor();
514             descriptor.setProperty(this.PROPERTY_CLASS_NAME,
515                                      resource.getClass().getName());
516
517             if (resource instanceof Catalog)
518             {
519                 // Get content length
520
descriptor.setProperty("getcontentlength", new Long JavaDoc(0));
521
522                 // Resource type (collection) - use xml element recognize by webdav client
523
descriptor.setProperty(new NodeProperty("resourcetype", "<collection/>", true));
524             }
525             else
526             {
527                 // Get content length
528
descriptor.setProperty("getcontentlength", new Long JavaDoc(0));
529
530                 // Last modification date
531
descriptor.setLastModified(new Date());
532
533                 // Etag generation
534
String JavaDoc etag = resource.getUri().hashCode() + "_"
535                                 //+ revisionNumber.hashCode() + "_"
536
+ descriptor.getContentLength();
537                 descriptor.setProperty(new NodeProperty("getetag", etag, true));
538
539                 descriptor.setProperty(new NodeProperty("getcontenttype", "", true));
540
541                 // Resource type (collection or other type of content)
542
descriptor.setProperty(new NodeProperty("resourcetype", "", true));
543
544                 // Source
545
descriptor.setProperty(new NodeProperty("source", "", true));
546
547                 // Content Language
548
//revisionDescriptor.setProperty("getcontentlanguage", stream., true);
549

550                 // Owner
551
//String owner = slideToken.getCredentialsToken().getPublicCredentials();
552
//descriptorescriptor.setProperty(new NodeProperty("owner", owner, true));
553

554                 // For Microsoft tools
555

556                 // Is hidden
557
NodeProperty property = new NodeProperty("ishidden", "0", "MICROSOFT");
558                 descriptor.setProperty(property);
559
560                 // Is collection
561
property = new NodeProperty("iscollection", "0", "MICROSOFT");
562                 descriptor.setProperty(property);
563
564                 // Is read only
565
property = new NodeProperty("isreadonly", "0", "MICROSOFT");
566                 descriptor.setProperty(property);
567
568                 // Last accessed
569
property = new NodeProperty("lastaccessed", (new Date()).toString(),
570                                             "MICROSOFT");
571                 descriptor.setProperty(property);
572             }
573
574             content.create(slideToken, resource.getUri(), descriptor, null);
575
576            // Grant permission if needed
577

578             Vector JavaDoc permissions = resource.getPermissions();
579
580             for (Enumeration e = permissions.elements(); e.hasMoreElements();)
581             {
582                 Permission p = (Permission) e.nextElement();
583                 this.grantPermission(resource.getUri(), p.getActor(),
584                                     p.getAction(), p.isInheritable(), p.isNegative());
585             }
586         }
587         catch (Exception JavaDoc e)
588         {
589             throw new JetspeedCMSException("Impossible to create the content resource");
590         }
591     }
592
593     /**
594     * Create a new resource in the repository with a content stream
595     * @param userNode User reference
596     * @param resource object describing the new resource
597     * @param stream stream which match to the resource content
598     */

599     public void createResource (Resource resource, FileItem stream)
600            throws JetspeedCMSException
601     {
602         try
603         {
604
605             String JavaDoc userNode = this.getSlideUserNode();
606             
607             // Get the SlideToken in function of a SubjectNode string
608
SlideToken slideToken = this.getSlideToken( userNode );
609
610             // Create the new resource ( Slide subjectNode )
611
SubjectNode subject = new SubjectNode();
612             structure.create(slideToken, subject, resource.getUri());
613
614             // Create the new content revision descriptor
615
NodeRevisionDescriptor descriptor = ((SlideResource) resource).getDesciptor();
616             descriptor.setProperty(this.PROPERTY_CLASS_NAME,
617                                    resource.getClass().getName());
618
619             // Get content length
620
descriptor.setProperty("getcontentlength", new Long JavaDoc(stream.getSize()));
621
622             // Last modification date
623
descriptor.setLastModified(new Date());
624
625             // Etag generation
626
String JavaDoc etag = resource.getUri().hashCode() + "_"
627                            //+ revisionNumber.hashCode() + "_"
628
+ descriptor.getContentLength();
629             descriptor.setProperty(new NodeProperty("getetag", etag, true));
630
631             String JavaDoc contentType = stream.getContentType();
632             descriptor.setProperty(new NodeProperty("getcontenttype", contentType, true));
633
634             // Resource type (collection or other type of content
635
descriptor.setProperty(new NodeProperty("resourcetype", "", true));
636
637             // Source
638
descriptor.setProperty(new NodeProperty("source", "", true));
639
640             // displayname : use in a webdav client
641
String JavaDoc displayName = stream.getFileName().substring( stream.getFileName().lastIndexOf("\\")+1 );
642
643             descriptor.setProperty(new NodeProperty("displayname",
644                                                     "<![CDATA[" + displayName+ "]]>"));
645
646             // Content Language
647
//revisionDescriptor.setProperty("getcontentlanguage", stream., true);
648

649             // Owner
650
//String owner = slideToken.getCredentialsToken().getPublicCredentials();
651
//descriptorescriptor.setProperty(new NodeProperty("owner", owner, true));
652

653             // For Microsoft tools
654

655             // Is hidden
656
NodeProperty property = new NodeProperty("ishidden", "0", "MICROSOFT");
657             descriptor.setProperty(property);
658
659             // Is collection
660
property = new NodeProperty("iscollection", "0", "MICROSOFT");
661             descriptor.setProperty(property);
662
663             // Is read only
664
property = new NodeProperty("isreadonly", "0", "MICROSOFT");
665             descriptor.setProperty(property);
666
667             // Last accessed
668
property = new NodeProperty("lastaccessed", (new Date()).toString(),
669                                         "MICROSOFT");
670             descriptor.setProperty(property);
671
672             // Add the content stream
673
NodeRevisionContent revisionContent = new NodeRevisionContent();
674             revisionContent.setContent(stream.getInputStream());
675
676             // Add all stuff in the slide repository
677
content.create(slideToken, resource.getUri(), descriptor, revisionContent);
678
679             // Grant permission if needed
680
Vector JavaDoc permissions = resource.getPermissions();
681
682             for (Enumeration e = permissions.elements(); e.hasMoreElements();)
683             {
684                 Permission p = (Permission) e.nextElement();
685                 this.grantPermission(resource.getUri(), p.getActor(),
686                                      p.getAction(), p.isInheritable(), p.isNegative());
687             }
688         }
689         catch (Exception JavaDoc e)
690         {
691             throw new JetspeedCMSException("Impossible to create the content resource");
692         }
693     }
694
695     /**
696     * Create a new link in the repository
697     * @param userNode User reference
698     * @param link object describing the new link
699     */

700     public void createLink (Link link)
701         throws JetspeedCMSException
702     {
703         try
704         {
705             String JavaDoc userNode = this.getSlideUserNode();
706             
707             // Get the SlideToken in function of a SubjectNode string
708
SlideToken slideToken = this.getSlideToken( userNode );
709
710             ObjectNode resourceNode = (ObjectNode) structure.retrieve(slideToken,
711                                             link.getTargetResourceUri() );
712             LinkNode linkNode = new LinkNode();
713             structure.createLink(slideToken, linkNode, link.getUri(), resourceNode);
714         }
715         catch (Exception JavaDoc e)
716         {
717             throw new JetspeedCMSException("Impossible to get the link");
718         }
719     }
720
721
722     // ------------------------------------------------------------------------------------------------
723
//
724
// PRIVATE METHODS
725
//
726
// ------------------------------------------------------------------------------------------------
727

728     /**
729     * Create a new SlideToken instance in function
730     * of a SubjectNode
731     *
732     * @param user reference
733     * @return a Slide toke object
734     */

735     private SlideToken getSlideToken (String JavaDoc userNode)
736     {
737         CredentialsToken credToken = new CredentialsToken(new String JavaDoc(userNode));
738
739         return new SlideTokenImpl(credToken);
740     }
741     
742     /**
743     * Populate the a catalog whith its childrens
744     *
745     *
746     * @param userNode user node reference
747     * @param children Collection which match to children uri
748     * @param catalog root catalog
749     * @param withSubCatalog if true, retrieve sub-catalog nodes
750     * @param withContent if false, retrieve only catalogs
751     * @param numberOfLevels number of level to retrieve
752     * (-1 : retrieve the complete graph from the root "catalog"
753     *
754     */

755
756     private void getChildren(String JavaDoc userNode, Enumeration children,
757                              Catalog catalog, boolean withSubCatalog,
758                              boolean withContent,int numberOfLevels)
759         throws JetspeedCMSException
760     {
761
762         if (Log.getLogger().isDebugEnabled())
763         {
764             Log.debug("Slide.getChildren for : " + catalog.getUri());
765         }
766
767         if (numberOfLevels != -1)
768         {
769             numberOfLevels--;
770         }
771
772         while (children.hasMoreElements())
773         {
774             String JavaDoc childUri = (String JavaDoc) children.nextElement();
775
776             if (Log.getLogger().isDebugEnabled())
777             {
778                 Log.debug("Slide.getChildren - Child found : " + childUri);
779             }
780
781            try
782            {
783                 Resource resource = this.getResource(childUri);
784
785                 if (resource instanceof Catalog)
786                 {
787                     if (withSubCatalog)
788                     {
789                         // numberOfLevels == -1 means all levels in the repository tree
790
if ((numberOfLevels == -1) || (numberOfLevels > 0))
791                         {
792                             int tmp = numberOfLevels;
793                             this.populateCatalog((Catalog) resource,
794                                                   withSubCatalog,
795                                                   withContent,
796                                                   numberOfLevels );
797                         }
798
799                         if (Log.getLogger().isDebugEnabled())
800                         {
801                             Log.debug("Slide.add Children : " + resource.getKey());
802                         }
803
804                         catalog.addResource( resource.getKey(), resource);
805                     }
806                 }
807                 else
808                 {
809                     if (withContent)
810                     {
811                         catalog.addResource(resource.getKey(), resource);
812                     }
813                 }
814             }
815             catch (JetspeedCMSException e)
816             {
817                 // if the exception is AccessDenied : continue the loop for other children
818
// else it is a more serious exception => throws the exception to the caller
819
if (!e.isAccessDenied())
820                 {
821                     throw new JetspeedCMSException("Impossible to get the children information ");
822                 }
823             }
824         }
825     }
826
827
828     /**
829     * Return the Slide User node depending of the current Jetspeed user session
830     *
831     * @return the slide user node
832     */

833     private String JavaDoc getSlideUserNode()
834     {
835         
836         JetspeedRunData data = ((JetspeedRunDataService) TurbineServices.getInstance()
837                                             .getService(RunDataService.SERVICE_NAME))
838                                             .getCurrentRunData();
839         return Utility.getUserUri(data.getUser().getUserName());
840     }
841 }
842
Popular Tags