KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java,v 1.39.2.1 2004/12/02 21:21:05 ozeigermann Exp $
3  * $Revision: 1.39.2.1 $
4  * $Date: 2004/12/02 21:21:05 $
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 package org.apache.slide.webdav.util;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import org.apache.slide.common.NamespaceAccessToken;
32 import org.apache.slide.common.PropertyName;
33 import org.apache.slide.common.RequestedProperties;
34 import org.apache.slide.common.RequestedPropertiesImpl;
35 import org.apache.slide.common.RequestedProperty;
36 import org.apache.slide.common.RequestedPropertyImpl;
37 import org.apache.slide.common.SlideException;
38 import org.apache.slide.common.SlideToken;
39 import org.apache.slide.common.UriPath;
40 import org.apache.slide.content.Content;
41 import org.apache.slide.content.NodeProperty;
42 import org.apache.slide.content.NodeRevisionDescriptor;
43 import org.apache.slide.content.NodeRevisionDescriptors;
44 import org.apache.slide.content.NodeRevisionNumber;
45 import org.apache.slide.content.RevisionDescriptorNotFoundException;
46 import org.apache.slide.content.NodeProperty.NamespaceCache;
47 import org.apache.slide.lock.Lock;
48 import org.apache.slide.search.RequestedResource;
49 import org.apache.slide.security.AccessDeniedException;
50 import org.apache.slide.security.Security;
51 import org.apache.slide.structure.Structure;
52 import org.apache.slide.util.Configuration;
53 import org.apache.slide.util.XMLValue;
54 import org.apache.slide.webdav.WebdavServletConfig;
55 import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
56 import org.apache.slide.webdav.util.resourcekind.ResourceKind;
57 import org.jdom.CDATA;
58 import org.jdom.Comment;
59 import org.jdom.Element;
60 import org.jdom.EntityRef;
61 import org.jdom.JDOMException;
62 import org.jdom.Namespace;
63 import org.jdom.ProcessingInstruction;
64 import org.jdom.Text;
65
66
67 /**
68  * This class is used to retrieve the properties of a resource as a
69  * <code>&lt;propstat&gt;</code> element. The main code of this class
70  * has been copied from the <code>PropFindMethod</code>. All methods
71  * providing property information (<code>PropFindMethod</code>,
72  * <code>ReportMethod</code>) should use this class.
73  *
74  * @version $Revision: 1.39.2.1 $
75  *
76  */

