KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > ant > ResourceProperties


1 // vi: set ts=3 sw=3:
2
/*
3  * $Header: /home/cvs/jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/ResourceProperties.java,v 1.3.2.1 2004/08/15 13:01:15 luetzkendorf Exp $
4  * $Revision: 1.3.2.1 $
5  * $Date: 2004/08/15 13:01:15 $
6  * ========================================================================
7  * Copyright 2004 The Apache Software Foundation
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ========================================================================
21  */

22 package org.apache.webdav.ant;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
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 /**
42  * Helper for holding properies of WebDAV resources retrieved by PROPFIND
43  * requests.
44  *
45  */

46 public class ResourceProperties {
47    /** Maps resource URLs to lists of properties. */
48    private Map JavaDoc resourceMap = new HashMap JavaDoc();
49    
50    
51    public void storeProperties(PropFindMethod propFind)
52       throws URIException
53    {
54       // for each content element, check resource type and classify
55
for (Enumeration JavaDoc e = propFind.getAllResponseURLs(); e.hasMoreElements(); )
56       {
57          String JavaDoc href = (String JavaDoc) e.nextElement();
58          URI uri = new URI(propFind.getURI(), href);
59          
60          String JavaDoc key = uri.toString();
61          List JavaDoc properties = (List JavaDoc)this.resourceMap.get(key);
62          if (properties == null) {
63             properties = new ArrayList JavaDoc();
64             this.resourceMap.put(key, properties);
65          }
66          for(Enumeration JavaDoc 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 JavaDoc 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 JavaDoc uri, PropertyName propertyName)
84    {
85       List JavaDoc properties = (List JavaDoc)this.resourceMap.get(uri);
86       if (properties != null) {
87          for(Iterator JavaDoc 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 JavaDoc 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 JavaDoc relative)
110       throws URIException
111    {
112       HttpURL url = Utils.createHttpURL(baseUrl, relative);
113       return getResourceType(url.toString());
114    }
115    
116    public ResourceTypeProperty getResourceType(String JavaDoc uri) {
117       ResourceTypeProperty p =
118             (ResourceTypeProperty)getProperty(uri, Utils.RESOURCETYPE);
119       return p;
120    }
121 }
122
Popular Tags