KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > util > PropertyHelper


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyHelper.java,v 1.80.2.3 2004/12/02 15:46:32 ozeigermann Exp $
3  * $Revision: 1.80.2.3 $
4  * $Date: 2004/12/02 15:46:32 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.webdav.util;
25 import java.io.IOException JavaDoc;
26 import java.io.StringReader JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.Date JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Set JavaDoc;
36
37 import org.apache.commons.codec.digest.DigestUtils;
38 import org.apache.slide.authenticate.CredentialsToken;
39 import org.apache.slide.common.Domain;
40 import org.apache.slide.common.NamespaceAccessToken;
41 import org.apache.slide.common.NamespaceConfig;
42 import org.apache.slide.common.ServiceAccessException;
43 import org.apache.slide.common.SlideException;
44 import org.apache.slide.common.SlideToken;
45 import org.apache.slide.common.Uri;
46 import org.apache.slide.common.UriPath;
47 import org.apache.slide.content.Content;
48 import org.apache.slide.content.NodeProperty;
49 import org.apache.slide.content.NodeRevisionDescriptor;
50 import org.apache.slide.content.NodeRevisionDescriptors;
51 import org.apache.slide.content.NodeRevisionNumber;
52 import org.apache.slide.content.RevisionDescriptorNotFoundException;
53 import org.apache.slide.content.NodeProperty.NamespaceCache;
54 import org.apache.slide.event.VetoException;
55 import org.apache.slide.lock.Lock;
56 import org.apache.slide.lock.LockTokenNotFoundException;
57 import org.apache.slide.lock.NodeLock;
58 import org.apache.slide.lock.ObjectLockedException;
59 import org.apache.slide.search.RequestedResource;
60 import org.apache.slide.search.Search;
61 import org.apache.slide.search.SearchQuery;
62 import org.apache.slide.search.SearchQueryResult;
63 import org.apache.slide.security.ACLSecurityImpl;
64 import org.apache.slide.security.AccessDeniedException;
65 import org.apache.slide.security.NodePermission;
66 import org.apache.slide.security.Security;
67 import org.apache.slide.security.SecurityImpl;
68 import org.apache.slide.structure.ActionNode;
69 import org.apache.slide.structure.LinkedObjectNotFoundException;
70 import org.apache.slide.structure.ObjectNode;
71 import org.apache.slide.structure.ObjectNotFoundException;
72 import org.apache.slide.structure.Structure;
73 import org.apache.slide.structure.SubjectNode;
74 import org.apache.slide.util.Configuration;
75 import org.apache.slide.util.XMLValue;
76 import org.apache.slide.webdav.WebdavServletConfig;
77 import org.apache.slide.webdav.method.LockMethod;
78 import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
79 import org.apache.slide.webdav.util.resourcekind.Activity;
80 import org.apache.slide.webdav.util.resourcekind.CheckedInVersionControlled;
81 import org.apache.slide.webdav.util.resourcekind.CheckedOutVersionControlled;
82 import org.apache.slide.webdav.util.resourcekind.DeltavCompliantCollection;
83 import org.apache.slide.webdav.util.resourcekind.ResourceKind;
84 import org.apache.slide.webdav.util.resourcekind.Version;
85 import org.apache.slide.webdav.util.resourcekind.VersionHistory;
86 import org.apache.slide.webdav.util.resourcekind.Workspace;
87 import org.jdom.Attribute;
88 import org.jdom.CDATA;
89 import org.jdom.Document;
90 import org.jdom.Element;
91 import org.jdom.JDOMException;
92 import org.jdom.Namespace;
93 import org.jdom.Text;
94 import org.jdom.input.SAXBuilder;
95
96
97
98 /**
99  * Helper class for handling WebDAV properties.
100  *
101  */

