KickJava   Java API By Example, From Geeks To Geeks.

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


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.AbstractDataStoreInterface;
25 import org.openharmonise.commons.xml.namespace.NamespaceType;
26 import org.openharmonise.dav.server.managers.HarmonisePropertiesManager;
27 import org.openharmonise.dav.server.utils.*;
28 import org.openharmonise.rm.DataAccessException;
29 import org.openharmonise.rm.factory.*;
30 import org.openharmonise.rm.resources.*;
31 import org.openharmonise.rm.resources.metadata.properties.PropertyGroup;
32 import org.openharmonise.rm.resources.metadata.properties.ranges.*;
33 import org.w3c.dom.*;
34
35 import com.ibm.webdav.*;
36
37 /**
38  * A subclass of <code>DAVRange</code> which handles
39  * compound property ranges, i.e. a range which specifies that a
40  * property has values which are property instances of other properties.
41  *
42  * @author Michael Bell
43  * @version $Revision: 1.2 $
44  * @since November 20, 2003
45  */

46 public class DAVPropertyRange extends DAVRange {
47
48     /**
49      * @param dsi
50      */

51     public DAVPropertyRange(AbstractDataStoreInterface dsi) {
52         super(dsi, new ProfileRange());
53     }
54
55     /**
56      * @param dsi
57      * @param range
58      */

59     public DAVPropertyRange(AbstractDataStoreInterface dsi, Range range) {
60         super(dsi, range);
61     }
62
63     /**
64      * @param dsi
65      * @param davPropEl
66      */

67     public DAVPropertyRange(AbstractDataStoreInterface dsi, Element davPropEl)
68         throws WebDAVException {
69         super(dsi, new ProfileRange(), davPropEl);
70
71     }
72
73     
74     /* (non-Javadoc)
75      * @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)
76      */

77     protected void addRangeDetails(Element rangeEl, Range range, Document doc)
78         throws WebDAVException {
79         Element resourceTypeEl =
80             doc.createElementNS(
81                 NamespaceType.DAV.getURI(),
82                 HarmonisePropertiesManager.TAG_RESOURCETYPE);
83         resourceTypeEl.setPrefix(NamespaceType.DAV.getPrefix());
84
85         Element propResEl =
86             doc.createElementNS(
87                 NamespaceType.DAV.getURI(),
88                 HarmonisePropertiesManager.TAG_PROPERTY_RESOURCE);
89         propResEl.setPrefix(NamespaceType.DAV.getPrefix());
90         resourceTypeEl.appendChild(propResEl);
91         rangeEl.appendChild(resourceTypeEl);
92
93         List allowedPropGroups =
94             ((ProfileRange) m_range).getAllowedPropertyParents();
95
96         Iterator iter = allowedPropGroups.iterator();
97         try {
98             while (iter.hasNext()) {
99                 String JavaDoc sPath = (String JavaDoc) iter.next();
100                 if (sPath != null) {
101                     AbstractParentObject parent =
102                         (
103                             AbstractParentObject) HarmoniseObjectFactory
104                                 .instantiateHarmoniseObject(
105                             m_dsi,
106                             PropertyGroup.class.getName(),
107                             sPath);
108                     String JavaDoc sDAVPath = HarmoniseNameResolver.getDAVPath(parent);
109                     if(sDAVPath != null) {
110                         Element hrefEl =
111                             doc.createElementNS(
112                                 NamespaceType.DAV.getURI(),
113                                 HarmonisePropertiesManager.TAG_HREF);
114                         hrefEl.setPrefix(NamespaceType.DAV.getPrefix());
115                         hrefEl.appendChild(doc.createTextNode(sDAVPath));
116                         rangeEl.appendChild(hrefEl);
117                     }
118                     
119                 }
120             }
121
122         } catch (HarmoniseFactoryException e) {
123             throw new WebDAVException(
124                 WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
125                 e.getLocalizedMessage());
126         } catch (NameResolverException e) {
127             throw new WebDAVException(
128                 WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
129                 e.getLocalizedMessage());
130         }
131
132     }
133
134     
135     /* (non-Javadoc)
136      * @see org.openharmonise.dav.server.property.ranges.DAVRange#populate(org.w3c.dom.Element)
137      */

138     public void populate(Element propEl) throws WebDAVException {
139         try {
140             //deal with hrefs
141
NodeList hrefNodes =
142                 propEl.getElementsByTagNameNS(
143                     NamespaceType.DAV.getURI(),
144                     HarmonisePropertiesManager.TAG_HREF);
145
146             List ohPaths = new ArrayList();
147             AbstractParentObject parent = null;
148
149             String JavaDoc sParentClassName = null;
150             for (int i = 0; i < hrefNodes.getLength(); i++) {
151                 Element hrefEl = (Element) hrefNodes.item(i);
152
153                 String JavaDoc hrefVal = hrefEl.getChildNodes().item(0).getNodeValue();
154
155                 if (hrefVal != null && hrefVal.length() > 0) {
156                     AbstractChildObject child =
157                         HarmoniseNameResolver.getObjectFromURL(m_dsi, hrefVal);
158
159                     if ((child instanceof PropertyGroup) == false) {
160                         throw new WebDAVException(
161                             WebDAVStatus.SC_BAD_REQUEST,
162                             "Invalid path - " + hrefVal);
163                     }
164
165                     ohPaths.add(child.getFullPath());
166                     parent = (AbstractParentObject) child;
167
168                     //ensure that we're not mixing parent types in the hrefs
169
if (sParentClassName != null
170                         && parent.getClass().getName().equals(sParentClassName)
171                             == false) {
172                         throw new WebDAVException(
173                             WebDAVStatus.SC_BAD_REQUEST,
174                             "Invalid set of paths");
175                     }
176
177                     sParentClassName = parent.getClass().getName();
178                 }
179
180             }
181
182             ((ProfileRange) m_range).setAllowedPropertyParents(ohPaths);
183         } catch (DataAccessException e) {
184             throw new WebDAVException(
185                 WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
186                 e.getLocalizedMessage());
187         } catch (NameResolverException e) {
188             throw new WebDAVException(
189                 WebDAVStatus.SC_INTERNAL_SERVER_ERROR,
190                 e.getLocalizedMessage());
191         }
192
193     }
194
195 }
196
Popular Tags