1 22 package org.apache.webdav.ant; 23 24 import java.util.ArrayList ; 25 import java.util.Enumeration ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import org.apache.commons.httpclient.HttpURL; 32 import org.apache.commons.httpclient.URI; 33 import org.apache.commons.httpclient.URIException; 34 35 import org.apache.webdav.lib.Property; 36 import org.apache.webdav.lib.PropertyName; 37 import org.apache.webdav.lib.methods.PropFindMethod; 38 import org.apache.webdav.lib.properties.GetLastModifiedProperty; 39 import org.apache.webdav.lib.properties.ResourceTypeProperty; 40 41 46 public class ResourceProperties { 47 48 private Map resourceMap = new HashMap (); 49 50 51 public void storeProperties(PropFindMethod propFind) 52 throws URIException 53 { 54 for (Enumeration e = propFind.getAllResponseURLs(); e.hasMoreElements(); ) 56 { 57 String href = (String ) e.nextElement(); 58 URI uri = new URI(propFind.getURI(), href); 59 60 String key = uri.toString(); 61 List properties = (List )this.resourceMap.get(key); 62 if (properties == null) { 63 properties = new ArrayList (); 64 this.resourceMap.put(key, properties); 65 } 66 for(Enumeration f = propFind.getResponseProperties(href); 67 f.hasMoreElements();) 68 { 69 properties.add((Property)f.nextElement()); 70 } 71 } 72 } 73 74 public Property getProperty(HttpURL baseUrl, 75 String relative, 76 PropertyName propertyName) 77 throws URIException 78 { 79 HttpURL url = Utils.createHttpURL(baseUrl, relative); 80 return getProperty(url.getURI(), propertyName); 81 } 82 83 public Property getProperty(String uri, PropertyName propertyName) 84 { 85 List properties = (List )this.resourceMap.get(uri); 86 if (properties != null) { 87 for(Iterator i = properties.iterator(); i.hasNext();) { 88 Property p = (Property)i.next(); 89 if (p.getLocalName().equals(propertyName.getLocalName()) && 90 p.getNamespaceURI().equals(propertyName.getNamespaceURI())) 91 { 92 return p; 93 } 94 } 95 } 96 return null; 97 } 98 99 public long getLastModified(String uri) { 100 GetLastModifiedProperty p = 101 (GetLastModifiedProperty)getProperty(uri, Utils.GETLASTMODIFIED); 102 if (p != null) { 103 return p.getDate().getTime(); 104 } else { 105 return 0; 106 } 107 } 108 109 public ResourceTypeProperty getResourceType(HttpURL baseUrl, String relative) 110 throws URIException 111 { 112 HttpURL url = Utils.createHttpURL(baseUrl, relative); 113 return getResourceType(url.toString()); 114 } 115 116 public ResourceTypeProperty getResourceType(String uri) { 117 ResourceTypeProperty p = 118 (ResourceTypeProperty)getProperty(uri, Utils.RESOURCETYPE); 119 return p; 120 } 121 } 122 | Popular Tags |