102
103 public class PropertyHelper extends AbstractWebdavHelper implements WebdavConstants, DeltavConstants, AclConstants, DaslConstants, BindConstants {
104     
105     public final static String JavaDoc LOCKDISCOVERY_INCL_PRINCIPAL =
106         "lockdiscoveryIncludesPrincipalURL";
107     
108     public final static String JavaDoc PRIVILEGE_NAMESPACE = "privilege-namespace";
109     
110     private boolean lockdiscoveryIncludesPrincipalURL = true;
111     
112     /**
113      * The Element returned by {@link #getCheckoutSetQueryElement
114      * getCheckoutSetQueryElement()}.
115      */

116     protected Element checkoutSetQueryElement = null;
117     
118     /**
119      * The <literal> Element used in the basic search query returned by
120      * {@link #getCheckoutSetQueryElement getCheckoutSetQueryElement()}.
121      */

122     protected Element checkoutSetQueryLiteralElement = null;
123     
124     /**
125      * The Element returned by {@link #getWorkspaceCheckoutSetQueryElement
126      * getWorkspaceCheckoutSetQueryElement()}.
127      */

128     protected Element workspaceCheckoutSetQueryElement = null;
129     
130     /**
131      * The <href> Element used in the basic search query returned by
132      * {@link #getWorkspaceCheckoutSetQueryElement getWorkspaceCheckoutSetQueryElement()}.
133      */

134     protected Element workspaceCheckoutSetQueryHrefElement = null;
135     
136     private WebdavServletConfig sConf = null;
137     
138     
139     
140     /**
141      * Factory method.
142      * @deprecated
143      */

144 // public static PropertyHelper
145
// getPropertyHelper( SlideToken sToken, NamespaceAccessToken nsaToken) {
146
// return new PropertyHelper( sToken, nsaToken, null );
147
// }
148

149     /**
150      * Factory method.
151      */

152     public static PropertyHelper
153         getPropertyHelper( SlideToken sToken, NamespaceAccessToken nsaToken, WebdavServletConfig sConf ) {
154         return new PropertyHelper( sToken, nsaToken, sConf );
155     }
156     
157     
158     /**
159      * Protected contructor
160      */

161     protected PropertyHelper( SlideToken sToken, NamespaceAccessToken nsaToken, WebdavServletConfig sConf ) {
162         super( sToken, nsaToken );
163         this.sConf = sConf;
164         if( sConf != null )
165             lockdiscoveryIncludesPrincipalURL =
166                 !("false".equalsIgnoreCase(sConf.getInitParameter(LOCKDISCOVERY_INCL_PRINCIPAL)));
167     }
168     
169     /**
170      * Create initial default properties to be stored for the specified
171      * resource kind.
172      * The result set does not contain transient properties.
173      * @post result != null
174      * @return a list of initial non-transient properties (empty list if none)
175      */

176     public List JavaDoc createInitialProperties( ResourceKind resourceKind, String JavaDoc resourcePath ) {
177         
178         Set JavaDoc sp = resourceKind.getSupportedLiveProperties();
179         List JavaDoc result = null;
180         
181         if( sp == null )
182             result = Collections.EMPTY_LIST;
183         else {
184             result = new ArrayList JavaDoc();
185             Iterator JavaDoc i = sp.iterator();
186             while( i.hasNext() ) {
187                 String JavaDoc propName = (String JavaDoc)i.next();
188                 if( AbstractResourceKind.isComputedProperty(propName) )
189                     continue;
190                 Object JavaDoc pvalue = createDefaultValue( propName, resourceKind, resourcePath );
191                 if (pvalue != null) {
192                     result.add( new NodeProperty(propName, pvalue) );
193                 }
194             }
195         }
196         return result;
197     }
198     
199     /**
200      * Create a default value for the specified property name and resource
201      * kind
202      */

203     Object JavaDoc createDefaultValue( String JavaDoc propName, ResourceKind resourceKind, String JavaDoc resourcePath ) {
204         
205         String JavaDoc autoVersion =
206             Domain.getParameter(I_AUTO_VERSION,
207                                 I_AUTO_VERSION_DEFAULT,
208                                 nsaToken.getUri(sToken, resourcePath).getStore());
209         
210         String JavaDoc checkoutFork =
211             Domain.getParameter(I_CHECKOUT_FORK,
212                                 I_CHECKOUT_FORK_DEFAULT,
213                                 nsaToken.getUri(sToken, resourcePath).getStore());
214         
215         String JavaDoc checkinFork =
216             Domain.getParameter(I_CHECKIN_FORK,
217                                 I_CHECKIN_FORK_DEFAULT,
218                                 nsaToken.getUri(sToken, resourcePath).getStore());
219         
220         String JavaDoc result = null;
221         
222         if( P_RESOURCETYPE.equals(propName) ) {
223             StringBuffer JavaDoc rtvv = new StringBuffer JavaDoc();
224             try {
225                 if( resourceKind instanceof VersionHistory ) {
226                     rtvv.append(
227                         xmlOut.outputString(new Element(E_VERSION_HISTORY, DNSP)) );
228                     rtvv.append(
229                         xmlOut.outputString(new Element(E_COLLECTION, DNSP)) );
230                 }
231                 if( resourceKind instanceof DeltavCompliantCollection ) {
232                     rtvv.append(
233                         xmlOut.outputString(new Element(E_COLLECTION, DNSP)) );
234                 }
235                 if( resourceKind instanceof Activity ) {
236                     rtvv.append(
237                         xmlOut.outputString(new Element(E_ACTIVITY, DNSP)) );
238                 }
239             }
240             catch( Exception JavaDoc x ) {
241                 x.printStackTrace();
242             }
243             result = rtvv.toString();
244         }
245         else if( P_SUPPORTED_METHOD_SET.equals(propName) ) {
246             Iterator JavaDoc i = resourceKind.getSupportedMethods().iterator();
247             StringBuffer JavaDoc smsv = new StringBuffer JavaDoc();
248             while( i.hasNext() ) {
249                 String JavaDoc m = (String JavaDoc) i.next();
250                 Element sm = new Element( E_SUPPORTED_METHOD, DNSP );
251                 Attribute na = new Attribute( A_NAME, m, DNSP );
252                 sm.setAttribute( na );
253                 try {
254                     smsv.append( xmlOut.outputString(sm) );
255                 }
256                 catch( Exception JavaDoc x ) { x.printStackTrace(); }
257             }
258             result = smsv.toString();
259         }
260         else if( P_SUPPORTED_LIVE_PROPERTY_SET.equals(propName) ) {
261             Iterator JavaDoc i = resourceKind.getSupportedLiveProperties().iterator();
262             StringBuffer JavaDoc spsv = new StringBuffer JavaDoc();
263             while( i.hasNext() ) {
264                 String JavaDoc p = (String JavaDoc) i.next();
265                 Element sp = new Element( E_SUPPORTED_LIVE_PROPERTY, DNSP );
266                 Element na = new Element( E_NAME, DNSP );
267                 na.addContent( p );
268                 sp.addContent( na );
269                 try {
270                     spsv.append( xmlOut.outputString(sp) );
271                 }
272                 catch( Exception JavaDoc x ) { x.printStackTrace(); }
273             }
274             result = spsv.toString();
275         }
276         else if( P_SUPPORTED_REPORT_SET.equals(propName) ) {
277             Iterator JavaDoc i = resourceKind.getSupportedReports().iterator();
278             StringBuffer JavaDoc srsv = new StringBuffer JavaDoc();
279             while( i.hasNext() ) {
280                 String JavaDoc r = (String JavaDoc) i.next();
281                 Element sr = new Element( E_SUPPORTED_REPORT, DNSP );
282                 Element na = new Element( E_NAME, DNSP );
283                 na.addContent( r );
284                 sr.addContent( na );
285                 try {
286                     srsv.append( xmlOut.outputString(sr) );
287                 }
288                 catch( Exception JavaDoc x ) { x.printStackTrace(); }
289             }
290             result = srsv.toString();
291         }
292         else if( P_AUTO_VERSION.equals(propName) ) {
293             
294             XMLValue xmlValue = new XMLValue();
295             
296             if (autoVersion.length() > 0) {
297                 xmlValue.add(new Element(autoVersion, DNSP));
298             }
299             
300             if( ! resourceKind.isSupportedPropertyValue(P_AUTO_VERSION, xmlValue) ) {
301                 Domain.warn( "Auto-version not configured properly; using "
302                                 +E_CHECKOUT_CHECKIN );
303                 xmlValue = new XMLValue(new Element(E_CHECKOUT_CHECKIN, DNSP));
304             }
305             
306             result = xmlValue.toString();
307         }
308         else if( P_CHECKOUT_FORK.equals(propName) ) {
309             
310             XMLValue xmlValue = new XMLValue();
311             
312             if (checkoutFork.length() > 0) {
313                 xmlValue.add(new Element(checkoutFork, DNSP));
314             }
315             
316             if( ! resourceKind.isSupportedPropertyValue(P_CHECKOUT_FORK, xmlValue) ) {
317                 Domain.warn( "Checkout-fork not configured properly; using "
318                                 +E_FORBIDDEN );
319                 xmlValue = new XMLValue(new Element(E_FORBIDDEN, DNSP));
320             }
321             
322             result = xmlValue.toString();
323         }
324         else if( P_CHECKIN_FORK.equals(propName) ) {
325             
326             XMLValue xmlValue = new XMLValue();
327             
328             if (checkinFork.length() > 0) {
329                 xmlValue.add(new Element(checkinFork, DNSP));
330             }
331             
332             if( ! resourceKind.isSupportedPropertyValue(P_CHECKIN_FORK, xmlValue) ) {
333                 Domain.warn( "Checkin-fork not configured properly; using "
334                                 +E_FORBIDDEN );
335                 xmlValue = new XMLValue(new Element(E_FORBIDDEN, DNSP));
336             }
337             
338             result = xmlValue.toString();
339         }
340         else if( P_GETCONTENTLANGUAGE.equals(propName) ) {
341             result = "en";
342         }
343         else if( P_CREATOR_DISPLAYNAME.equals(propName) ) {
344             if( sToken != null ) {
345                 CredentialsToken credToken = sToken.getCredentialsToken();
346                 if( credToken != null ) {
347                     result = credToken.getPublicCredentials();
348                     if (result == null || result.equals("") || result.equals("/")) {
349                         result = SubjectNode.UNAUTHENTICATED_URI;
350                     }
351                 }
352             }
353         }
354         // REQUIRED properties
355
else if( P_PREDECESSOR_SET.equals(propName) ) {
356             result = "";
357         }
358         else if( P_CHECKOUT_SET.equals(propName) ) {
359             result = "";
360         }
361         else if( P_COMMENT.equals(propName) ) {
362             result = "";
363         }
364         else if( P_LABEL_NAME_SET.equals(propName) ) {
365             result = "";
366         }
367         return result;
368     }
369     
370     /**
371      * Create CDATA value.
372      */

373     public Object JavaDoc createCdataValue( String JavaDoc text ) {
374         StringBuffer JavaDoc b = new StringBuffer JavaDoc();
375         if( text == null )
376             text = "";
377         b.append( "![CDATA[" ).append( text ).append( "]]" );
378         return b.toString();
379     }
380     
381     /**
382      * Create href value.
383      */

384     public Object JavaDoc createHrefValue( String JavaDoc uri ) {
385         String JavaDoc result = "";
386         
387         Element href = new Element( E_HREF, DNSP );
388         href.addContent( uri );
389         try {
390             result = xmlOut.outputString( href );
391         }
392         catch( Exception JavaDoc x ) {
393             x.printStackTrace();
394         }
395         
396         return result;
397     }
398     
399     /**
400      * Create href set value.
401      */

402     public Object JavaDoc createHrefSetValue( List JavaDoc uriList ) {
403         StringBuffer JavaDoc b = new StringBuffer JavaDoc();
404         Iterator JavaDoc i = uriList.iterator();
405         while( i.hasNext() )
406             b.append( createHrefValue((String JavaDoc)i.next()) );
407         return b.toString();
408     }
409     
410     /**
411      * Create href set value.
412      */

413     public Object JavaDoc createHrefSetValue( String JavaDoc rootElement, List JavaDoc uriList ) {
414         String JavaDoc result = "";
415         
416         Element root = new Element( rootElement, DNSP );
417         Iterator JavaDoc i = uriList.iterator();
418         
419         while( i.hasNext() ) {
420             Element href = new Element( E_HREF, DNSP );
421             href.addContent( (String JavaDoc)i.next() );
422             root.addContent( href );
423         }
424         try {
425             result = xmlOut.outputString( root );
426         }
427         catch( Exception JavaDoc x ) {
428             x.printStackTrace();
429         }
430         
431         return result;
432     }
433     
434     /**
435      * Parse an XML-Valued property value.
436      */

437     public Element parsePropertyValue( String JavaDoc propValue ) throws JDOMException, IOException JavaDoc {
438         Document d = xmlBuilder.build( new StringReader JavaDoc(propValue) );
439         return d.getRootElement();
440     }
441     
442     /**
443      * Returns the property of the resource described by
444      * the resourcePath.
445      *
446      * @param propertyName the name of the property.
447      * @param resourcePath the path that identifies the resource.
448      *
449      * @return the property.
450      *
451      * @throws SlideException
452      * @throws JDOMException
453      * @deprecated use {@link #getProperty(String, String, String)}
454      */

455     public NodeProperty getProperty(String JavaDoc propertyName, String JavaDoc resourcePath) throws SlideException, JDOMException {
456         return getProperty(propertyName, resourcePath, null);
457     }
458     
459     /**
460      * Returns the property of the resource described by
461      * the resourcePath.
462      *
463      * @param propertyName the name of the property.
464      * @param resourcePath the path that identifies the resource.
465      * @param contextPath a String , the result of HttpRequest.getContextPath()
466      * @param servletPath a String, the result of HttpRequest.getServletPath()
467      *
468      * @return the property.
469      *
470      * @throws SlideException
471      * @throws JDOMException
472      */

473     public NodeProperty getProperty(String JavaDoc propertyName, String JavaDoc resourcePath, String JavaDoc slideContextPath) throws SlideException, JDOMException {
474         
475         UriHandler uriHandler = UriHandler.getUriHandler(resourcePath);
476         String JavaDoc uri = null;
477         NodeRevisionDescriptors revisionDescriptors = null;
478         NodeRevisionDescriptor revisionDescriptor = null;
479         Content contentHelper = nsaToken.getContentHelper();
480         
481         if (uriHandler.isVersionUri()) {
482             uri = uriHandler.getAssociatedHistoryUri();
483             NodeRevisionNumber revisionNumber = new NodeRevisionNumber(uriHandler.getVersionName());
484             revisionDescriptors = contentHelper.retrieve(sToken, uri);
485             revisionDescriptor = contentHelper.retrieve(sToken, revisionDescriptors, revisionNumber);
486         }
487         else if (uriHandler.isHistoryUri()) {
488             uri = uriHandler.getAssociatedHistoryUri();
489             NodeRevisionNumber revisionNumber = new NodeRevisionNumber("0.0");
490             revisionDescriptors = contentHelper.retrieve(sToken, uri);
491             revisionDescriptor = contentHelper.retrieve(sToken, revisionDescriptors, revisionNumber);
492         }
493         else {
494             uri = resourcePath;
495             revisionDescriptors = contentHelper.retrieve(sToken, uri);
496             revisionDescriptor = contentHelper.retrieve(sToken, revisionDescriptors);
497         }
498         return getProperty(propertyName, revisionDescriptors, revisionDescriptor, slideContextPath);
499     }
500     
501     /**
502      * Returns the property of the resource described by
503      * the resourcePath.
504      *
505      * @param propertyName the name of the property.
506      * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
507      * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
508      *
509      * @return the property.
510      *
511      * @throws SlideException
512      * @throws JDOMException
513      * @deprecated use {@link #getProperty(String, NodeRevisionDescriptors, NodeRevisionDescriptor, String)}
514      */

515     public NodeProperty getProperty(String JavaDoc propertyName, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) throws SlideException, JDOMException {
516         return getProperty(propertyName, revisionDescriptors, revisionDescriptor, null);
517     }
518     
519     /**
520      * Returns the property of the resource described by
521      * the resourcePath.
522      *
523      * @param propertyName the name of the property.
524      * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
525      * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
526      * @param contextPath a String , the result of HttpRequest.getContextPath()
527      * @param servletPath a String, the result of HttpRequest.getServletPath()
528      *
529      * @return the property.
530      *
531      * @throws SlideException
532      * @throws JDOMException
533      */

534     public NodeProperty getProperty(String JavaDoc propertyName, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws SlideException, JDOMException {
535         
536         NodeProperty property = revisionDescriptor.getProperty( propertyName );
537         ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor);
538         if (resourceKind.isSupportedLiveProperty(propertyName)) {
539             if (AbstractResourceKind.isComputedProperty(propertyName)) {
540                 property = computeProperty(propertyName, revisionDescriptors, revisionDescriptor, slideContextPath);
541             }
542         }
543         
544         return property;
545     }
546     
547     /**
548      * Returns the computed property of the resource.
549      *
550      * @param propertyName the name of the property.
551      * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
552      * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
553      * @param contextPath a String , the result of HttpRequest.getContextPath()
554      * @param servletPath a String, the result of HttpRequest.getServletPath()
555      *
556      * @return the property.
557      *
558      * @throws SlideException
559      * @throws JDOMException
560      */

561     public NodeProperty computeProperty(String JavaDoc propertyName, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws SlideException, JDOMException {
562         
563         NodeProperty property = null;
564         if (P_SUCCESSOR_SET.equals(propertyName)) {
565             property = new NodeProperty(propertyName, computeSuccessorSet(revisionDescriptors, revisionDescriptor, slideContextPath));
566         }
567         else if (P_VERSION_HISTORY.equals(propertyName)) {
568             property = new NodeProperty(propertyName, computeVersionHistory(revisionDescriptors, revisionDescriptor, slideContextPath));
569         }
570         else if (P_ROOT_VERSION.equals(propertyName)) {
571             property = new NodeProperty(propertyName, computeRootVersion(revisionDescriptors, revisionDescriptor, slideContextPath));
572         }
573         else if (P_SUPPORTED_METHOD_SET.equals(propertyName)) {
574             property = new NodeProperty(propertyName, computeSupportedMethodSet(revisionDescriptors, revisionDescriptor, slideContextPath));
575         }
576         else if (P_SUPPORTED_LIVE_PROPERTY_SET.equals(propertyName)) {
577             property = new NodeProperty(propertyName, computeSupportedLivePropertySet(revisionDescriptors, revisionDescriptor, slideContextPath));
578         }
579         else if (P_SUPPORTED_REPORT_SET.equals(propertyName)) {
580             property = new NodeProperty(propertyName, computeSupportedReportSet(revisionDescriptors, revisionDescriptor, slideContextPath));
581         }
582         else if (P_CHECKOUT_SET.equals(propertyName)) {
583             property = new NodeProperty(propertyName, computeCheckoutSet(revisionDescriptors, revisionDescriptor, slideContextPath));
584         }
585         else if (P_WORKSPACE_CHECKOUT_SET.equals(propertyName)) {
586             property = new NodeProperty(propertyName, computeWorkspaceCheckoutSet(revisionDescriptors, revisionDescriptor, slideContextPath));
587         }
588         else if (P_WORKSPACE.equals(propertyName)) {
589             XMLValue ws = null;
590             if (Configuration.useBinding(nsaToken.getUri(sToken, revisionDescriptors.getUri()).getStore())) {
591                 ws = computeWorkspace(revisionDescriptors, revisionDescriptor, slideContextPath);
592             }
593             else {
594                 ws = computeWorkspaceNoBinding(revisionDescriptors, revisionDescriptor, slideContextPath);
595             }
596             if (ws != null) {
597                 property = new NodeProperty(propertyName, ws);
598             }
599         }
600             
601         else if (P_LOCKDISCOVERY.equals(propertyName)) {
602             property = new NodeProperty(propertyName, computeLockDiscovery(revisionDescriptors, revisionDescriptor, slideContextPath));
603         }
604         else if (P_SUPPORTEDLOCK.equals(propertyName)) {
605             property = new NodeProperty(propertyName, computeSupportedlock(revisionDescriptors, revisionDescriptor, slideContextPath));
606         }
607         else if (P_SUPPORTED_PRIVILEGE_SET.equals(propertyName)) {
608             property = new NodeProperty(propertyName, computeSupportedPrivilegeSet(revisionDescriptors, revisionDescriptor, slideContextPath));
609         }
610         else if (P_CURRENT_USER_PRIVILEGE_SET.equals(propertyName)) {
611             property = new NodeProperty(propertyName, computeCurrentuserPrivilegeSet(revisionDescriptors, revisionDescriptor, slideContextPath));
612         }
613         else if (P_ACL.equals(propertyName)) {
614             property = new NodeProperty(propertyName, computeAcl(revisionDescriptors, revisionDescriptor, slideContextPath));
615         }
616         else if (P_PRINCIPAL_COLLECTION_SET.equals(propertyName)) {
617             property = new NodeProperty(propertyName, computePrincipalCollectionSet(revisionDescriptors, revisionDescriptor, slideContextPath));
618         }
619         else if (P_PRIVILEGE_COLLECTION_SET.equals(propertyName)) {
620             property = new NodeProperty(propertyName, computePrivilegeCollectionSet(revisionDescriptors, revisionDescriptor, slideContextPath));
621         }
622         else if (P_OWNER.equals(propertyName)) {
623             property = new NodeProperty(propertyName, computeOwner(revisionDescriptors, revisionDescriptor, slideContextPath));
624         }
625         else if (P_CREATIONUSER.equals(propertyName)) {
626             property = new NodeProperty(propertyName, computeCreationUser(revisionDescriptors, revisionDescriptor, slideContextPath));
627         }
628         else if (P_MODIFICATIONUSER.equals(propertyName)) {
629             property = new NodeProperty(propertyName, computeModificationUser(revisionDescriptors, revisionDescriptor, slideContextPath));
630         }
631         else if (P_INHERITED_ACL_SET.equals(propertyName)) {
632             property = new NodeProperty(propertyName, computeInheritedAclSet(revisionDescriptors, revisionDescriptor, slideContextPath));
633         }
634         else if (P_ACL_RESTRICTIONS.equals(propertyName)) {
635             property = new NodeProperty(propertyName, computeAclRestrictions(revisionDescriptors, revisionDescriptor, slideContextPath));
636         }
637         else if (P_GROUP_MEMBERSHIP.equals(propertyName)) {
638             property = new NodeProperty(propertyName, computeGroupMembership(revisionDescriptors, revisionDescriptor, slideContextPath));
639         }
640         
641         return property;
642     }
643     
644     /**
645      * Returns an XMLValue containing the <code>&lt;href&gt;</code> elements
646      * describing the successors of the resource.
647      *
648      * The concatenation of <code>contextPath</code>,<code>servletPath</code> and
649      * <code>revisionDescriptor.getUri()</code> gives the absolute URL of the resource
650      * on this server.
651      *
652      * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
653      * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
654      * @param servletPath a String, the result of HttpRequest.getServletPath()
655      * @param contextPath a String , the result of HttpRequest.getContextPath()
656      *
657      * @return the successor list.
658      *
659      * @throws ObjectLockedException
660      * @throws RevisionDescriptorNotFoundException
661      * @throws ServiceAccessException
662      * @throws LinkedObjectNotFoundException
663      * @throws AccessDeniedException
664      * @throws ObjectNotFoundException
665      */

666     public XMLValue computeSuccessorSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
667         
668         XMLValue xmlValue = new XMLValue();
669         Element hrefElement = new Element(E_HREF, DNSP);
670         //NodeRevisionDescriptor successorRevisionDescriptor = null;
671
NodeRevisionNumber successorRevisionNumber = null;
672         Enumeration JavaDoc successorEnum = revisionDescriptors.getSuccessors(revisionDescriptor.getRevisionNumber());
673         
674         if (successorEnum != null) {
675             while (successorEnum.hasMoreElements()) {
676                 successorRevisionNumber = (NodeRevisionNumber)successorEnum.nextElement();
677                 hrefElement = (Element)hrefElement.clone();
678                 StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(revisionDescriptors.getUri());
679                 if ( ! revisionDescriptors.getUri().endsWith("/") ) {
680                     buffer.append("/");
681                 }
682                 buffer.append(successorRevisionNumber.toString());
683                 
684                 hrefElement.setText(WebdavUtils.getAbsolutePath (
685                                         buffer.toString(),
686                                         slideContextPath, sConf));
687                 
688                 xmlValue.add(hrefElement);
689             }
690         }
691         return xmlValue;
692     }
693     
694     /**
695      * Returns an XMLValue containing the <code>&lt;href&gt;</code> element
696      * with the history URI of the resource. If the resource is neither a
697      * VR, checked-in VCR or checked-out VCR, the returned XMLValue is empty.
698      *
699      * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
700      * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
701      * @param contextPath a String , the result of HttpRequest.getContextPath()
702      * @param servletPath a String, the result of HttpRequest.getServletPath()
703      *
704      * @return the version history <code>&lt;href&gt;</code>.
705      *
706      * @throws ObjectLockedException
707      * @throws RevisionDescriptorNotFoundException
708      * @throws ServiceAccessException
709      * @throws LinkedObjectNotFoundException
710      * @throws AccessDeniedException
711      * @throws ObjectNotFoundException
712      * @throws JDOMException
713      */

714     public XMLValue computeVersionHistory(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, JDOMException {
715         
716         XMLValue xmlValue = new XMLValue();
717         ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor);
718         if (resourceKind instanceof Version) {
719             Element element = new Element(E_HREF, DNSP);
720             
721             element.setText(WebdavUtils.getAbsolutePath (
722                                 revisionDescriptors.getUri(), slideContextPath,
723                                 sConf));
724             
725             xmlValue.add(element);
726         }
727         else if (resourceKind instanceof CheckedInVersionControlled) {
728             Element element = new Element(E_HREF, DNSP);
729             String JavaDoc checkedInHref = revisionDescriptor.getProperty(P_CHECKED_IN).getValue().toString();
730             String JavaDoc checkedInUri = ((Element)new XMLValue(checkedInHref).iterator().next()).getText();
731             UriHandler uriHandler = UriHandler.getUriHandler(checkedInUri);
732             
733             element.setText (WebdavUtils.getAbsolutePath (
734                                  uriHandler.getAssociatedHistoryUri(),
735                                  slideContextPath, sConf));
736             
737             xmlValue.add(element);
738         }
739         else if (resourceKind instanceof CheckedOutVersionControlled) {
740             Element element = new Element(E_HREF, DNSP);
741             String JavaDoc checkedOutHref = revisionDescriptor.getProperty(P_CHECKED_OUT).getValue().toString();
742             String JavaDoc checkedOutUri = ((Element)new XMLValue(checkedOutHref).iterator().next()).getText();
743             UriHandler uriHandler = UriHandler.getUriHandler(checkedOutUri);
744             
745             element.setText(WebdavUtils.getAbsolutePath (
746                                 uriHandler.getAssociatedHistoryUri(),
747                                 slideContextPath, sConf));
748             
749             xmlValue.add(element);
750         }
751         
752         return xmlValue;
753     }
754     
755     /**
756      * Returns an XMLValue containing the <code>&lt;href&gt;</code> element
757      * with the URI of the root version of the history.
758      * If the resource is not a history, the returned XMLValue is empty.
759      *
760      * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
761      * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
762      * @param servletPath a String, the result of HttpRequest.getServletPath()
763      * @param contextPath a String , the result of HttpRequest.getContextPath()
764      *
765      * @return the root version URI.
766      *
767      * @throws ObjectLockedException
768      * @throws RevisionDescriptorNotFoundException
769      * @throws ServiceAccessException
770      * @throws LinkedObjectNotFoundException
771      * @throws AccessDeniedException
772      * @throws ObjectNotFoundException
773      */

774     public XMLValue computeRootVersion(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
775         
776         XMLValue xmlValue = new XMLValue();
777         
778         ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor);
779         if (resourceKind instanceof VersionHistory) {
780             Element element = new Element(E_HREF, DNSP);
781             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(revisionDescriptors.getUri());
782             if ( ! revisionDescriptors.getUri().endsWith("/") ) {
783                 buffer.append("/");
784             }
785             buffer.append(revisionDescriptors.getInitialRevision().toString());
786             
787             element.setText(WebdavUtils.getAbsolutePath (
788                                 buffer.toString(),
789                                 slideContextPath, sConf));
790             
791             xmlValue.add(element);
792         }
793         
794         return xmlValue;
795     }
796     
797     /**
798      * Returns an XMLValue containing the <code>&lt;supported-method&gt;</code>
799      * elements with the name (attribute) of the supported methods.
800      * <br></br>
801      * <i>Note:</i>
802      * <br></br>
803      * <i>
804      * Due to the specification this is <b>not</b> a computed property, but because
805      * of implementation problems it is not stored.
806      * </i>
807      *
808      * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
809      * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
810      * @param servletPath a String, the result of HttpRequest.getServletPath()
811      * @param contextPath a String , the result of HttpRequest.getContextPath()
812      *
813      * @return the supported methods.
814      *
815      * @throws ObjectLockedException
816      * @throws RevisionDescriptorNotFoundException
817      * @throws ServiceAccessException
818      * @throws LinkedObjectNotFoundException
819      * @throws AccessDeniedException
820      * @throws ObjectNotFoundException
821      */

