1 23 24 package org.apache.slide.common; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.apache.slide.content.NodeProperty; 31 import org.jdom.Element; 32 33 34 39 public class RequestedPropertiesImpl implements RequestedProperties { 40 41 protected boolean isAllProp = false; 42 protected List propertyList = new ArrayList (); 43 44 47 public RequestedPropertiesImpl() {} 48 49 58 public RequestedPropertiesImpl (Element propElement) throws PropertyParseException { 59 add(propElement); 60 } 61 62 63 72 public void add(Element propElement) throws PropertyParseException { 73 74 String uri = propElement.getNamespace().getURI(); 75 String prefix = propElement.getNamespace().getPrefix(); 76 String name = propElement.getName (); 77 78 if (name.equals ("allprop") && uri.equals ("DAV:")) { 79 isAllProp = true; 80 } 81 else { 82 Iterator it = propElement.getChildren().iterator(); 83 84 while (it.hasNext()) { 85 Element prop = (Element)it.next(); 86 uri = prop.getNamespace().getURI(); 87 prefix = prop.getNamespace().getPrefix(); 88 name = prop.getName (); 89 if (uri.equals ("DAV:") && name.equals ("property")) { 90 name = prop.getAttributeValue ("name"); 91 if( prop.getAttributeValue ("namespace") != null ) { 92 uri = prop.getAttributeValue ("namespace"); 93 prefix = ""; } 95 } 96 97 addProperty (createRequestedProperty(name, 98 prefix, 99 uri, 100 prop.getContent())); 101 } 102 } 103 } 104 105 120 protected RequestedProperty createRequestedProperty(String name, String namespacePrefix, String namespaceUri, List content) throws PropertyParseException { 121 return new RequestedPropertyImpl(name, namespaceUri); 122 } 123 124 129 public Iterator iterator () { 130 if (isAllProp == true) 131 throw new IllegalStateException (); 132 133 return propertyList.iterator(); 134 } 135 136 137 139 145 public Iterator getRequestedProperties() { 146 if (isAllProp) 147 throw new IllegalStateException (); 148 149 return propertyList.iterator(); 150 } 151 152 158 public boolean isAllProp() { 159 return isAllProp; 160 } 161 162 165 public void setIsAllProp(boolean isAllProp) { 166 this.isAllProp = isAllProp; 167 } 168 169 177 public boolean contains (String name, String namespace) { 178 if (isAllProp) 179 return true; 180 181 RequestedProperty prop = new RequestedPropertyImpl (name, namespace); 182 return propertyList.contains (prop); 183 } 184 185 193 public boolean contains (NodeProperty property) { 194 if (isAllProp) 195 return true; 196 197 RequestedProperty prop = 198 new RequestedPropertyImpl (property.getName(), 199 property.getNamespace()); 200 return propertyList.contains (prop); 201 } 202 203 204 239 244 public String toString () { 245 Iterator it = iterator(); 246 StringBuffer sb = new StringBuffer (); 247 248 while (it.hasNext()) { 249 sb.append (((RequestedProperty)it.next()).toString()); 250 if (it.hasNext()) 251 sb.append (", "); 252 } 253 return sb.toString(); 254 } 255 256 257 262 public void addProperty (RequestedProperty prop) { 263 if (isAllProp == true) 264 throw new IllegalStateException (); 265 266 propertyList.add (prop); 267 } 268 } 269 270 | Popular Tags |