77 public class PropertyRetrieverImpl extends AbstractWebdavHelper implements PropertyRetriever, WebdavConstants, DeltavConstants, AclConstants, BindConstants {
78     
79     
80     /**
81      * The Content helper.
82      */

83     protected Content content = null;
84     
85     /**
86      * The Lock helper used to access the locks.
87      */

88     protected Lock lock = null;
89     
90     /**
91      * The Security helper.
92      */

93     protected Security security = null;
94     
95     /**
96      * The Structure helper.
97      */

98     protected Structure structure = null;
99     
100     /**
101      * The PropertyHelper used to access the (computed) properties.
102      */

103     protected PropertyHelper propertyHelper = null;
104     
105     /**
106      * the webdavservlet configuration
107      */

108     protected WebdavServletConfig config = null;
109     /**
110      * Creates a PropertyRetriever from the given parameters.
111      *
112      * @param token the NamespaceAccessToken used to access the helpers.
113      * @param slideToken the SlideToken used to retrieve the NodeRevisionDescriptor(s).
114      */

115     public PropertyRetrieverImpl(NamespaceAccessToken token, SlideToken slideToken, WebdavServletConfig sConf) {
116         
117         super(slideToken, token);
118         this.structure = token.getStructureHelper();
119         this.content = token.getContentHelper();
120         this.security = token.getSecurityHelper();
121         this.lock = token.getLockHelper();
122         this.config = sConf;
123         propertyHelper = PropertyHelper.getPropertyHelper(slideToken, token, sConf);
124     }
125     
126     /** deprecated */
127     // public PropertyRetrieverImpl(NamespaceAccessToken token, SlideToken slideToken) {
128
// super(slideToken, token);
129
// this.structure = token.getStructureHelper();
130
// this.content = token.getContentHelper();
131
// this.security = token.getSecurityHelper();
132
// this.lock = token.getLockHelper();
133
//
134
// propertyHelper = PropertyHelper.getPropertyHelper(slideToken, token, null);
135
// }
136

137     /**
138      * Returns the PropertyHelper used to access the (computed) properties.
139      *
140      * @return the PropertyHelper used to access the (computed) properties.
141      */

142     protected PropertyHelper getPropertyHelper() {
143         return propertyHelper;
144     }
145     
146     
147     /**
148      * Returns the requested properties of the last revision of the resource
149      * identified by the given <code>uri</code> as list of <code>&lt;propstat&gt;</code>
150      * JDOM Elements.
151      *
152      * @param requestedProperties the requested properties.
153      * @param uri the URI of the resource.
154      * @param contextPath a String , the result of HttpRequest.getContextPath()
155      * @param servletPath a String, the result of HttpRequest.getServletPath()
156      * @param extendedAllprop indicates if the <code>DeltaV</code> specific
157      * properties should be included in case
158      * all properties are requested.
159      *
160      * @return the requested properties as list of <code>&lt;propstat&gt;</code>
161      * JDOM Element.
162      *
163      * @throws SlideException
164      * @throws JDOMException if creating the JDOM Element fails.
165      */

166     public List JavaDoc getPropertiesOfObject(RequestedProperties requestedProperties, String JavaDoc uri, String JavaDoc servletContextPath, boolean extendedAllprop) throws SlideException, JDOMException {
167         
168         NodeRevisionDescriptors revisionDescriptors = null;
169         NodeRevisionDescriptor revisionDescriptor = null;
170         
171         //boolean isCollection = false;
172

173         try {
174             revisionDescriptors =
175                 content.retrieve(sToken, uri);
176             
177             try {
178                 
179                 revisionDescriptor = content.retrieve(sToken,
180                                                       revisionDescriptors);
181                 //isCollection = WebdavUtils.isCollection(revisionDescriptor);
182

183                 
184             } catch (RevisionDescriptorNotFoundException e) {
185                 
186                 // The object doesn't have any revision, we create a dummy
187
// NodeRevisionDescriptor object
188
//isCollection = true;
189
revisionDescriptor = new NodeRevisionDescriptor(0);
190                 
191                 if (!Configuration.useBinding(nsaToken.getUri(sToken, uri).getStore())) {
192                     revisionDescriptor.setName(new UriPath(uri).lastSegment());
193                 }
194             }
195             
196         } catch (AccessDeniedException e) {
197             if (revisionDescriptor == null) {
198                 revisionDescriptor = new NodeRevisionDescriptor(0);
199             }
200         }
201         // catch (Exception e) {
202
// // resp.setStatus(getErrorCode(e));
203
// throw new WebdavException(getErrorCode(e)); // abort the TA
204
// }
205

206         return getPropertiesOfObject(requestedProperties, revisionDescriptors, revisionDescriptor, servletContextPath, extendedAllprop);
207     }
208     
209     /**
210      * Returns the requested properties of the resource identified by the given
211      * <code>uri</code> and <code>revisionNumber</code> as list of
212      * <code>&lt;propstat&gt;</code> JDOM Elements.
213      *
214      * @param requestedProperties the requested properties.
215      * @param uri the URI of the resource.
216      * @param revisionNumber the revision number of the requested resource.
217      * @param contextPath a String , the result of HttpRequest.getContextPath()
218      * @param servletPath a String, the result of HttpRequest.getServletPath()
219      * @param extendedAllprop indicates if the <code>DeltaV</code> specific
220      * properties should be included in case
221      * all properties are requested.
222      *
223      * @return the requested properties as list of <code>&lt;propstat&gt;</code>
224      * JDOM Element.
225      *
226      * @throws SlideException
227      * @throws JDOMException if creating the JDOM Element fails.
228      */

229     public List JavaDoc getPropertiesOfObject(RequestedProperties requestedProperties, String JavaDoc uri, NodeRevisionNumber revisionNumber, String JavaDoc servletContextPath, boolean extendedAllprop) throws SlideException, JDOMException {
230         
231         NodeRevisionDescriptors revisionDescriptors = content.retrieve(sToken, uri);
232         NodeRevisionDescriptor revisionDescriptor = content.retrieve(sToken,
233                                                                      revisionDescriptors,
234                                                                      revisionNumber);
235         return getPropertiesOfObject(requestedProperties, revisionDescriptors, revisionDescriptor, servletContextPath, extendedAllprop);
236     }
237     
238     /**
239      * Returns the requested properties of the resource identified by the given
240      * <code>uri</code> and <code>revisionNumber</code> as list of
241      * <code>&lt;propstat&gt;</code> JDOM Elements.
242      *
243      * @param requestedProperties the requested properties.
244      * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
245      * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
246      * @param contextPath a String , the result of HttpRequest.getContextPath()
247      * @param servletPath a String, the result of HttpRequest.getServletPath()
248      * @param extendedAllprop indicates if the <code>DeltaV</code> specific
249      * properties should be included in case
250      * all properties are requested.
251      *
252      * @return the requested properties as list of <code>&lt;propstat&gt;</code>
253      * JDOM Element.
254      *
255      * @throws SlideException
256      * @throws JDOMException if creating the JDOM Element fails.
257      */

258     public List JavaDoc getPropertiesOfObject(RequestedProperties requestedProperties, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String JavaDoc servletContextPath, boolean extendedAllprop) throws SlideException, JDOMException {
259         
260         ComputedPropertyProvider propertyProvider = new ComputedPropertyProvider(nsaToken,
261                                                                                  sToken,
262                                                                                  propertyHelper,
263                                                                                  servletContextPath);
264         return getPropertiesOfObject(requestedProperties,
265                                      new ResourceWithProvidedProperties(revisionDescriptors,
266                                                                         revisionDescriptor,
267                                                                         propertyProvider),
268                                      servletContextPath,
269                                      extendedAllprop);
270         
271     }
272     
273     /**
274      * Returns the requested properties of the <code><requestedResource/code>
275      * as list of <code>&lt;propstat&gt;</code> JDOM Elements.
276      *
277      * @param requestedProperties the requested properties.
278      * @param requestedResource the resource for which to return the properties.
279      * @param contextPath a String , the result of HttpRequest.getContextPath()
280      * @param servletPath a String, the result of HttpRequest.getServletPath()
281      * @param extendedAllprop indicates if the <code>DeltaV</code> specific
282      * properties should be included in case
283      * all properties are requested.
284      *
285      * @return the requested properties as list of <code>&lt;propstat&gt;</code>
286      * JDOM Element.
287      *
288      * @throws SlideException
289      * @throws JDOMException if creating the JDOM Element fails.
290      */

291     public List JavaDoc getPropertiesOfObject(RequestedProperties requestedProperties, RequestedResource requestedResource, String JavaDoc servletContextPath, boolean extendedAllprop) throws SlideException, JDOMException {
292         
293         List JavaDoc elementList = new ArrayList JavaDoc();
294         
295 // String status = new String("HTTP/1.1 " + WebdavStatus.SC_OK + " "
296
// + WebdavStatus.getStatusText
297
// (WebdavStatus.SC_OK));
298

299         if (requestedProperties.isAllProp()) {
300             elementList = getAllPropertiesOfObject(requestedResource, servletContextPath, extendedAllprop);
301         }
302         else {
303             elementList = getRequestedPropertiesOfObject(requestedProperties, requestedResource, servletContextPath);
304         }
305         return elementList;
306     }
307     
308     /**
309      * Returns the requested properties of the <code><requestedResource/code>
310      * as list of <code>&lt;propstat&gt;</code> JDOM Elements.
311      *
312      * @param requestedProperties the requested properties.
313      * @param requestedResource the resource for which to return the properties.
314      * @param contextPath a String , the result of HttpRequest.getContextPath()
315      * @param servletPath a String, the result of HttpRequest.getServletPath()
316      *
317      * @return the requested properties as list of <code>&lt;propstat&gt;</code>
318      * JDOM Element.
319      *
320      * @throws SlideException
321      */

322     protected List JavaDoc getRequestedPropertiesOfObject(RequestedProperties requestedProperties, RequestedResource requestedResource, String JavaDoc servletContextPath) throws SlideException {
323         
324         List JavaDoc elementList = new ArrayList JavaDoc();
325         Iterator JavaDoc propertyIterator = requestedProperties.getRequestedProperties();
326         
327         Element propstat = new Element(E_PROPSTAT, NamespaceCache.DEFAULT_NAMESPACE);
328         Element prop = new Element(E_PROP, NamespaceCache.DEFAULT_NAMESPACE);
329         propstat.addContent(prop);
330         Element propertyElement = null;
331         boolean anyPropertyFound = false;
332         
333         // maps the code of the error (that occurred when retrieving the property)
334
// to the List of RequestedProperty that caused that error
335
Map JavaDoc erroneousPropertiesMap = new HashMap JavaDoc();
336         
337         String JavaDoc status = new String JavaDoc("HTTP/1.1 " + WebdavStatus.SC_OK
338                                        + " " + WebdavStatus.getStatusText
339                                        (WebdavStatus.SC_OK));
340         
341         while (propertyIterator.hasNext()) {
342             
343             RequestedProperty property = (RequestedProperty)propertyIterator.next();
344             NodeProperty currentProperty = null;
345             Integer JavaDoc errorCode = null;
346             try {
347                 currentProperty = requestedResource.getProperty(property.getName(),
348                                                                 property.getNamespace());
349                 if (currentProperty == null) {
350                     errorCode = new Integer JavaDoc(WebdavStatus.SC_NOT_FOUND);
351                 }
352             }
353             catch (AccessDeniedException e) {
354                 errorCode = new Integer JavaDoc(WebdavStatus.SC_FORBIDDEN);
355             }
356             
357             if (errorCode != null) {
358                 List JavaDoc erroneousPropertiesList = (List JavaDoc)erroneousPropertiesMap.get(errorCode);
359                 if (erroneousPropertiesList == null) {
360                     erroneousPropertiesList = new ArrayList JavaDoc();
361                     erroneousPropertiesMap.put(errorCode, erroneousPropertiesList);
362                 }
363                 erroneousPropertiesList.add(new PropertyName(property.getName(), property.getNamespace()));
364             }
365             else {
366                 propertyElement = getPropertyElement(currentProperty, servletContextPath);
367                 if (propertyElement != null) {
368                     anyPropertyFound = true;
369                     prop.addContent(propertyElement);
370                 }
371             }
372         }
373         
374         if (anyPropertyFound) {
375             Element statusElement = new Element(E_STATUS, NamespaceCache.DEFAULT_NAMESPACE);
376             statusElement.setText(status);
377             propstat.addContent(statusElement);
378             elementList.add(propstat);
379         }
380         
381         elementList.addAll(getPropstatForErroneousProperties(erroneousPropertiesMap, servletContextPath));
382         
383         return elementList;
384     }
385     
386     
387     /**
388      * Returns all properties of the <code><requestedResource/code>
389      * as list of <code>&lt;propstat&gt;</code> JDOM Elements.
390      *
391      * @param requestedResource the resource for which to return the properties.
392      * @param contextPath a String , the result of HttpRequest.getContextPath()
393      * @param servletPath a String, the result of HttpRequest.getServletPath()
394      * @param extendedAllprop indicates if the <code>DeltaV</code> specific
395      * properties should be included in case
396      * all properties are requested.
397      *
398      * @return the requested properties as list of <code>&lt;propstat&gt;</code>
399      * JDOM Element.
400      *
401      * @throws SlideException
402      */

403     protected List JavaDoc getAllPropertiesOfObject(RequestedResource requestedResource, String JavaDoc servletContextPath, boolean extendedAllprop) throws SlideException {
404         
405         List JavaDoc elementList = new ArrayList JavaDoc();
406         Element propstat = new Element(E_PROPSTAT, NamespaceCache.DEFAULT_NAMESPACE);
407         elementList.add(propstat);
408         Element prop = new Element(E_PROP, NamespaceCache.DEFAULT_NAMESPACE);
409         propstat.addContent(prop);
410         Element propertyElement = null;
411         
412         // maps the code of the error (that occurred when retrieving the property)
413
// to the List of RequestedProperty that caused that error
414
Map JavaDoc erroneousPropertiesMap = new HashMap JavaDoc();
415         
416         
417         String JavaDoc status = new String JavaDoc("HTTP/1.1 " + WebdavStatus.SC_OK
418                                        + " " + WebdavStatus.getStatusText
419                                        (WebdavStatus.SC_OK));
420         
421         Iterator JavaDoc propertyNameIterator = requestedResource.getAllPropertiesNames();
422         while (propertyNameIterator.hasNext()) {
423             
424             PropertyName currentPropertyName = (PropertyName) propertyNameIterator.next();
425             if (currentPropertyName != null) {
426                 
427                 if ( !extendedAllprop && S_DAV.equals(currentPropertyName.getNamespace()) && (
428                         DeltavConstants.DELTAV_PROPERTY_LIST.contains(currentPropertyName.getName()) ||
429                             BindConstants.BIND_PROPERTY_LIST.contains(currentPropertyName.getName()) ||
430                             AclConstants.ACL_PROPERTY_LIST.contains(currentPropertyName.getName())
431                     )
432                    ) {
433                     // skip properties from specification extensions
434
continue;
435                 }
436                 
437                 NodeProperty currentProperty = null;
438                 Integer JavaDoc errorCode = null;
439                 try {
440                     currentProperty = requestedResource.getProperty(currentPropertyName);
441                     if (currentProperty == null) {
442                         errorCode = new Integer JavaDoc(WebdavStatus.SC_NOT_FOUND);
443                     }
444                 }
445                 catch (AccessDeniedException e) {
446                     errorCode = new Integer JavaDoc(WebdavStatus.SC_FORBIDDEN);
447                 }
448                 
449                 if (errorCode != null) {
450                     List JavaDoc erroneousPropertiesList = (List JavaDoc)erroneousPropertiesMap.get(errorCode);
451                     if (erroneousPropertiesList == null) {
452                         erroneousPropertiesList = new ArrayList JavaDoc();
453                         erroneousPropertiesMap.put(errorCode, erroneousPropertiesList);
454                     }
455                     erroneousPropertiesList.add(currentPropertyName);
456                 }
457                 else {
458                     propertyElement = getPropertyElement(currentProperty, servletContextPath);
459                     if (propertyElement != null) {prop.addContent(propertyElement);}
460                 }
461             }
462         }
463         
464         
465         Element statusElement = new Element(E_STATUS, NamespaceCache.DEFAULT_NAMESPACE);
466         statusElement.setText(status);
467         propstat.addContent(statusElement);
468         
469         elementList.addAll(getPropstatForErroneousProperties(erroneousPropertiesMap, servletContextPath));
470         
471         return elementList;
472     }
473     
474     /**
475      * Returns a list of <code>&lt;propstat&gt;</code> JDOM Elements for the properties
476      * that could not be retrieved due to an error.
477      *
478      * @param erroneousPropertiesMap maps the (Integer) code of the error (that occurred
479      * when retrieving the property) to the List of
480      * PropertyName that caused that error.
481      * @param contextPath a String , the result of HttpRequest.getContextPath()
482      * @param servletPath a String, the result of HttpRequest.getServletPath()
483      *
484      * @return A List of <code>&lt;propstat&gt;</code> JDOM Elements for the erroneous properties.
485      */

486     protected List JavaDoc getPropstatForErroneousProperties(Map JavaDoc erroneousPropertiesMap, String JavaDoc servletContextPath) {
487         
488         List JavaDoc elementList = new ArrayList JavaDoc();
489         Iterator JavaDoc iterator = erroneousPropertiesMap.keySet().iterator();
490         while (iterator.hasNext()) {
491             
492             Integer JavaDoc errorCode = (Integer JavaDoc)iterator.next();
493             List JavaDoc erroneousPropertiesList = (List JavaDoc)erroneousPropertiesMap.get(errorCode);
494             Element propstat = new Element(E_PROPSTAT, NamespaceCache.DEFAULT_NAMESPACE);
495             elementList.add(propstat);
496             Element prop = new Element(E_PROP, NamespaceCache.DEFAULT_NAMESPACE);
497             propstat.addContent(prop);
498             
499             String JavaDoc status = new String JavaDoc("HTTP/1.1 " + errorCode.intValue()
500                                            + " " + WebdavStatus.getStatusText(errorCode.intValue()));
501             
502             Iterator JavaDoc propertyIterator = erroneousPropertiesList.iterator();
503             while (propertyIterator.hasNext()) {
504                 
505                 PropertyName erroneousProperty =
506                     (PropertyName) propertyIterator.next();
507                 Element propertyElement = getPropertyElement(erroneousProperty.getNamespace(),
508                                                              erroneousProperty.getName(),
509                                                              null,
510                                                              servletContextPath);
511                 if (propertyElement != null) {prop.addContent(propertyElement);}
512             }
513             
514             Element statusElement = new Element(E_STATUS, NamespaceCache.DEFAULT_NAMESPACE);
515             statusElement.setText(status);
516             propstat.addContent(statusElement);
517         }
518         
519         return elementList;
520     }
521     
522     
523     
524     /**
525      * Returns the JDOM Element for the given <code>property</code>.
526      *
527      * @param property the property for which to return the Element.
528      * @param contextPath a String , the result of HttpRequest.getContextPath()
529      * @param servletPath a String, the result of HttpRequest.getServletPath()
530      *
531      * @return the JDOM Element for the given <code>property</code>.
532      */

533     private Element getPropertyElement(NodeProperty property, String JavaDoc servletContextPath) {
534         if (property != null) {
535             return getPropertyElement(property.getNamespace(),
536                                       property.getName(),
537                                       property.getValue(),
538                                       servletContextPath);
539         }
540         return null;
541     }
542     
543     /**
544      * Returns the JDOM Element for the given <code>property</code>.
545      *
546      * @param namespaceString the property namespace.
547      * @param propertyName the property Name.
548      * @param propertyValue the property Value.
549      * @param contextPath a String , the result of HttpRequest.getContextPath()
550      * @param servletPath a String, the result of HttpRequest.getServletPath()
551      *
552      * @return the JDOM Element for the given <code>property</code>.
553      */

554     private Element getPropertyElement(String JavaDoc namespaceString,
555                                        String JavaDoc propertyName,
556                                        Object JavaDoc propertyValue,
557                                        String JavaDoc servletContextPath) {
558         Element property = null;
559         Namespace namespace = Namespace.NO_NAMESPACE;
560         Namespace valueDefaultNamespace = null;
561         if (namespaceString != null) {
562             namespace = NamespaceCache.getNamespace(namespaceString);
563             if (NamespaceCache.DEFAULT_URI.equals(namespace.getURI())) {
564                 // use the DAV: as the default namespace
565
// for XML values of DAV: properties
566
valueDefaultNamespace = namespace;
567             }
568         }
569         
570         property = new Element(propertyName, namespace);
571         if ( (propertyValue != null) && (propertyValue.toString().length() > 0)) {
572             if( propertyValue.toString().indexOf('<') >= 0 ) {
573                 try {
574                     XMLValue xmlValue = new XMLValue(propertyValue.toString(), valueDefaultNamespace);
575                     if (AbstractResourceKind.isLiveProperty(propertyName)) {
576                         convertHrefValueToAbsoluteURL (xmlValue, servletContextPath, config);
577                     }
578                     Iterator JavaDoc iterator = xmlValue.iterator();
579                     while (iterator.hasNext()) {
580                         Object JavaDoc o = iterator.next();
581                         if( o instanceof Element )
582                             property.addContent((Element)o);
583                         else if( o instanceof Text )
584                             property.addContent((Text)o);
585                         else if( o instanceof Comment )
586                             property.addContent((Comment)o);
587                         else if( o instanceof ProcessingInstruction )
588                             property.addContent((ProcessingInstruction)o);
589                         else if( o instanceof CDATA )
590                             property.addContent((CDATA)o);
591                         else if( o instanceof EntityRef )
592                             property.addContent((EntityRef)o);
593                     }
594                 }
595                 catch (JDOMException e) {
596                     property.setText(propertyValue.toString());
597                 }
598             }
599             else {
600                 property.setText(propertyValue.toString());
601             }
602         }
603         return property;
604     }
605     
606     
607     
608     
609     /**
610      * If the given <code>xmlValue</code> contains <code>&lt;href&gt;</code> elements,
611      * the relative URI is converted to an absolute one.
612      *
613      * @param xmlValue the XMLValue that might contain <code>&lt;href&gt;</code>
614      * values to convert.
615      * @param contextPath a String , the result of HttpRequest.getContextPath()
616      * @param servletPath a String, the result of HttpRequest.getServletPath()
617      */

618     protected static void convertHrefValueToAbsoluteURL (XMLValue xmlValue,
619                                                          String JavaDoc servletContextPath,
620                                                          WebdavServletConfig config) {
621         if (xmlValue != null) {
622             Iterator JavaDoc iterator = xmlValue.iterator();
623             Element element = null;
624             while (iterator.hasNext()) {
625                 Object JavaDoc o = iterator.next();
626                 if( o instanceof Element ) {
627                     element = (Element)o;
628                     convertHrefValueToAbsoluteURL(element, servletContextPath, config);
629                 }
630             }
631         }
632     }
633     
634     private static void convertHrefValueToAbsoluteURL (Element element,
635                                                        String JavaDoc servletContextPath,
636                                                        WebdavServletConfig config) {
637         if (element.getChildren().size() > 0) {
638             Iterator JavaDoc i = element.getChildren().iterator();
639             while (i.hasNext()) {
640                 Element child = (Element)i.next();
641                 // hrefs for owner and active locks have to be left untouched (issue 32436)
642
if (!(element.getName().equals("activelock") && child.getName().equals("owner"))) {
643                     convertHrefValueToAbsoluteURL(child, servletContextPath, config);
644                 }
645             }
646         }
647         if ( E_HREF.equals(element.getName()) && (element.getText() != null) ) {
648             if ( !PropertyHelper.isAbsoluteURL(servletContextPath, element.getText()) ) {
649                 
650                 element.setText(WebdavUtils.getAbsolutePath (element.getText(),
651                         servletContextPath, config));
652             }
653         }
654     }
655     
656     /**
657      * Discover what properties exist or are supported by a resource.
658      * @param resourcePath a String
659      * @param liveOnly only live properties
660      * @return a RequestedProperties
661      * @throws SlideException
662      */

663     public RequestedProperties getAllPropertyNames(String JavaDoc resourcePath, boolean liveOnly) throws SlideException {
664         NodeRevisionDescriptor nrd =
665             content.retrieve(sToken, content.retrieve(sToken, resourcePath));
666         ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, resourcePath, nrd);
667         RequestedPropertiesImpl result = (RequestedPropertiesImpl)getAllPropertyNames(resourceKind);
668         
669         if (!liveOnly) {
670             // add this resource's dead properties
671
Enumeration JavaDoc props = nrd.enumerateProperties();
672             while (props.hasMoreElements()) {
673                 NodeProperty np = (NodeProperty)props.nextElement();
674                 if (!result.contains(np)) {
675                     result.addProperty(new RequestedPropertyImpl(np.getName(), np.getNamespace()));
676                 }
677             }
678         }
679         return result;
680     }
681     
682     /**
683      * Discover what properties are supported by the specified resourcetype.
684      *
685      * @param resourceKind a ResourceKind
686      *
687      * @return a RequestedProperties
688      *
689      * @throws SlideException
690      *
691      */

692     public RequestedProperties getAllPropertyNames(ResourceKind resourceKind) throws SlideException {
693         RequestedPropertiesImpl result = new RequestedPropertiesImpl();
694         Iterator JavaDoc liveprops = resourceKind.getSupportedLiveProperties().iterator();
695         while (liveprops.hasNext()) {
696             result.addProperty(new RequestedPropertyImpl((String JavaDoc)liveprops.next(), DNSP.getURI()));
697         }
698         return result;
699     }
700     
701 }
702
703
704
Popular Tags