822     public XMLValue computeSupportedMethodSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
823         
824         XMLValue xmlValue = new XMLValue();
825         
826         ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor);
827         Set JavaDoc supportedMethodNames = resourceKind.getSupportedMethods();
828         Iterator JavaDoc iterator = supportedMethodNames.iterator();
829         Element supportedMethod = null;
830         while (iterator.hasNext()) {
831             supportedMethod = new Element(E_SUPPORTED_METHOD, DNSP);
832             supportedMethod.setAttribute(new Attribute(E_NAME, (String JavaDoc)iterator.next()));
833             xmlValue.add(supportedMethod);
834         }
835         
836         return xmlValue;
837     }
838     
839     /**
840      * Returns an XMLValue containing the <code>&lt;supported-live-property&gt;</code>
841      * elements containing <code>&lt;prop&gt;</code> which are containing
842      * elements with the name of the property.
843      * <br></br>
844      * <i>Note:</i>
845      * <br></br>
846      * <i>
847      * Due to the specification this is <b>not</b> a computed property, but because
848      * of implementation problems it is not stored.
849      * </i>
850      *
851      * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
852      * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
853      * @param contextPath a String , the result of HttpRequest.getContextPath()
854      * @param servletPath a String, the result of HttpRequest.getServletPath()
855      *
856      * @return the supported live properties.
857      *
858      * @throws ObjectLockedException
859      * @throws RevisionDescriptorNotFoundException
860      * @throws ServiceAccessException
861      * @throws LinkedObjectNotFoundException
862      * @throws AccessDeniedException
863      * @throws ObjectNotFoundException
864      */

865     public XMLValue computeSupportedLivePropertySet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
866         
867         XMLValue xmlValue = new XMLValue();
868         
869         ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor);
870         Set JavaDoc supportedLivePropertyNames = resourceKind.getSupportedLiveProperties();
871         Iterator JavaDoc iterator = supportedLivePropertyNames.iterator();
872         Element supportedLivePropertyElement = null;
873         Element propElement = null;
874         Element propertyElement = null;
875         while (iterator.hasNext()) {
876             
877             supportedLivePropertyElement = new Element(E_SUPPORTED_LIVE_PROPERTY, DNSP);
878             propElement = new Element(E_PROP, DNSP);
879             supportedLivePropertyElement.addContent(propElement);
880             propertyElement = new Element((String JavaDoc)iterator.next(), DNSP);
881             propElement.addContent(propertyElement);
882             xmlValue.add(supportedLivePropertyElement);
883         }
884         
885         return xmlValue;
886     }
887     
888     /**
889      * Returns an XMLValue containing the <code>&lt;supported-report&gt;</code>
890      * elements containing <code>&lt;report&gt;</code> which are containing
891      * elements with the name of the report.
892      * <br></br>
893      * <i>Note:</i>
894      * <br></br>
895      * <i>
896      * Due to the specification this is <b>not</b> a computed property, but because
897      * of implementation problems it is not stored.
898      * </i>
899      *
900      * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
901      * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
902      * @param contextPath a String , the result of HttpRequest.getContextPath()
903      * @param servletPath a String, the result of HttpRequest.getServletPath()
904      *
905      * @return the supported reports.
906      *
907      * @throws ObjectLockedException
908      * @throws RevisionDescriptorNotFoundException
909      * @throws ServiceAccessException
910      * @throws LinkedObjectNotFoundException
911      * @throws AccessDeniedException
912      * @throws ObjectNotFoundException
913      */

