KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > lib > properties > ResourceTypeProperty


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/properties/ResourceTypeProperty.java,v 1.5.2.1 2004/09/26 14:19:20 luetzkendorf Exp $
3  * $Revision: 1.5.2.1 $
4  * $Date: 2004/09/26 14:19:20 $
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.webdav.lib.properties;
25
26 import org.apache.webdav.lib.BaseProperty;
27 import org.apache.webdav.lib.ResponseEntity;
28 import org.apache.webdav.lib.util.DOMUtils;
29 import org.w3c.dom.Element JavaDoc;
30 import org.w3c.dom.NodeList JavaDoc;
31
32 /**
33  * An interface that describes a standard Resource Type property (as defined by
34  * the WebDAV specification).
35  *
36  */

37 public class ResourceTypeProperty extends BaseProperty {
38
39     private boolean initialized = false;
40     private boolean isCollection = false;
41     private boolean isPrincipal = false;
42
43     // -------------------------------------------------------------- Constants
44

45
46     /**
47      * The property name.
48      */

49     public static final String JavaDoc TAG_NAME = "resourcetype";
50
51     /**
52      * The property collection tag.
53      */

54     public static final String JavaDoc TAG_COLLECTION = "collection";
55     public static final String JavaDoc TAG_PRINCIPAL = "principal";
56
57
58     // ----------------------------------------------------------- Constructors
59

60
61     /**
62      * Default constructor for the property.
63      */

64     public ResourceTypeProperty(ResponseEntity response, Element JavaDoc element) {
65         super(response, element);
66     }
67
68
69     // --------------------------------------------------------- Public Methods
70

71
72     /**
73      * Returns true if the resource is a collection. A collection is indicated
74      * by a response like this:
75      *
76      * <pre>
77      * &lt;D:resourcetype&gt;&lt;D:collection/&gt;&lt;/D:resourcetype&gt;
78      * </pre>
79      */

80     public boolean isCollection() {
81         init();
82         return isCollection;
83     }
84     
85     public boolean isPrincipal() {
86         init();
87         return isPrincipal;
88     }
89
90     private void init()
91     {
92
93         if (initialized)
94             return;
95
96         initialized=true;
97
98         NodeList JavaDoc tmp = element.getChildNodes();
99         for (int i = 0; tmp != null && i < tmp.getLength(); i++ ) {
100             try {
101                 Element JavaDoc child = (Element JavaDoc) tmp.item(i);
102                 if (TAG_COLLECTION.equals(DOMUtils.getElementLocalName(child))
103                      && "DAV:".equals(DOMUtils.getElementNamespaceURI(child)))
104                 {
105                     isCollection=true;
106                 }
107                 if (TAG_PRINCIPAL.equals(DOMUtils.getElementLocalName(child))
108                         && "DAV:".equals(DOMUtils.getElementNamespaceURI(child)))
109                 {
110                     isPrincipal=true;
111                 }
112             } catch (ClassCastException JavaDoc e) {
113             }
114         }
115     }
116
117     /**
118      * This method returns the value of the property.
119      * For this property "COLLECTION" is returned if
120      * this resource is a collection, "" otherwise.
121      *
122      * WARNING: this will change in the future
123      * use isCollection()
124      */

125     public String JavaDoc getPropertyAsString() {
126         init();
127         return isCollection?"COLLECTION":"";
128     }
129 }
130
Popular Tags