KickJava   Java API By Example, From Geeks To Geeks.

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


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

21
22 package org.apache.slide.webdav.util;
23
24 import java.util.Collection JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 import org.apache.slide.content.NodeProperty.NamespaceCache;
29
30 public class PropertySearchSetProperty {
31     
32     private static HashMap JavaDoc propertyMap = null;
33     
34     private String JavaDoc property = null;
35     
36     private String JavaDoc description = null;
37     
38     private String JavaDoc namespace = null;
39     
40     /**
41      * Returns an iterator over the principal-search-property-set.
42      *
43      * @return iterator over the principal-search-property-set
44      */

45     public static Iterator JavaDoc getPropertySetIterator(){
46         if (propertyMap == null) {
47             loadProperties();
48         }
49         Collection JavaDoc values = propertyMap.values();
50         return values.iterator();
51     }
52     
53     private PropertySearchSetProperty (String JavaDoc prop, String JavaDoc namesp, String JavaDoc desc) {
54         property = prop;
55         description = desc;
56         namespace = namesp;
57     }
58     
59     /** loads the principal-search-properties-set
60      */

61     private static void loadProperties () {
62         String JavaDoc propSet = AclConstants.C_PRINCIPAL_SEARCH_PROPERTY_SET;
63         int index = 0;
64         int doubleIndex = 0;
65         int trippleIndex = 0;
66         String JavaDoc currentProp = null;
67         String JavaDoc currentTripple = null;
68         String JavaDoc currentDesc = null;
69         String JavaDoc namespace = null;
70         propertyMap = new HashMap JavaDoc();
71         int len = AclConstants.C_PRINCIPAL_SEARCH_PROPERTY_SET.length();
72         while ((index != -1) && (index != (len-1))) {
73             index = propSet.indexOf(AclConstants.C_SEARCH_PROPERTY_SET_SEPERATOR);
74             if (index == -1) {
75                 currentTripple = propSet;
76             } else {
77                 currentTripple = propSet.substring(0, index);
78                 propSet = propSet.substring(index+1);
79             }
80             
81             if ((len > 0) && (!(propSet.equals(AclConstants.C_SEARCH_PROPERTY_SET_SEPERATOR)))) {
82                 trippleIndex = currentTripple.indexOf(",");
83                 if (trippleIndex == -1) {
84                     currentProp = currentTripple;
85                     namespace = NamespaceCache.DEFAULT_URI;
86                     currentDesc = "";
87                 }else {
88                     String JavaDoc currentDouble = currentTripple.substring(trippleIndex+1);
89                     currentProp = currentTripple.substring(0,trippleIndex);
90                     doubleIndex = currentDouble.indexOf(",");
91                     if (doubleIndex == -1) {
92                         namespace = currentDouble;
93                         currentDesc = "";
94                     }else {
95                         namespace = currentDouble.substring(0,doubleIndex);
96                         currentDesc = currentDouble.substring(doubleIndex+1);
97                     }
98                 }
99                 String JavaDoc key = new String JavaDoc(currentProp + namespace);
100                 propertyMap.put(key,(new PropertySearchSetProperty(currentProp,namespace,currentDesc)));
101                 len = propSet.length();
102             }
103         }
104     }
105     
106     /** Verifies if the property is in the search-property-set
107      *
108      * @return true if property is found, false else
109      */

110     public static boolean inSearchPropertySet(String JavaDoc property, String JavaDoc namespace) {
111         if (propertyMap == null) {
112             loadProperties();
113         }
114         String JavaDoc space;
115         if (namespace == null) {
116             space = NamespaceCache.DEFAULT_URI;
117         } else {
118             space = namespace;
119         }
120         return propertyMap.containsKey(property + space);
121     }
122     
123     /** returns the property name of this property
124      *
125      * @return property name
126      */

127     public String JavaDoc getPropertyName() {
128         return property;
129     }
130
131     /** returns the namespace of this property
132      *
133      * @return property namspace
134      */

135     public String JavaDoc getNamespace() {
136         return namespace;
137     }
138     
139     /** returns the description of this property
140      *
141      * @return property description
142      */

143     public String JavaDoc getDescription () {
144         return description;
145     }
146 }
147
148
Popular Tags