914     public XMLValue computeSupportedReportSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException {
915         
916         XMLValue xmlValue = new XMLValue();
917         
918         ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor);
919         Set JavaDoc supportedReportNames = resourceKind.getSupportedReports();
920         Iterator JavaDoc iterator = supportedReportNames.iterator();
921         Element supportedReportElement = null;
922         Element reportElement = null;
923         Element propertyElement = null;
924         while (iterator.hasNext()) {
925             
926             supportedReportElement = new Element(E_SUPPORTED_REPORT, DNSP);
927             reportElement = new Element(E_REPORT, DNSP);
928             supportedReportElement.addContent(reportElement);
929             propertyElement = new Element((String JavaDoc)iterator.next(), DNSP);
930             reportElement.addContent(propertyElement);
931             xmlValue.add(supportedReportElement);
932         }
933         
934         return xmlValue;
935     }
936     
937     /**
938      * Returns an XMLValue containing <code>&lt;href&gt;</code> elements
939      * with the URI of the VCRs that have a <code>&lt;checked-out&gt;</code>
940      * property pointing to this VR.
941      * If the resource is not a VR, the returned XMLValue is empty.
942      * The difference to the other
943      * {@link #computeCheckoutSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) computeCheckoutSet()}
944      * method signature is that the <code>&lt;href&gt;</code> contain only
945      * the slide URI and not the complete URI that is to be returned by e.g.
946      * PROPFIND.
947      *
948      * @deprecated use {@link #computeCheckoutSet(NodeRevisionDescriptors, NodeRevisionDescriptor, String)}
949      * @param revisionDescriptors the NodeRevisionDescriptors of the VR.
950      * @param revisionDescriptor the NodeRevisionDescriptor of the VR.
951      *
952      * @return the value of the <code>&lt;checkout-set&gt;</code> property.
953      *
954      * @throws SlideException
955      * @throws JDOMException
956      */

957     public XMLValue computeCheckoutSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) throws SlideException, JDOMException {
958         return computeCheckoutSet(revisionDescriptors, revisionDescriptor, null);
959     }
960     
961     /**
962      * Returns an XMLValue containing <code>&lt;href&gt;</code> elements
963      * with the URI of the VCRs that have a <code>&lt;checked-out&gt;</code>
964      * property pointing to this VR.
965      * If the resource is not a VR, the returned XMLValue is empty.
966      *
967      * @param revisionDescriptors the NodeRevisionDescriptors of the VR.
968      * @param revisionDescriptor the NodeRevisionDescriptor of the VR.
969      * @param contextPath a String , the result of HttpRequest.getContextPath()
970      * @param servletPath a String, the result of HttpRequest.getServletPath()
971      *
972      * @return the value of the <code>&lt;checkout-set&gt;</code> property.
973      *
974      * @throws SlideException
975      * @throws JDOMException
976      */

977     public XMLValue computeCheckoutSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws SlideException, JDOMException {
978         
979         XMLValue xmlValue = new XMLValue();
980         
981         ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor);
982         if (resourceKind instanceof Version) {
983             
984             String JavaDoc resourcePath = VersioningHelper.getUri(nsaToken,
985                                                           sToken,
986                                                           nsaToken.getContentHelper(),
987                                                           revisionDescriptors,
988                                                           revisionDescriptor);
989             
990             Element basicSearch = getCheckoutSetQueryElement(resourcePath);
991             
992             String JavaDoc grammarNamespace = basicSearch.getNamespaceURI();
993             Search searchHelper = nsaToken.getSearchHelper();
994         // @FIXME Why is servletPath not required?
995
SearchQuery searchQuery = searchHelper.createSearchQuery(grammarNamespace,
996                                                                      basicSearch,
997                                                                      sToken,
998                                                                      Integer.MAX_VALUE,
999                                                                      slideContextPath);
1000            
1001            SearchQueryResult queryResult = searchHelper.search(sToken, searchQuery);
1002            Iterator JavaDoc queryResultIterator = queryResult.iterator();
1003            RequestedResource requestedResource = null;
1004            Element href = null;
1005            while (queryResultIterator.hasNext()) {
1006                requestedResource = (RequestedResource)queryResultIterator.next();
1007                href = new Element(E_HREF, DNSP);
1008                
1009                href.setText (WebdavUtils.getAbsolutePath (
1010                                  requestedResource.getUri(), slideContextPath, sConf));
1011                
1012                xmlValue.add(href);
1013            }
1014        }
1015        
1016        return xmlValue;
1017    }
1018    
1019    /**
1020     * Returns the query document used to search all resources that have
1021     * a &lt;checked-out&gt; property with a &lt;href&gt; value containing
1022     * the URI that identifies the given resource.
1023     *
1024     * @param resourcePath the Uri to search for.
1025     *
1026     * @return the query document.
1027     */

1028    protected Element getCheckoutSetQueryElement(String JavaDoc resourcePath) throws SlideException {
1029        
1030        if (checkoutSetQueryElement == null) {
1031            
1032            checkoutSetQueryElement = new Element(DaslConstants.E_BASICSEARCH, DNSP);
1033            
1034            Element select = new Element(DaslConstants.E_SELECT, DNSP);
1035            checkoutSetQueryElement.addContent(select);
1036            Element prop = new Element(E_PROP, DNSP);
1037            select.addContent(prop);
1038            Element checkedOut = new Element(P_CHECKED_OUT, DNSP);
1039            prop.addContent(checkedOut);
1040            
1041            Element from = new Element(DaslConstants.E_FROM, DNSP);
1042            checkoutSetQueryElement.addContent(from);
1043            Element scope = new Element(DaslConstants.E_SCOPE, DNSP);
1044            from.addContent(scope);
1045            Element href = new Element(E_HREF, DNSP);
1046            scope.addContent(href);
1047            href.setText("");
1048            Iterator JavaDoc excludeIterator = getNonVcrPathExcludeList().iterator();
1049            while (excludeIterator.hasNext()) {
1050                scope.addContent((Element)excludeIterator.next());
1051            }
1052            
1053            Element where = new Element(DaslConstants.E_WHERE, DNSP);
1054            checkoutSetQueryElement.addContent(where);
1055            Element propcontains = new Element(DaslConstants.E_PROPCONTAINS, NamespaceCache.SLIDE_NAMESPACE);
1056            where.addContent(propcontains);
1057            propcontains.addContent((Element)prop.clone());
1058            checkoutSetQueryLiteralElement = new Element(DaslConstants.E_LITERAL, DNSP);
1059            propcontains.addContent(checkoutSetQueryLiteralElement);
1060        }
1061        checkoutSetQueryLiteralElement.setText(resourcePath);
1062        
1063        return checkoutSetQueryElement;
1064    }
1065    
1066    /**
1067     ** Returns a List of <code>&lt;exclude&gt;</code> elements containing the
1068     ** paths to exclude from the search since they does not contain
1069     ** version-controlled resources (e.g. the users path and the history paths) .
1070     **
1071     ** @pre true
1072     ** @post true
1073     **
1074     ** @return a List of <code>&lt;exclude&gt;</code> elements.
1075     **/

1076    public List JavaDoc getNonVcrPathExcludeList() {
1077        
1078        List JavaDoc excludeList = new ArrayList JavaDoc();
1079        
1080        String JavaDoc usersPath = truncateLeadingSlash(nsaToken.getNamespaceConfig().getUsersPath());
1081        addExcludeElement(usersPath, excludeList);
1082        
1083        String JavaDoc groupsPath = truncateLeadingSlash(nsaToken.getNamespaceConfig().getGroupsPath());
1084        addExcludeElement(groupsPath, excludeList);
1085        
1086        String JavaDoc rolesPath = truncateLeadingSlash(nsaToken.getNamespaceConfig().getRolesPath());
1087        addExcludeElement(rolesPath, excludeList);
1088        
1089        Iterator JavaDoc historyPathIterator = HistoryPathHandler.getHistoryPathHandler().getResolvedHistoryPaths().iterator();
1090        while (historyPathIterator.hasNext()) {
1091            String JavaDoc path = truncateLeadingSlash(historyPathIterator.next().toString());
1092            addExcludeElement(path, excludeList);
1093        }
1094        
1095        return excludeList;
1096    }
1097    
1098    private void addExcludeElement(String JavaDoc path, List JavaDoc excludeList) {
1099        if (path != null && path.length() > 0) {
1100            Element excludeElement = new Element(DaslConstants.E_EXCLUDE, NamespaceCache.SLIDE_NAMESPACE);
1101            excludeElement.setText(path);
1102            excludeList.add(excludeElement);
1103        }
1104    }
1105    
1106    /**
1107     * Returns an XMLValue containing <code>&lt;href&gt;</code> elements
1108     * with the URI of the VCRs in the workspace identified the given
1109     * NodeRevisionDescriptor(s) that have a <code>&lt;checked-out&gt;</code>.
1110     * If the resource is not a Workspace, the returned XMLValue is empty.
1111     *
1112     * @param revisionDescriptors the NodeRevisionDescriptors of the Workspace.
1113     * @param revisionDescriptor the NodeRevisionDescriptor of the Workspace.
1114     * @param contextPath a String , the result of HttpRequest.getContextPath()
1115     * @param servletPath a String, the result of HttpRequest.getServletPath()
1116     *
1117     * @return the value of the <code>&lt;workspace-checkout-set&gt;</code> property.
1118     *
1119     * @throws SlideException
1120     * @throws JDOMException
1121     */

