1 package com.ibm.webdav; 2 3 15 import java.net.*; 16 import java.util.*; 17 18 import org.w3c.dom.*; 19 20 import com.ibm.webdav.impl.*; 21 22 23 28 public class Collection extends Resource { 29 30 31 public static final String shallow = "0"; 32 33 public static final String deep = "infinity"; 34 35 36 37 public static final String thisResource = "0"; 38 40 public static final String immediateMembers = "1"; 41 43 public static final String allMembers = "infinity"; 44 45 private Vector members = null; 47 public Collection() { 48 super(); 49 } 50 60 public Collection(String url) throws WebDAVException { 61 try { 62 initialize(new URL(url), null); 63 } catch (java.io.IOException exc) { 64 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Bad URL"); 65 } 66 } 67 80 public Collection(String url, TargetSelector targetSelector) throws WebDAVException { 81 try { 82 initialize(new URL(url), targetSelector); 83 } catch (java.io.IOException exc) { 84 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Bad URL"); 85 } 86 } 87 97 public Collection(String protocol, String host, int port, String file) throws WebDAVException { 98 try { 99 initialize(new URL(protocol, host, port, file), null); 100 } catch (java.io.IOException exc) { 101 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Bad URL"); 102 } 103 } 104 114 public Collection(String protocol, String host, String file) throws WebDAVException { 115 try { 116 initialize(new URL(protocol, host, file), null); 117 } catch (java.io.IOException exc) { 118 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Bad URL"); 119 } 120 } 121 133 public Collection(URL url) throws WebDAVException { 134 try { 135 initialize(url, null); 136 } catch (java.io.IOException exc) { 137 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Bad URL"); 138 } 139 } 140 153 public Collection(URL url, TargetSelector targetSelector) throws WebDAVException { 154 try { 155 initialize(url, targetSelector); 156 } catch (java.io.IOException exc) { 157 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Bad URL"); 158 } 159 } 160 174 public Collection(URL context, String spec) throws WebDAVException { 175 try { 176 initialize(new URL(context, spec), null); 177 } catch (java.io.IOException exc) { 178 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Bad URL"); 179 } 180 } 181 184 public void baseline() throws WebDAVException { 185 } 186 195 public MultiStatus copy(String destinationURL) throws WebDAVException { 196 return copy(destinationURL, true, null, Collection.deep); 197 } 198 215 public MultiStatus copy(String destinationURL, boolean overwrite, Vector propertiesToCopy) throws WebDAVException { 216 return copy(destinationURL, overwrite, propertiesToCopy, Collection.deep); 217 } 218 240 public MultiStatus copy(String destinationURL, boolean overwrite, Vector propertiesToCopy, String depth) throws WebDAVException { 241 flushCaches(); 242 return ((IRCollection)impl).copy(context, destinationURL, overwrite, propertiesToCopy, depth); 243 } 244 249 public void createCollection() throws WebDAVException { 250 createCollection((Document) null); 251 } 252 264 public MultiStatus createCollection(Document contents) throws WebDAVException { 265 MultiStatus result = null; 266 result = ((IRCollection)impl).createCollection(context, contents); 267 return result; 268 } 269 277 public Collection createSubCollection(String collectionName) throws WebDAVException { 278 Collection subCollection = null; 279 try { 280 subCollection = new Collection(getURL().toString() + collectionName); 281 } catch (WebDAVException exc) { 282 throw exc; 283 } 284 subCollection.getRequestContext().precondition(getRequestContext().precondition()); 285 subCollection.getRequestContext().authorization(getRequestContext().authorization()); 286 subCollection.createCollection(); 287 return subCollection; 288 } 289 293 public void flushCaches() throws WebDAVException { 294 super.flushCaches(); 295 members = null; 296 } 297 302 public Vector getMembers() throws WebDAVException { 303 if (members == null) { 304 members = new Vector(); 305 MultiStatus multiStatus = getProperties(Collection.immediateMembers); 306 URL thisURLu = getURL(); 307 String thisURL = thisURLu.toString(); 308 309 Enumeration responses = multiStatus.getResponses(); 311 while (responses.hasMoreElements()) { 312 PropertyResponse response = ((Response)responses.nextElement()).toPropertyResponse(); 313 String memberName = response.getResource(); 314 URL uu = null; 315 try { 316 uu = new URL( thisURLu, memberName ); 317 } catch (java.net.MalformedURLException exc) { 318 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Malformed URL"); 319 } 320 memberName = uu.toString(); 321 if (!memberName.equals(thisURL)) { 323 Resource resource = null; 324 try { 328 URL urll = new URL(getURL(), response.getResource()); 329 if (response.isOnACollection()) { 330 resource = new Collection(urll); 331 } else { 332 resource = new Resource(urll); 333 } 334 } catch (Exception exc) { 335 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Malformed URL"); 336 } 337 MultiStatus childProperties = new MultiStatus(); 338 childProperties.addResponse(response); 339 CollectionMember member = new CollectionMember(this, resource, childProperties); 340 members.addElement(member); 341 } 342 } 343 } 344 return members; 345 } 346 358 public MultiStatus getProperties(PropertyName names[], String depth) throws WebDAVException { 359 return ((IRCollection)impl).getProperties(context, names, depth); 360 } 361 373 public MultiStatus getProperties(String depth) throws WebDAVException { 374 return ((IRCollection)impl).getProperties(context, depth); 375 } 376 388 public MultiStatus getProperty(PropertyName name, String depth) throws WebDAVException { 389 PropertyName[] names = new PropertyName[1]; 390 names[0] = name; 391 return getProperties(names, depth); 392 } 393 406 public MultiStatus getPropertyNames(String depth) throws WebDAVException { 407 return ((IRCollection)impl).getPropertyNames(context, depth); 408 } 409 411 protected void initialize(URL url, TargetSelector targetSelector) throws WebDAVException { 412 String file = url.getFile(); 413 if (!file.endsWith("/")) { 414 file = file + "/"; 415 } 416 try { 417 this.url = new URL(url, file); 418 impl = ResourceFactory.createCollection(url, targetSelector); 419 } catch (Exception exc) { 420 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Malformed URL"); 421 } 422 } 423 440 public MultiStatus lock(String scope, String type, int timeout, Element owner) throws WebDAVException { 441 return lock(scope, type, timeout, owner, Collection.deep); 442 } 443 464 public MultiStatus lock(String scope, String type, int timeout, Element owner, String depth) throws WebDAVException { 465 return ((IRCollection) impl).lock(context, scope, type, timeout, owner, depth); 466 } 467 } 468 | Popular Tags |