001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019:
020: package org.openharmonise.dav.server.property.ranges;
021:
022: import java.util.*;
023:
024: import org.openharmonise.commons.dsi.*;
025: import org.openharmonise.commons.xml.*;
026: import org.openharmonise.commons.xml.namespace.*;
027: import org.openharmonise.dav.server.managers.*;
028: import org.openharmonise.dav.server.utils.*;
029: import org.openharmonise.rm.resources.*;
030: import org.openharmonise.rm.resources.metadata.properties.ranges.*;
031: import org.w3c.dom.*;
032:
033: import com.ibm.webdav.*;
034:
035: /**
036: * A subclass of <code>DAVRange</code> which handles
037: * relative object property ranges, i.e. for properties whose property
038: * instance values are the set of resources defined by a path relative
039: * to the object to which the metadata is attributed.
040: *
041: * @author Michael Bell
042: * @version $Revision: 1.2 $
043: * @since February 13, 2004
044: */
045: public class DAVRelativeObjectRange extends DAVRange {
046:
047: /**
048: * @param dsi
049: */
050: public DAVRelativeObjectRange(AbstractDataStoreInterface dsi) {
051: super (dsi, new RelativeChildObjectRange());
052: }
053:
054: /**
055: * @param dsi
056: * @param range
057: */
058: public DAVRelativeObjectRange(AbstractDataStoreInterface dsi,
059: Range range) {
060: super (dsi, range);
061: }
062:
063: /**
064: * @param dsi
065: * @param range
066: * @param davPropEl
067: * @throws WebDAVException
068: */
069: public DAVRelativeObjectRange(AbstractDataStoreInterface dsi,
070: Element davPropEl) throws WebDAVException {
071: super (dsi, new RelativeChildObjectRange(), davPropEl);
072: }
073:
074: /* (non-Javadoc)
075: * @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)
076: */
077: protected void addRangeDetails(Element rangeEl, Range range,
078: Document doc) throws WebDAVException {
079:
080: Element resourceTypeEl = doc.createElementNS(NamespaceType.DAV
081: .getURI(), HarmonisePropertiesManager.TAG_RESOURCETYPE);
082: resourceTypeEl.setPrefix(NamespaceType.DAV.getPrefix());
083:
084: String sResourceType = HarmoniseNameResolver.RESOURCE_TYPE_RESOURCE;
085:
086: Element valEl = doc.createElementNS(NamespaceType.DAV.getURI(),
087: sResourceType);
088: valEl.setPrefix(NamespaceType.DAV.getPrefix());
089: resourceTypeEl.appendChild(valEl);
090: rangeEl.appendChild(resourceTypeEl);
091:
092: String sPathRestiction = ((RelativeChildObjectRange) range)
093: .getPathRestriction();
094:
095: Element hrefEl = doc.createElementNS(
096: NamespaceType.DAV.getURI(),
097: HarmonisePropertiesManager.TAG_HREF);
098: hrefEl.setPrefix(NamespaceType.DAV.getPrefix());
099: hrefEl.appendChild(doc.createTextNode(sPathRestiction));
100: rangeEl.appendChild(hrefEl);
101:
102: }
103:
104: /* (non-Javadoc)
105: * @see org.openharmonise.dav.server.property.ranges.DAVRange#populate(org.w3c.dom.Element)
106: */
107: public void populate(Element propEl) throws WebDAVException {
108:
109: //get resource type
110: String sResourceType = null;
111:
112: Element resourceEl = XMLUtils.getFirstNamedChild(propEl,
113: HarmonisePropertiesManager.TAG_RESOURCETYPE);
114:
115: if (resourceEl != null) {
116: Element resourceTypeEl = XMLUtils
117: .getFirstElementChild(resourceEl);
118: sResourceType = resourceTypeEl.getLocalName();
119: }
120:
121: //deal with hrefs
122: NodeList hrefNodes = propEl.getElementsByTagNameNS(
123: NamespaceType.DAV.getURI(),
124: HarmonisePropertiesManager.TAG_HREF);
125:
126: List relPaths = new ArrayList();
127: AbstractParentObject parent = null;
128:
129: String sParentClassName = null;
130: for (int i = 0; i < hrefNodes.getLength(); i++) {
131: Element hrefEl = (Element) hrefNodes.item(i);
132:
133: String hrefVal = hrefEl.getChildNodes().item(0)
134: .getNodeValue();
135:
136: if (hrefVal != null && hrefVal.length() > 0) {
137:
138: relPaths.add(hrefVal);
139: }
140:
141: }
142:
143: ((RelativeChildObjectRange) m_range)
144: .setPathRestriction((String) relPaths.get(0));
145:
146: }
147:
148: }
|