1122    public XMLValue computeWorkspaceNoBinding(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws SlideException, JDOMException {
1123        XMLValue result = null;
1124        UriHandler hrUh = UriHandler.getUriHandler(revisionDescriptors, revisionDescriptor);
1125        String JavaDoc associatedWsUri = hrUh.getAssociatedWorkspaceUri();
1126        if (associatedWsUri != null) {
1127            result = new XMLValue();
1128            Element hrElm = new Element(E_HREF, DNSP);
1129            hrElm.setText(associatedWsUri);
1130            result.add(hrElm);
1131        }
1132        return result;
1133    }
1134    
1135    /**
1136     * Returns an XMLValue containing <code>&lt;href&gt;</code> elements
1137     * with the URI of the VCRs in the workspace identified the given
1138     * NodeRevisionDescriptor(s) that have a <code>&lt;checked-out&gt;</code>.
1139     * If the resource is not a Workspace, the returned XMLValue is empty.
1140     *
1141     * @param revisionDescriptors the NodeRevisionDescriptors of the Workspace.
1142     * @param revisionDescriptor the NodeRevisionDescriptor of the Workspace.
1143     * @param contextPath a String , the result of HttpRequest.getContextPath()
1144     * @param servletPath a String, the result of HttpRequest.getServletPath()
1145     *
1146     * @return the value of the <code>&lt;workspace-checkout-set&gt;</code> property.
1147     *
1148     * @throws SlideException
1149     * @throws JDOMException
1150     */

1151    public XMLValue computeWorkspace(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws SlideException, JDOMException {
1152        XMLValue result = null;
1153        
1154        UriHandler rUh = new UriHandler(revisionDescriptors.getUri());
1155        if (rUh.getAssociatedWorkspaceUri() != null) {
1156            result = new XMLValue();
1157            Element hrElm = new Element(E_HREF, DNSP);
1158            hrElm.setText(rUh.getAssociatedWorkspaceUri());
1159            result.add(hrElm);
1160            return result;
1161        }
1162        
1163        NodeProperty psProp = revisionDescriptor.getProperty(P_PARENT_SET);
1164        if (psProp == null) {
1165            return new XMLValue();
1166        }
1167        
1168        List JavaDoc psUris = new ArrayList JavaDoc();
1169        XMLValue xv = new XMLValue(String.valueOf(psProp.getValue()));
1170        Iterator JavaDoc i = xv.getList().iterator();
1171        while (i.hasNext()) {
1172            Element pElm = (Element)i.next();
1173            UriHandler hrUh = new UriHandler(pElm.getChild(E_HREF, DNSP).getText());
1174            if (hrUh.getAssociatedWorkspaceUri() != null) {
1175                result = new XMLValue();
1176                Element hrElm = new Element(E_HREF, DNSP);
1177                hrElm.setText(hrUh.getAssociatedWorkspaceUri());
1178                result.add(hrElm);
1179                break;
1180            }
1181            else if (!hrUh.isRootUri()) {
1182                psUris.add(hrUh);
1183            }
1184        }
1185        
1186        if (result == null) {
1187            i = psUris.iterator();
1188            while (i.hasNext()) {
1189                NodeRevisionDescriptors nrds =
1190                    nsaToken.getContentHelper().retrieve(sToken, ((UriHandler)i.next()).getUri());
1191                NodeRevisionDescriptor nrd =
1192                    nsaToken.getContentHelper().retrieve(sToken, nrds);
1193                result = computeWorkspace(nrds, nrd, slideContextPath);
1194                if (result != null) {
1195                    break;
1196                }
1197            }
1198        }
1199        
1200        return result;
1201    }
1202    
1203    /**
1204     * Returns an XMLValue containing <code>&lt;href&gt;</code> elements
1205     * with the URI of the VCRs in the workspace identified the given
1206     * NodeRevisionDescriptor(s) that have a <code>&lt;checked-out&gt;</code>.
1207     * If the resource is not a Workspace, the returned XMLValue is empty.
1208     *
1209     * @param revisionDescriptors the NodeRevisionDescriptors of the Workspace.
1210     * @param revisionDescriptor the NodeRevisionDescriptor of the Workspace.
1211     * @param contextPath a String , the result of HttpRequest.getContextPath()
1212     * @param servletPath a String, the result of HttpRequest.getServletPath()
1213     *
1214     * @return the value of the <code>&lt;workspace-checkout-set&gt;</code> property.
1215     *
1216     * @throws SlideException
1217     * @throws JDOMException
1218     */

1219    public XMLValue computeWorkspaceCheckoutSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws SlideException, JDOMException {
1220        
1221        XMLValue xmlValue = new XMLValue();
1222        
1223        ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor);
1224        if (resourceKind instanceof Workspace) {
1225            
1226            Element basicSearch = getWorkspaceCheckoutSetQueryElement(revisionDescriptors.getUri());
1227            String JavaDoc grammarNamespace = basicSearch.getNamespaceURI();
1228            Search searchHelper = nsaToken.getSearchHelper();
1229            SearchQuery searchQuery = searchHelper.createSearchQuery(grammarNamespace,
1230                                                                     basicSearch,
1231                                                                     sToken,
1232                                                                     Integer.MAX_VALUE,
1233                                                                     slideContextPath);
1234            SearchQueryResult queryResult = searchHelper.search(sToken, searchQuery);
1235            Iterator JavaDoc queryResultIterator = queryResult.iterator();
1236            RequestedResource requestedResource = null;
1237            Element hrefElement = null;
1238            while (queryResultIterator.hasNext()) {
1239                requestedResource = (RequestedResource)queryResultIterator.next();
1240                hrefElement = new Element(E_HREF, DNSP);
1241                
1242                
1243                hrefElement.setText (WebdavUtils.getAbsolutePath (
1244                                         requestedResource.getUri(),
1245                                         slideContextPath, sConf));
1246                
1247                xmlValue.add(hrefElement);
1248            }
1249        }
1250        
1251        return xmlValue;
1252    }
1253    
1254    /**
1255     * Returns the query document used to search all resources that have
1256     * a &lt;checked-out&gt; property within the given <code>scopePath</code>.
1257     *
1258     * @param scopePath the Uri of the scope to search in.
1259     *
1260     * @return the query document.
1261     */

1262    protected Element getWorkspaceCheckoutSetQueryElement(String JavaDoc scopePath) {
1263        
1264        if (workspaceCheckoutSetQueryElement == null) {
1265            
1266            workspaceCheckoutSetQueryElement = new Element(DaslConstants.E_BASICSEARCH, DNSP);
1267            
1268            Element select = new Element(DaslConstants.E_SELECT, DNSP);
1269            workspaceCheckoutSetQueryElement.addContent(select);
1270            Element prop = new Element(E_PROP, DNSP);
1271            select.addContent(prop);
1272            Element checkedOut = new Element(P_CHECKED_OUT, DNSP);
1273            prop.addContent(checkedOut);
1274            
1275            Element from = new Element(DaslConstants.E_FROM, DNSP);
1276            workspaceCheckoutSetQueryElement.addContent(from);
1277            Element scope = new Element(DaslConstants.E_SCOPE, DNSP);
1278            from.addContent(scope);
1279            workspaceCheckoutSetQueryHrefElement = new Element(E_HREF, DNSP);
1280            scope.addContent(workspaceCheckoutSetQueryHrefElement);
1281            
1282            Element where = new Element(DaslConstants.E_WHERE, DNSP);
1283            workspaceCheckoutSetQueryElement.addContent(where);
1284            Element isdefined = new Element(DaslConstants.E_ISDEFINED, DNSP);
1285            where.addContent(isdefined);
1286            isdefined.addContent((Element)prop.clone());
1287        }
1288        workspaceCheckoutSetQueryHrefElement.setText(truncateLeadingSlash(scopePath));
1289        
1290        return workspaceCheckoutSetQueryElement;
1291    }
1292    
1293    /**
1294     * Returns an XMLValue containing the value of the <code>&lt;lockdiscovery&gt;</code>
1295     * property.
1296     *
1297     * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
1298     * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
1299     * @param contextPath a String , the result of HttpRequest.getContextPath()
1300     * @param servletPath a String, the result of HttpRequest.getServletPath()
1301     *
1302     * @return the value of the <code>&lt;lockdiscovery&gt;</code> property.
1303     *
1304     * @throws ServiceAccessException
1305     * @throws LinkedObjectNotFoundException
1306     * @throws ObjectNotFoundException
1307     */

1308    private XMLValue computeLockDiscovery(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ServiceAccessException, LinkedObjectNotFoundException, ObjectNotFoundException, LockTokenNotFoundException {
1309        
1310        XMLValue xmlValue = new XMLValue();
1311        Lock lock = nsaToken.getLockHelper();
1312        NodeLock objectLockToken = null;
1313        Enumeration JavaDoc lockTokens = lock.enumerateLocks(sToken, revisionDescriptors.getUri(), true);
1314        Set JavaDoc addedLockIDs = new HashSet JavaDoc();
1315        while (lockTokens.hasMoreElements()) {
1316            objectLockToken = (NodeLock) lockTokens.nextElement();
1317            if (revisionDescriptors.getUri().equals(objectLockToken.getObjectUri()) ||
1318                objectLockToken.isInheritable()
1319               ) {
1320                
1321                if (!addedLockIDs.contains(objectLockToken.getLockId())) {
1322                    Element activelock = createActiveLockElement(objectLockToken,
1323                            slideContextPath);
1324                    if (activelock != null) {
1325                        xmlValue.add(activelock);
1326                        addedLockIDs.add(objectLockToken.getLockId());
1327                    }
1328                }
1329            }
1330        }
1331        
1332        return xmlValue;
1333    }
1334    
1335    /**
1336     * Returns an XMLValue containing the value of the <code>&lt;lockdiscovery&gt;</code>
1337     * property.
1338     *
1339     * @param objectLockToken the NodeLock for which to compute the value
1340     * @param servletPath a String, the result of HttpRequest.getServletPath()
1341     * @param contextPath a String , the result of HttpRequest.getContextPath()
1342     *
1343     * @return the value of the <code>&lt;lockdiscovery&gt;</code> property.
1344     *
1345     */

1346    public XMLValue computeLockDiscovery(NodeLock objectLockToken, String JavaDoc slideContextPath) {
1347        
1348        XMLValue xmlValue = new XMLValue();
1349        Element activelock = createActiveLockElement(objectLockToken, slideContextPath);
1350        
1351        if (activelock != null) {
1352            xmlValue.add(activelock);
1353        }
1354        return xmlValue;
1355    }
1356    
1357    /**
1358     * Returns the <code>&lt;activelock&gt;</code> element to be used as child
1359     * the <code>&lt;lockdiscovery&gt;</code> property.
1360     *
1361     * @param objectLockToken the NodeLock for which to compute the value
1362     * of the <code>&lt;activelock&gt;</code>.
1363     * @param servletPath a String, the result of HttpRequest.getServletPath()
1364     * @param contextPath a String , the result of HttpRequest.getContextPath()
1365     *
1366     * @return the <code>&lt;activelock&gt;</code> element.
1367     *
1368     */

1369    private Element createActiveLockElement(NodeLock objectLockToken, String JavaDoc slideContextPath) {
1370        
1371        Element activelock = null;
1372        //Security security = nsaToken.getSecurityHelper();
1373

1374        if (objectLockToken != null) {
1375            
1376            activelock = new Element(E_ACTIVELOCK, DNSP);
1377            Element locktype = new Element(E_LOCKTYPE, DNSP);
1378            activelock.addContent(locktype);
1379            if (objectLockToken.isLocal()) {
1380                Element transaction = new Element(E_TRANSACTION, DNSP);
1381                Element groupoperation = new Element(E_GROUPOPERATION, DNSP);
1382                transaction.addContent(groupoperation);
1383                locktype.addContent(transaction);
1384            } else {
1385                Element write = new Element(E_WRITE, DNSP);
1386                locktype.addContent(write);
1387            }
1388            Element lockscope = new Element(E_LOCKSCOPE, DNSP);
1389            activelock.addContent(lockscope);
1390            Element lockscopeValue = null;
1391            if (objectLockToken.isExclusive()) {
1392                lockscopeValue = new Element(E_EXCLUSIVE, DNSP);
1393            } else if (objectLockToken.isShared()) {
1394                lockscopeValue = new Element(E_SHARED, DNSP);
1395            } else if (objectLockToken.isLocal()) {
1396                lockscopeValue = new Element(E_LOCAL, DNSP);
1397            }
1398            lockscope.addContent(lockscopeValue);
1399            Element depth = new Element(E_DEPTH, DNSP);
1400            activelock.addContent(depth);
1401            if (objectLockToken.isInheritable()) {
1402                depth.setText("infinity");
1403            } else {
1404                depth.setText("0");
1405            }
1406            Element owner = new Element(E_OWNER, DNSP);
1407            activelock.addContent(owner);
1408            /* We need to write this as data (i.e. a CDATA section) because
1409             * we don't know what the subjectUri (i.e. username) might
1410             * contain. The webdav RFC leaves us completely free to
1411             * put whatever we want inside the owner element.
1412             */

1413            if( objectLockToken.getOwnerInfo() != null &&
1414               !objectLockToken.getOwnerInfo().equals(LockMethod.DEFAULT_LOCK_OWNER) ) {
1415                
1416                // try to parse
1417
try {
1418                    Document d =
1419                        new SAXBuilder().build( new StringReader JavaDoc(objectLockToken.getOwnerInfo()) );
1420                    owner.addContent(d.detachRootElement());
1421                }
1422                catch( Throwable JavaDoc e ) {
1423                    owner.addContent(new CDATA(objectLockToken.getOwnerInfo()));
1424                }
1425            }
1426            
1427            Element timeout = new Element(E_TIMEOUT, DNSP);
1428            activelock.addContent(timeout);
1429            long seconds = (new Long JavaDoc((objectLockToken.getExpirationDate().getTime()
1430                                          - (new Date JavaDoc()).getTime())/1000)).longValue();
1431            if (seconds > 0.75 * Integer.MAX_VALUE) {
1432                timeout.setText("Infinite");
1433            }
1434            else {
1435                timeout.setText("Second-"+seconds);
1436            }
1437            Element locktoken = new Element(E_LOCKTOKEN, DNSP);
1438            activelock.addContent(locktoken);
1439            Element href = new Element(E_HREF, DNSP);
1440            locktoken.addContent(href);
1441            href.setText(S_LOCK_TOKEN+objectLockToken.getLockId());
1442            
1443            // As proposed on February 08, 2003 by Lisa Dusseault in w3c-dist-auth-request@w3.org
1444
// >>>>>>>>>> start principal-URL >>>>>>>>>>>>
1445
if( lockdiscoveryIncludesPrincipalURL ) {
1446                Element principalUrl = new Element( E_PRINCIPAL_URL, DNSP);
1447                activelock.addContent(principalUrl);
1448                SubjectNode snode =
1449                    SubjectNode.getSubjectNode(objectLockToken.getSubjectUri());
1450                String JavaDoc subjectUri = objectLockToken.getSubjectUri();
1451                if (snode.equals(SubjectNode.UNAUTHENTICATED)) {
1452                    String JavaDoc userspath = nsaToken.getNamespaceConfig().getUsersPath();
1453                    subjectUri = userspath+"/"+snode.toString();
1454                }
1455                Element puhref = new Element(E_HREF, DNSP);
1456                principalUrl.addContent(puhref);
1457                
1458                puhref.setText(
1459                    WebdavUtils.getAbsolutePath(subjectUri, slideContextPath, sConf));
1460            }
1461            // <<<<<<<<<< end principal-URL <<<<<<<<<<<<<<
1462
}
1463        return activelock;
1464    }
1465    
1466    /**
1467     * Returns an XMLValue containing the value of the <code>&lt;supportedlock&gt;</code>
1468     * property.
1469     *
1470     * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
1471     * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
1472     * @param contextPath the context path of the NodeRevisionDescriptors' uri.
1473     * @param servletPath a String, the result of HttpRequest.getServletPath()
1474     *
1475     * @return the value of the <code>&lt;supportedlock&gt;</code> property.
1476     *
1477     * @throws ObjectLockedException
1478     * @throws RevisionDescriptorNotFoundException
1479     * @throws ServiceAccessException
1480     * @throws LinkedObjectNotFoundException
1481     * @throws AccessDeniedException
1482     * @throws ObjectNotFoundException
1483     * @throws JDOMException
1484     */

1485    public XMLValue computeSupportedlock(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1486        
1487        XMLValue xmlValue = new XMLValue();
1488        
1489        Element lockentry = new Element(E_LOCKENTRY, DNSP);
1490        Element lockscope = new Element(E_LOCKSCOPE, DNSP);
1491        lockentry.addContent(lockscope);
1492        Element exclusive = new Element(E_EXCLUSIVE, DNSP);
1493        lockscope.addContent(exclusive);
1494        Element locktype = new Element(E_LOCKTYPE, DNSP);
1495        lockentry.addContent(locktype);
1496        Element write = new Element(E_WRITE, DNSP);
1497        locktype.addContent(write);
1498        xmlValue.add(lockentry);
1499        
1500        lockentry = new Element(E_LOCKENTRY, DNSP);
1501        lockscope = new Element(E_LOCKSCOPE, DNSP);
1502        lockentry.addContent(lockscope);
1503        Element shared = new Element(E_SHARED, DNSP);
1504        lockscope.addContent(shared);
1505        locktype = new Element(E_LOCKTYPE, DNSP);
1506        lockentry.addContent(locktype);
1507        write = new Element(E_WRITE, DNSP);
1508        locktype.addContent(write);
1509        xmlValue.add(lockentry);
1510        
1511        return xmlValue;
1512    }
1513    
1514    
1515    /**
1516     * Returns an XMLValue containing the value of the <code>&lt;supported-privilege-set&gt;</code>
1517     * property.
1518     *
1519     * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
1520     * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
1521     * @param contextPath a String , the result of HttpRequest.getContextPath()
1522     * @param servletPath a String, the result of HttpRequest.getServletPath()
1523     *
1524     * @return the value of the <code>&lt;supported-privilege-set&gt;</code> property.
1525     *
1526     * @throws ObjectLockedException
1527     * @throws RevisionDescriptorNotFoundException
1528     * @throws ServiceAccessException
1529     * @throws LinkedObjectNotFoundException
1530     * @throws AccessDeniedException
1531     * @throws ObjectNotFoundException
1532     * @throws JDOMException
1533     */

1534    public XMLValue computeSupportedPrivilegeSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1535        Map JavaDoc actionAggregation = ((SecurityImpl)nsaToken.getSecurityHelper()).getActionAggregation(sToken);
1536        Set JavaDoc rootSet = new HashSet JavaDoc(actionAggregation.keySet());
1537        Iterator JavaDoc actions = actionAggregation.keySet().iterator();
1538        while (actions.hasNext()) {
1539            ActionNode a = (ActionNode)actions.next();
1540            Iterator JavaDoc aggregates = ((Set JavaDoc)actionAggregation.get(a)).iterator();
1541            while (aggregates.hasNext()) {
1542                ActionNode c = (ActionNode)aggregates.next();
1543                rootSet.remove(c);
1544            }
1545        }
1546        Element rootSp = new Element(E_SUPPORTED_PRIVILEGE, DNSP);
1547        Element p = new Element(E_PRIVILEGE, DNSP);
1548        p.addContent(new Element(E_ALL, DNSP));
1549        rootSp.addContent(p);
1550        Iterator JavaDoc roots = rootSet.iterator();
1551        addElementsForAggregatedActions(rootSp, roots, actionAggregation);
1552        return new XMLValue(rootSp);
1553    }
1554    
1555    /**
1556     * Build the tree of an action with all its aggregated actions for use in
1557     * the result of <code>supported-privilege-set</code> queries.
1558     *
1559     * This method modifies <code>parentActionElement</code>.
1560     *
1561     * @param parentActionElement The action element to which to add the direct
1562     * aggregated acttions to.
1563     * @param aggregatedActions The direct aggregated actions.
1564     * @param actionAggregation A map from an action to its direct aggregated
1565     * actions.
1566     */

1567    private void addElementsForAggregatedActions(Element parentActionElement, Iterator JavaDoc aggregatedActions, Map JavaDoc actionAggregation) {
1568        while (aggregatedActions.hasNext()) {
1569            ActionNode a = (ActionNode)aggregatedActions.next();
1570            Element sp = new Element(E_SUPPORTED_PRIVILEGE, DNSP);
1571            Element p = new Element(E_PRIVILEGE, DNSP);
1572            Namespace actionNamespace = a.getNamespace();
1573            if (actionNamespace == null) {
1574                actionNamespace = DNSP;
1575            }
1576            p.addContent(new Element(a.getPath().lastSegment(), actionNamespace));
1577            addElementsForAggregatedActions(p, ((Set JavaDoc)actionAggregation.get(a)).iterator(), actionAggregation);
1578            sp.addContent(p);
1579            parentActionElement.addContent(sp);
1580        }
1581    }
1582
1583
1584    /**
1585     * Creates a <code>&lt;privilege&gt;</code> element containing an
1586     * element with the given <code>privilegeName</code>.
1587     *
1588     * @param privilegeName the name of the privilege.
1589     *
1590     * @return the <code>&lt;privilege&gt;</code> element.
1591     * @throws ServiceAccessException
1592     * @throws RevisionDescriptorNotFoundException
1593     */

1594    private Element createPrivilege(ActionNode privilege, Uri privilegeUri) throws RevisionDescriptorNotFoundException, ServiceAccessException {
1595        return createPrivilege(privilege, true, privilegeUri);
1596    }
1597    
1598    /**
1599     * Creates a <code>&lt;privilege&gt;</code> element containing an
1600     * element with the given <code>privilegeName</code>.
1601     *
1602     * @param privilegeName the name of the privilege.
1603     * @param useDavNamespace if <code>true</code> the <code>DAV:</code>
1604     * namespace will be used for the contained element,
1605     * otherwise the slide namespace.
1606     *
1607     * @return the <code>&lt;privilege&gt;</code> element.
1608     * @throws ServiceAccessException
1609     * @throws RevisionDescriptorNotFoundException
1610     */

1611    private Element createPrivilege(ActionNode privilege, boolean useDavNamespace, Uri privilegeUri) throws RevisionDescriptorNotFoundException, ServiceAccessException {
1612        NodeRevisionNumber latestRevisionNumber = privilegeUri.getStore().retrieveRevisionDescriptors(privilegeUri).getLatestRevision();
1613        NodeProperty privilegeNamespaceProperty = privilegeUri.getStore().retrieveRevisionDescriptor(privilegeUri, latestRevisionNumber).getProperty(PRIVILEGE_NAMESPACE, WebdavConstants.S_DAV);
1614        Namespace privilegeNamespace = null;
1615        if (privilegeNamespaceProperty != null && privilegeNamespaceProperty.getValue() instanceof String JavaDoc) {
1616            privilegeNamespace = Namespace.getNamespace((String JavaDoc) privilegeNamespaceProperty.getValue());
1617        } else {
1618            privilegeNamespace = DNSP;
1619            if ( ! useDavNamespace ) {
1620                privilegeNamespace = NamespaceCache.SLIDE_NAMESPACE;
1621            }
1622        }
1623        Element privilegeElement = new Element(E_PRIVILEGE, DNSP);
1624        Element privilegeNameElement = new Element(privilege.getPath().lastSegment(), privilegeNamespace);
1625        privilegeElement.addContent(privilegeNameElement);
1626        return privilegeElement;
1627    }
1628    
1629    /**
1630     * Returns an XMLValue containing the value of the
1631     * <code>&lt;current-user-privilege-set&gt;</code> property.
1632     *
1633     * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
1634     * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
1635     * @param contextPath a String , the result of HttpRequest.getContextPath()
1636     * @param servletPath a String, the result of HttpRequest.getServletPath()
1637     *
1638     * @return the value of the <code>&lt;current-user-privilege-set&gt;</code> property.
1639     *
1640     * @throws ObjectLockedException
1641     * @throws RevisionDescriptorNotFoundException
1642     * @throws ServiceAccessException
1643     * @throws LinkedObjectNotFoundException
1644     * @throws AccessDeniedException
1645     * @throws ObjectNotFoundException
1646     * @throws JDOMException
1647     */

1648    public XMLValue computeCurrentuserPrivilegeSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1649        XMLValue xmlValue = new XMLValue();
1650        
1651        try {
1652        NamespaceConfig config = nsaToken.getNamespaceConfig();
1653        Structure structure = nsaToken.getStructureHelper();
1654        ObjectNode object = structure.retrieve(sToken, revisionDescriptors.getUri());
1655
1656        // check read-own-permissions permission
1657
Security security = nsaToken.getSecurityHelper();
1658        security.checkCredentials(sToken, object, config.getReadOwnPermissionsAction());
1659        
1660            String JavaDoc actionsPath = config.getActionsPath();
1661            Uri actionsPathUri = nsaToken.getUri(sToken, actionsPath);
1662            ObjectNode actionsPathNode = actionsPathUri.getStore().retrieveObject(actionsPathUri);
1663            Enumeration JavaDoc actions = actionsPathNode.enumerateChildren();
1664            addGrantedActionsToPrivilegeSet(xmlValue, object, actions);
1665        }
1666        catch (ServiceAccessException e) {
1667            throw e;
1668        }
1669        catch (SlideException e) {
1670            return xmlValue;
1671        }
1672        return xmlValue;
1673    }
1674    
1675    /**
1676     * Build a set of privileges a subject has for an object for use in the
1677     * result of <code>current-user-privilege-set</code> queries.
1678     *
1679     * This method modifies <code>xmlValue</code>.
1680     *
1681     * @param xmlValue The element to which to add the actions which have been
1682     * granted to the subject.
1683     * @param object The object for which to determine which actions have been
1684     * granted.
1685     * @param actions The URIs (as <code>String</code>s) of the actions to
1686     * check.
1687     */

