KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/properties/PrincipalCollectionSetProperty.java,v 1.4 2004/08/02 15:45:50 unico Exp $
3  * $Revision: 1.4 $
4  * $Date: 2004/08/02 15:45:50 $
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 java.util.Vector JavaDoc;
27 import org.apache.webdav.lib.BaseProperty;
28 import org.apache.webdav.lib.ResponseEntity;
29 import org.apache.webdav.lib.util.DOMUtils;
30 import org.w3c.dom.Element JavaDoc;
31 import org.w3c.dom.Node JavaDoc;
32 import org.w3c.dom.NodeList JavaDoc;
33
34 /**
35  * This class models the <code>&lt;D:principal-collection-set&gt;</code> property, which is
36  * defined in the WebDAV Access Control Protocol specification.
37  *
38  * @version $Revision: 1.4 $
39  */

40 public class PrincipalCollectionSetProperty extends BaseProperty {
41
42     /**
43      * The property name.
44      */

45     public static final String JavaDoc TAG_NAME = "principal-collection-set";
46
47     // ----------------------------------------------------------- Constructors
48

49     /**
50      * Default constructor for the property.
51      */

52     public PrincipalCollectionSetProperty(ResponseEntity response, Element JavaDoc element) {
53         super(response, element);
54     }
55
56
57     // --------------------------------------------------------- Public Methods
58

59     private String JavaDoc[] hrefs=null;
60
61     private void init()
62     {
63         // check if already initialized
64
if (this.hrefs!=null)
65             return;
66
67         Vector JavaDoc hrefVector = new Vector JavaDoc();
68         NodeList JavaDoc hrefNodes = DOMUtils.getElementsByTagNameNS(element, "href", "DAV:");
69         if (hrefNodes!=null)
70         {
71             for (int i = 0; i < hrefNodes.getLength(); i++)
72             {
73                 Node JavaDoc hrefNode = hrefNodes.item(i);
74                 String JavaDoc href = DOMUtils.getTextValue(hrefNode);
75                 if ((href!=null) && (href.length()>0))
76                     hrefVector.add(href);
77             }
78         }
79
80         this.hrefs=(String JavaDoc[]) hrefVector.toArray(new String JavaDoc[hrefVector.size()]);
81     }
82
83     /**
84      * Returns the Hrefs present in this principal-collection-set property.
85      *
86      * @return String[] A href array or null when there are no href.
87      */

88     public String JavaDoc[] getHrefs()
89     {
90         init();
91         return this.hrefs;
92     }
93
94     public String JavaDoc getPropertyAsString() {
95         String JavaDoc[] hrefs = getHrefs();
96
97         if ((hrefs==null) || (hrefs.length==0))
98             return "";
99
100         StringBuffer JavaDoc tmp = new StringBuffer JavaDoc(hrefs[0]);
101         for (int i=1; i<hrefs.length ; i++) {
102             tmp.append(", ");
103             tmp.append(hrefs[i]);
104         }
105
106         return tmp.toString();
107     }
108
109 }
110
Popular Tags