KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > dav > server > property > ranges > DAVRelativeObjectRange


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19
20 package org.openharmonise.dav.server.property.ranges;
21
22 import java.util.*;
23
24 import org.openharmonise.commons.dsi.*;
25 import org.openharmonise.commons.xml.*;
26 import org.openharmonise.commons.xml.namespace.*;
27 import org.openharmonise.dav.server.managers.*;
28 import org.openharmonise.dav.server.utils.*;
29 import org.openharmonise.rm.resources.*;
30 import org.openharmonise.rm.resources.metadata.properties.ranges.*;
31 import org.w3c.dom.*;
32
33 import com.ibm.webdav.*;
34
35 /**
36  * A subclass of <code>DAVRange</code> which handles
37  * relative object property ranges, i.e. for properties whose property
38  * instance values are the set of resources defined by a path relative
39  * to the object to which the metadata is attributed.
40  *
41  * @author Michael Bell
42  * @version $Revision: 1.2 $
43  * @since February 13, 2004
44  */

45 public class DAVRelativeObjectRange extends DAVRange {
46
47     /**
48      * @param dsi
49      */

50     public DAVRelativeObjectRange(AbstractDataStoreInterface dsi) {
51         super(dsi, new RelativeChildObjectRange());
52     }
53
54     /**
55      * @param dsi
56      * @param range
57      */

58     public DAVRelativeObjectRange(
59         AbstractDataStoreInterface dsi,
60         Range range) {
61         super(dsi, range);
62     }
63
64     /**
65      * @param dsi
66      * @param range
67      * @param davPropEl
68      * @throws WebDAVException
69      */

70     public DAVRelativeObjectRange(
71         AbstractDataStoreInterface dsi,
72         Element davPropEl)
73         throws WebDAVException {
74         super(dsi, new RelativeChildObjectRange(), davPropEl);
75     }
76
77     
78     /* (non-Javadoc)
79      * @see org.openharmonise.dav.server.property.ranges.DAVRange#addRangeDetails(org.w3c.dom.Element, org.openharmonise.rm.resources.metadata.properties.ranges.Range, org.w3c.dom.Document)
80      */

81     protected void addRangeDetails(Element rangeEl, Range range, Document doc)
82         throws WebDAVException {
83
84         Element resourceTypeEl =
85             doc.createElementNS(
86                 NamespaceType.DAV.getURI(),
87                 HarmonisePropertiesManager.TAG_RESOURCETYPE);
88         resourceTypeEl.setPrefix(NamespaceType.DAV.getPrefix());
89
90         String JavaDoc sResourceType = HarmoniseNameResolver.RESOURCE_TYPE_RESOURCE;
91
92         Element valEl =
93             doc.createElementNS(NamespaceType.DAV.getURI(), sResourceType);
94         valEl.setPrefix(NamespaceType.DAV.getPrefix());
95         resourceTypeEl.appendChild(valEl);
96         rangeEl.appendChild(resourceTypeEl);
97
98         String JavaDoc sPathRestiction =
99             ((RelativeChildObjectRange) range).getPathRestriction();
100
101         Element hrefEl =
102             doc.createElementNS(
103                 NamespaceType.DAV.getURI(),
104                 HarmonisePropertiesManager.TAG_HREF);
105         hrefEl.setPrefix(NamespaceType.DAV.getPrefix());
106         hrefEl.appendChild(doc.createTextNode(sPathRestiction));
107         rangeEl.appendChild(hrefEl);
108
109     }
110
111     /* (non-Javadoc)
112      * @see org.openharmonise.dav.server.property.ranges.DAVRange#populate(org.w3c.dom.Element)
113      */

114     public void populate(Element propEl) throws WebDAVException {
115
116         //get resource type
117
String JavaDoc sResourceType = null;
118
119         Element resourceEl =
120             XMLUtils.getFirstNamedChild(
121                 propEl,
122                 HarmonisePropertiesManager.TAG_RESOURCETYPE);
123
124         if (resourceEl != null) {
125             Element resourceTypeEl = XMLUtils.getFirstElementChild(resourceEl);
126             sResourceType = resourceTypeEl.getLocalName();
127         }
128
129         //deal with hrefs
130
NodeList hrefNodes =
131             propEl.getElementsByTagNameNS(
132                 NamespaceType.DAV.getURI(),
133                 HarmonisePropertiesManager.TAG_HREF);
134
135         List relPaths = new ArrayList();
136         AbstractParentObject parent = null;
137
138         String JavaDoc sParentClassName = null;
139         for (int i = 0; i < hrefNodes.getLength(); i++) {
140             Element hrefEl = (Element) hrefNodes.item(i);
141
142             String JavaDoc hrefVal = hrefEl.getChildNodes().item(0).getNodeValue();
143
144             if (hrefVal != null && hrefVal.length() > 0) {
145
146                 relPaths.add(hrefVal);
147             }
148
149         }
150
151         ((RelativeChildObjectRange) m_range).setPathRestriction(
152             (String JavaDoc) relPaths.get(0));
153
154     }
155
156 }
157
Popular Tags