1688    private void addGrantedActionsToPrivilegeSet(XMLValue xmlValue, ObjectNode object, Enumeration JavaDoc actions) throws ServiceAccessException, ObjectNotFoundException, RevisionDescriptorNotFoundException {
1689        while (actions.hasMoreElements()) {
1690            Uri aNodeUri = nsaToken.getUri(sToken, (String JavaDoc)actions.nextElement());
1691            ObjectNode oNode = aNodeUri.getStore().retrieveObject(aNodeUri);
1692            if (oNode.hasChildren()) {
1693                addGrantedActionsToPrivilegeSet(xmlValue, object, oNode.enumerateChildren());
1694            } else {
1695                ActionNode aNode = ActionNode.getActionNode(oNode.getUri());
1696                if (nsaToken.getSecurityHelper().hasPermission(sToken, object, aNode)) {
1697                    xmlValue.add(createPrivilege(aNode, aNodeUri));
1698                }
1699            }
1700        }
1701    }
1702
1703
1704    /**
1705     * Returns an XMLValue containing the value of the
1706     * <code>&lt;acl&gt;</code> property.
1707     *
1708     * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
1709     * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
1710     * @param contextPath a String , the result of HttpRequest.getContextPath()
1711     * @param servletPath a String, the result of HttpRequest.getServletPath()
1712     *
1713     * @return the value of the <code>&lt;acl&gt;</code> property.
1714     *
1715     * @throws ObjectLockedException
1716     * @throws RevisionDescriptorNotFoundException
1717     * @throws ServiceAccessException
1718     * @throws LinkedObjectNotFoundException
1719     * @throws AccessDeniedException
1720     * @throws ObjectNotFoundException
1721     * @throws JDOMException
1722     */

1723    //public XMLValue computeAcl(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String contextPath, String serverURL) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException, VetoException {
1724
public XMLValue computeAcl(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException, VetoException {
1725        // FIXME serverUrl?
1726
XMLValue xmlValue = new XMLValue();
1727        
1728        NamespaceConfig config = nsaToken.getNamespaceConfig();
1729        Structure structure = nsaToken.getStructureHelper();
1730        ObjectNode objectNode = structure.retrieve(sToken, revisionDescriptors.getUri());
1731        
1732        // check read-acl permission
1733
Security security = nsaToken.getSecurityHelper();
1734        security.checkCredentials(sToken, objectNode, config.getReadPermissionsAction());
1735        
1736        String JavaDoc currentSubjectUri = "";
1737        boolean currentNegative = false;
1738        String JavaDoc currentInheritedFrom = "";
1739        Element currentAceElm = null;
1740        Element currentGrantDenyElm = null;
1741        Enumeration JavaDoc permissions = security.enumeratePermissions(sToken, objectNode, true);
1742        while (permissions.hasMoreElements()) {
1743            NodePermission perm = (NodePermission)permissions.nextElement();
1744            if (!perm.getSubjectUri().equals(currentSubjectUri)
1745                || (perm.isNegative() && !currentNegative || !perm.isNegative() && currentNegative)
1746                || (!currentInheritedFrom.equals(perm.getInheritedFrom()))) {
1747                
1748                // save previous ACE
1749
if (currentAceElm != null) {
1750                    xmlValue.add(currentAceElm);
1751                }
1752                
1753                // new ACE
1754
currentAceElm = new Element(E_ACE, DNSP);
1755                
1756                // principal
1757
if (perm.isInvert()) {
1758                    Element invertElm = new Element(E_INVERT, DNSP);
1759                    invertElm.addContent(createPrincipalElement(perm.getSubjectUri()));
1760                    currentAceElm.addContent(invertElm);
1761                }
1762                else {
1763                    currentAceElm.addContent(createPrincipalElement(perm.getSubjectUri()));
1764                }
1765                
1766                // grant/deny
1767
currentGrantDenyElm = perm.isNegative()
1768                    ? new Element(E_DENY, DNSP)
1769                    : new Element(E_GRANT, DNSP);
1770                currentAceElm.addContent(currentGrantDenyElm);
1771                
1772                // inherited
1773
String JavaDoc inheritedFrom = perm.getInheritedFrom();
1774                if (inheritedFrom != null && inheritedFrom.length() > 0) {
1775                    currentAceElm.addContent(createInheritedElement(inheritedFrom));
1776                }
1777                
1778                // protected
1779
if (perm.isProtected()) {
1780                    currentAceElm.addContent(new Element(E_PROTECTED, DNSP));
1781                }
1782                
1783                currentSubjectUri = perm.getSubjectUri();
1784                currentNegative = perm.isNegative();
1785                currentInheritedFrom = inheritedFrom != null ? inheritedFrom : "";
1786            }
1787            currentGrantDenyElm.addContent(createPrivilegeElement(perm.getActionUri()));
1788        }
1789        
1790        // save last ACE
1791
if (currentAceElm != null) {
1792            xmlValue.add(currentAceElm);
1793        }
1794        
1795        return xmlValue;
1796    }
1797    
1798    private Element createInheritedElement(String JavaDoc inheritedFrom) {
1799        Element inheritedElm = new Element(E_INHERITED, DNSP);
1800        Element hrefElm = new Element(E_HREF, DNSP);
1801        hrefElm.addContent(new Text(inheritedFrom));
1802        inheritedElm.addContent(hrefElm);
1803        return inheritedElm;
1804    }
1805    
1806    private Element createPrincipalElement(String JavaDoc subjectUri) {
1807        Element principalElm = new Element(E_PRINCIPAL, DNSP);
1808        if (subjectUri.equals(SubjectNode.ALL_URI)) {
1809            Element allElm = new Element(E_ALL, DNSP);
1810            principalElm.addContent(allElm);
1811        }
1812        else if (subjectUri.equals(SubjectNode.AUTHENTICATED_URI)) {
1813            Element authenticatedElm = new Element(E_AUTHENTICATED, DNSP);
1814            principalElm.addContent(authenticatedElm);
1815        }
1816        else if (subjectUri.equals(SubjectNode.UNAUTHENTICATED_URI)) {
1817            Element unauthenticatedElm = new Element(E_UNAUTHENTICATED, DNSP);
1818            principalElm.addContent(unauthenticatedElm);
1819        }
1820        else if (subjectUri.equals(SubjectNode.OWNER_URI)) {
1821            Element propertyElm = new Element(E_PROPERTY, DNSP);
1822            propertyElm.addContent(new Element(P_OWNER, DNSP));
1823            principalElm.addContent(propertyElm);
1824        }
1825        else if (subjectUri.equals(SubjectNode.SELF_URI)) {
1826            Element selfElm = new Element(E_SELF, DNSP);
1827            principalElm.addContent(selfElm);
1828        }
1829        else {
1830            Element hrefElm = new Element(E_HREF, DNSP);
1831            hrefElm.addContent(new Text(subjectUri));
1832            principalElm.addContent(hrefElm);
1833        }
1834        return principalElm;
1835    }
1836    
1837    private Element createPrivilegeElement(String JavaDoc actionUriAsString) throws RevisionDescriptorNotFoundException, ServiceAccessException {
1838        Element privilegeElm = new Element(E_PRIVILEGE, DNSP);
1839        if (actionUriAsString.equals(ActionNode.ALL_URI)) {
1840            Element allElm = new Element(E_ALL, DNSP);
1841            privilegeElm.addContent(allElm);
1842        }
1843        else {
1844            Uri actionUri = nsaToken.getUri(sToken, actionUriAsString);
1845            NodeRevisionNumber latestRevisionNumber = actionUri.getStore().retrieveRevisionDescriptors(actionUri).getLatestRevision();
1846            NodeProperty privilegeNamespace = actionUri.getStore().retrieveRevisionDescriptor(actionUri, latestRevisionNumber).getProperty(PRIVILEGE_NAMESPACE, WebdavConstants.S_DAV);
1847            Namespace actionNamespace = null;
1848            if (privilegeNamespace != null && privilegeNamespace.getValue() instanceof String JavaDoc) {
1849                actionNamespace = Namespace.getNamespace((String JavaDoc) privilegeNamespace.getValue());
1850            }
1851            else {
1852                actionNamespace = DNSP;
1853            }
1854
1855            Element actionElm = new Element(new UriPath(actionUriAsString).lastSegment(), actionNamespace);
1856            privilegeElm.addContent(actionElm);
1857        }
1858        return privilegeElm;
1859    }
1860    
1861    /**
1862     * Returns an XMLValue containing the value of the
1863     * <code>&lt;principal-collection-set&gt;</code> property.
1864     *
1865     * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
1866     * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
1867     * @param contextPath a String , the result of HttpRequest.getContextPath()
1868     * @param servletPath a String, the result of HttpRequest.getServletPath()
1869     *
1870     * @return the value of the <code>&lt;principal-collection-set&gt;</code> property.
1871     *
1872     * @throws ObjectLockedException
1873     * @throws RevisionDescriptorNotFoundException
1874     * @throws ServiceAccessException
1875     * @throws LinkedObjectNotFoundException
1876     * @throws AccessDeniedException
1877     * @throws ObjectNotFoundException
1878     * @throws JDOMException
1879     */

1880    public XMLValue computePrincipalCollectionSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1881        XMLValue xmlValue = new XMLValue();
1882        NamespaceConfig namespaceConfig = nsaToken.getNamespaceConfig();
1883        
1884        xmlValue.addHref(WebdavUtils.getAbsolutePath (namespaceConfig.getUsersPath(),
1885                slideContextPath, sConf));
1886        
1887        if (namespaceConfig.getGroupsPath() != null) {
1888            
1889            xmlValue.addHref(WebdavUtils.getAbsolutePath (namespaceConfig.getGroupsPath(),
1890                    slideContextPath, sConf));
1891        }
1892        if (namespaceConfig.getRolesPath() != null) {
1893            xmlValue.addHref(WebdavUtils.getAbsolutePath (namespaceConfig.getRolesPath(),
1894                    slideContextPath, sConf));
1895        }
1896        return xmlValue;
1897    }
1898    
1899    
1900    public XMLValue computePrivilegeCollectionSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1901        XMLValue xmlValue = new XMLValue();
1902        NamespaceConfig namespaceConfig = nsaToken.getNamespaceConfig();
1903        
1904        String JavaDoc absUri = WebdavUtils.getAbsolutePath (namespaceConfig.getActionsPath(),
1905                slideContextPath, sConf);
1906        
1907        xmlValue.addHref(absUri);
1908        return xmlValue;
1909    }
1910    
1911    
1912    /**
1913     * Returns an XMLValue containing the value of the
1914     * <code>&lt;owner&gt;</code> property.
1915     * The XMLValue is comupted of userspath + user_collection + owner.
1916     * The userspath and the user_prefix properties are set in the Domain.xml file.
1917     *
1918     * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
1919     * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
1920     * @param contextPath a String , the result of HttpRequest.getContextPath()
1921     * @param servletPath a String, the result of HttpRequest.getServletPath()
1922     *
1923     * @return the value of the <code>&lt;owner&gt;</code> property.
1924     *
1925     * @throws ObjectLockedException
1926     * @throws RevisionDescriptorNotFoundException
1927     * @throws ServiceAccessException
1928     * @throws LinkedObjectNotFoundException
1929     * @throws AccessDeniedException
1930     * @throws ObjectNotFoundException
1931     * @throws JDOMException
1932     */

1933    public XMLValue computeOwner(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1934        
1935        NodeProperty ownerProperty = revisionDescriptor.getProperty(P_OWNER,
1936                                                                    NodeProperty.DEFAULT_NAMESPACE);
1937        
1938        XMLValue xmlValue = createUserPath(ownerProperty, slideContextPath);
1939        
1940        return xmlValue;
1941    }
1942    
1943    public XMLValue computeCreationUser(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1944        
1945        NodeProperty creationUserProperty = revisionDescriptor.getProperty(P_CREATIONUSER,
1946                                                                           NodeProperty.DEFAULT_NAMESPACE);
1947        XMLValue xmlValue = createUserPath(creationUserProperty, slideContextPath);
1948        
1949        return xmlValue;
1950    }
1951    
1952    public XMLValue computeModificationUser(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1953        
1954        NodeProperty modificationUserProperty = revisionDescriptor.getProperty(P_MODIFICATIONUSER,
1955                                                                               NodeProperty.DEFAULT_NAMESPACE);
1956        
1957        XMLValue xmlValue = createUserPath(modificationUserProperty, slideContextPath);
1958        
1959        return xmlValue;
1960    }
1961    
1962    public XMLValue computeInheritedAclSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1963        // TODO: find appropriate strategy, e.g. refer to root of namespace
1964
if (revisionDescriptor.getProperty(P_INHERITED_ACL_SET) != null) {
1965            Object JavaDoc v = revisionDescriptor.getProperty(P_INHERITED_ACL_SET).getValue();
1966            return (v instanceof XMLValue)
1967                ? (XMLValue)v
1968                : new XMLValue((String JavaDoc)v);
1969        }
1970        else {
1971            return new XMLValue();
1972        }
1973    }
1974    
1975    public XMLValue computeAclRestrictions(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1976        // no restrictions in Slide implementation?
1977
if (revisionDescriptor.getProperty(P_ACL_RESTRICTIONS) != null) {
1978            Object JavaDoc v = revisionDescriptor.getProperty(P_ACL_RESTRICTIONS).getValue();
1979            return (v instanceof XMLValue)
1980                ? (XMLValue)v
1981                : new XMLValue((String JavaDoc)v);
1982        }
1983        else {
1984            return new XMLValue();
1985        }
1986    }
1987    
1988    public XMLValue computeGroupMembership(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException {
1989        if (revisionDescriptor.getProperty(P_GROUP_MEMBERSHIP) != null) {
1990            Object JavaDoc v = revisionDescriptor.getProperty(P_GROUP_MEMBERSHIP).getValue();
1991            return (v instanceof XMLValue)
1992                ? (XMLValue)v
1993                : new XMLValue((String JavaDoc)v);
1994        }
1995        else {
1996            XMLValue xmlValue = new XMLValue();
1997            Uri principalUri = nsaToken.getUri(sToken, revisionDescriptors.getUri());
1998            SubjectNode principalNode = (SubjectNode)principalUri.getStore().retrieveObject(principalUri);
1999            Enumeration JavaDoc roles = ((ACLSecurityImpl)nsaToken.getSecurityHelper()).getGroupMembership(sToken, principalNode);
2000            while (roles.hasMoreElements()) {
2001                String JavaDoc rolePath = (String JavaDoc)roles.nextElement();
2002                String JavaDoc roleHref = slideContextPath+rolePath;
2003                xmlValue.addHref(roleHref);
2004            }
2005            return xmlValue;
2006        }
2007    }
2008    
2009    private XMLValue createUserPath(NodeProperty userProperty, String JavaDoc slideContextPath)
2010       throws IllegalArgumentException JavaDoc
2011    {
2012        XMLValue xmlValue = new XMLValue();
2013        String JavaDoc userHref = "";
2014        NamespaceConfig config = nsaToken.getNamespaceConfig();
2015        if ((userProperty != null) && (userProperty.getValue()!=null) &&
2016                (!"".equals(userProperty.getValue().toString()))) {
2017            
2018            userHref = slideContextPath + config.getUsersPath()
2019                       + "/" + userProperty.getValue().toString();
2020            xmlValue.addHref(userHref);
2021        }
2022        else {
2023            xmlValue.add(new Element(E_UNAUTHENTICATED, DNSP));
2024        }
2025        return xmlValue;
2026    }
2027    
2028    
2029    /**
2030     * Returns the concatenation of <code>serverURL</code>, <code>contextPath</code>
2031     * and <code>uri</code> and inserts all needed slashes.
2032     *
2033     * This method is deprecated, as it takes neither scope nor the servlet
2034     * path into account (when the servlet is not the default servlet). Please
2035     * use WebdavUtils.getAbsolutePath() instead.
2036     *
2037     * @deprecated
2038     * @param serverURL the URL of the server
2039     * @param contextPath the context path.
2040     * @param uri the (slide-) URI of the resource.
2041     *
2042     * @return the concatenated URL.
2043     */

2044    public static String JavaDoc getAbsoluteURL(String JavaDoc serverURL, String JavaDoc contextPath, String JavaDoc uri) {
2045        // FIXME servletContext??
2046
StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
2047        String JavaDoc lastAppended = null;
2048        // if (serverURL != null) {
2049
// buffer.append(serverURL);
2050
// lastAppended = buffer.toString();
2051
// }
2052
if (contextPath != null) {
2053            if ( (lastAppended != null) && !lastAppended.endsWith("/") && !contextPath.startsWith("/") ) {
2054                buffer.append("/");
2055            }
2056            buffer.append(contextPath);
2057            lastAppended = buffer.toString();
2058        }
2059        if (uri != null) {
2060            if ( (lastAppended != null) && !lastAppended.endsWith("/") && !uri.startsWith("/") ) {
2061                buffer.append("/");
2062            }
2063            buffer.append(uri);
2064        }
2065        
2066        return WebdavUtils.encodeURL(buffer.toString());
2067    }
2068    
2069    /**
2070     * Returns <code>true</code> if the given <code>uri</code> is an absolute URL.
2071     *
2072     * @param contextPath the context path.
2073     * @param uri the (slide-) URI of the resource.
2074     *
2075     * @return <code>true</code> if the given <code>uri</code> is an absolute URL.
2076     */

2077    public static boolean isAbsoluteURL(String JavaDoc servletContextPath, String JavaDoc uri) {
2078        if (uri.startsWith(S_RESOURCE_ID)) {
2079            return true;
2080        }
2081        if (uri.startsWith(S_LOCK_TOKEN)) {
2082            return true;
2083        }
2084        if (!uri.startsWith("/")) {
2085            uri = "/" + uri;
2086        }
2087        return uri.startsWith(servletContextPath);
2088    }
2089    
2090    /**
2091     * Adds the given <code>uri</code> as a <code>&lt;href&gt;</code> element
2092     * to the value of the property (specified by the <code>propertyName</code>)
2093     * of the given NodeRevisionDescriptor (if not already contained).
2094     *
2095     * @param revisionDescriptor the NodeRevisionDescriptor for which to
2096     * update the property.
2097     * @param propertyName the name of the property to add the uri to.
2098     * @param uri the uri to add as a <code>&lt;href&gt;</code> element.
2099     * @return true, if href was added; false, if already contained
2100     * @throws JDOMException
2101     *
2102     */

2103    public static boolean addHrefToProperty(NodeRevisionDescriptor revisionDescriptor, String JavaDoc propertyName, String JavaDoc uri) throws JDOMException {
2104        return addElementToProperty(revisionDescriptor, propertyName, E_HREF, uri);
2105    }
2106    
2107    /**
2108     * Adds the given <code>elementValue</code> as a <code>&lt;elementName&gt;</code> element
2109     * to the value of the property (specified by the <code>propertyName</code>)
2110     * of the given NodeRevisionDescriptor (if not already contained).
2111     *
2112     * @param revisionDescriptor the NodeRevisionDescriptor for which to
2113     * update the property.
2114     * @param propertyName the name of the property to add the element to.
2115     * @param elementName the name of the element to add.
2116     * @param elementValue the value to add as a <code>&lt;elementName&gt;</code> element.
2117     * @return true, if element was added; false, if already contained
2118     * @throws JDOMException
2119     *
2120     */

2121    public static boolean addElementToProperty(NodeRevisionDescriptor revisionDescriptor, String JavaDoc propertyName, String JavaDoc elementName, String JavaDoc elementValue) throws JDOMException {
2122        
2123        NodeProperty property = revisionDescriptor.getProperty(propertyName);
2124        if (property == null) {
2125            property = new NodeProperty(propertyName, null);
2126        }
2127        XMLValue xmlValue = new XMLValue((String JavaDoc)property.getValue());
2128        Iterator JavaDoc iterator = xmlValue.iterator();
2129        boolean alreadyContained = false;
2130        Element element = null;
2131        while (iterator.hasNext() && !alreadyContained) {
2132            element = (Element)iterator.next();
2133            if (element.getName().equals(elementName) && element.getText().equals(elementValue)) {
2134                alreadyContained = true;
2135            }
2136        }
2137        if (!alreadyContained) {
2138            element = new Element(elementName);
2139            element.setText(elementValue);
2140            xmlValue.add(element);
2141        }
2142        revisionDescriptor.setProperty(propertyName, xmlValue.toString());
2143        return !alreadyContained;
2144    }
2145    
2146    /**
2147     * Removes the <code>&lt;href&gt;</code> element with the given <code>uri</code>
2148     * from the value of the property (specified by the <code>propertyName</code>)
2149     * of the given NodeRevisionDescriptor (if contained).
2150     *
2151     * @param revisionDescriptor the NodeRevisionDescriptor for which to
2152     * update the property.
2153     * @param propertyName the name of the property to remove the uri from.
2154     * @param uri the uri of the <code>&lt;href&gt;</code> element
2155     * to remove.
2156     * @return true, if href was removed; false, if not found
2157     * @throws JDOMException
2158     *
2159     */

2160    public static boolean removeHrefFromProperty(NodeRevisionDescriptor revisionDescriptor, String JavaDoc propertyName, String JavaDoc uri) throws JDOMException {
2161        return removeElementFromProperty(revisionDescriptor, propertyName, E_HREF, uri);
2162    }
2163    
2164    /**
2165     * Removes the <code>&lt;elementName&gt;</code> element with the given <code>elementValue</code>
2166     * from the value of the property (specified by the <code>propertyName</code>)
2167     * of the given NodeRevisionDescriptor (if contained).
2168     *
2169     * @param revisionDescriptor the NodeRevisionDescriptor for which to
2170     * update the property.
2171     * @param propertyName the name of the property to add the element to.
2172     * @param elementName the name of the element to add.
2173     * @param elementValue the value to add as a <code>&lt;elementName&gt;</code> element.
2174     * @return true, if element was removed; false, if not found
2175     *
2176     * @throws JDOMException
2177     *
2178     */

2179    public static boolean removeElementFromProperty(NodeRevisionDescriptor revisionDescriptor, String JavaDoc propertyName, String JavaDoc elementName, String JavaDoc elementValue) throws JDOMException {
2180        
2181        NodeProperty property = revisionDescriptor.getProperty(propertyName);
2182        boolean found = false;
2183        if (property != null) {
2184            
2185            XMLValue xmlValue = new XMLValue((String JavaDoc)property.getValue());
2186            Iterator JavaDoc iterator = xmlValue.iterator();
2187            Element element = null;
2188            while (iterator.hasNext() && !found) {
2189                element = (Element)iterator.next();
2190                if (element.getName().equals(elementName) && element.getText().equals(elementValue)) {
2191                    found = true;
2192                    iterator.remove();
2193                }
2194            }
2195            if (found) {
2196                revisionDescriptor.setProperty(propertyName, xmlValue.toString());
2197            }
2198        }
2199        return found;
2200    }
2201    
2202    /**
2203     * Any leading <code>/</code> in the given <code>uri</code> will be removed.
2204     *
2205     * @param uri the Uri to remove leading slashes from.
2206     *
2207     * @return the Uri without leading slashes.
2208     */

2209    public static String JavaDoc truncateLeadingSlash(String JavaDoc uri) {
2210        
2211        if (uri == null) {
2212            return uri;
2213        }
2214        
2215        while (uri.startsWith("/")) {
2216            uri = uri.substring(1);
2217        }
2218        return uri;
2219    }
2220    
2221    /**
2222     * Any leading <code>/</code> in the given <code>uri</code> will be removed.
2223     *
2224     * @param uri the Uri to remove leading slashes from.
2225     *
2226     * @return the Uri without leading slashes.
2227     */

2228    public static String JavaDoc computeEtag(String JavaDoc uri, NodeRevisionDescriptor nrd) {
2229        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
2230        sb.append(System.currentTimeMillis()).append('_')
2231          .append(uri.hashCode()).append('_')
2232          .append(nrd.getLastModified()).append('_')
2233          .append(nrd.getContentLength());
2234        return new String JavaDoc(DigestUtils.md5Hex(sb.toString()));
2235    }
2236    
2237    
2238}
2239
2240
2241
2242
Popular Tags