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 org.openharmonise.commons.dsi.*;
023: import org.openharmonise.commons.xml.*;
024: import org.openharmonise.commons.xml.namespace.*;
025: import org.openharmonise.dav.server.managers.*;
026: import org.openharmonise.dav.server.utils.*;
027: import org.openharmonise.rm.resources.metadata.properties.*;
028: import org.openharmonise.rm.resources.metadata.properties.ranges.*;
029: import org.openharmonise.rm.resources.workflow.properties.*;
030: import org.openharmonise.rm.resources.workflow.properties.ranges.*;
031: import org.w3c.dom.*;
032:
033: import com.ibm.webdav.*;
034:
035: /**
036: * Factory class to generate the appropriate <code>DAVRange</code> class for the
037: * given Harmonise range or DAV property element.
038: *
039: * @author Michael Bell
040: * @version $Revision: 1.1 $
041: * @since November 20, 2003
042: */
043: public class DAVRangeFactory {
044:
045: /**
046: *
047: */
048: private DAVRangeFactory() {
049: super ();
050:
051: }
052:
053: static public DAVRange getDAVRange(AbstractDataStoreInterface dsi,
054: Range range) {
055: DAVRange davRange = null;
056:
057: if (range instanceof StringRange) {
058: davRange = new DAVStringRange(dsi, range);
059: } else if (range instanceof IntegerRange) {
060: davRange = new DAVIntegerRange(dsi, range);
061: } else if (range instanceof BooleanRange) {
062: davRange = new DAVBooleanRange(dsi, range);
063: } else if (range instanceof AbsoluteChildObjectRange) {
064: davRange = new DAVResourceRange(dsi, range);
065: } else if (range instanceof FloatRange) {
066: davRange = new DAVFloatRange(dsi, range);
067: } else if (range instanceof DateRange) {
068: davRange = new DAVDateRange(dsi, range);
069: } else if (range instanceof URIRange) {
070: davRange = new DAVURIRange(dsi, range);
071: } else if (range instanceof ProfileRange) {
072: davRange = new DAVPropertyRange(dsi, range);
073: } else if (range instanceof RelativeChildObjectRange) {
074: davRange = new DAVRelativeObjectRange(dsi, range);
075: }
076:
077: return davRange;
078: }
079:
080: static public DAVRange getDAVRange(AbstractDataStoreInterface dsi,
081: Property prop, Element davPropEl) throws WebDAVException {
082: DAVRange davRange = null;
083:
084: if (prop instanceof WorkflowProperty) {
085: davRange = new DAVResourceRange(dsi, new WorkflowRange(),
086: davPropEl);
087: } else {
088:
089: NodeList restrNodes = davPropEl.getElementsByTagNameNS(
090: NamespaceType.XML_SCHEMA.getURI(),
091: DAVRange.TAG_RESTRICTION);
092: NodeList resourceTypeNodes = davPropEl
093: .getElementsByTagNameNS(NamespaceType.DAV.getURI(),
094: HarmonisePropertiesManager.TAG_RESOURCETYPE);
095:
096: if (restrNodes.getLength() > 0) {
097: Element restrEl = (Element) restrNodes.item(0);
098:
099: String sBase = restrEl.getAttributeNS(
100: NamespaceType.XML_SCHEMA.getURI(), "base");
101:
102: if (sBase.equals(DAVRange.TYPE_STRING)) {
103: davRange = new DAVStringRange(dsi, davPropEl);
104: } else if (sBase.equals(DAVRange.TYPE_INTEGER)) {
105: davRange = new DAVIntegerRange(dsi, davPropEl);
106: } else if (sBase.equals(DAVRange.TYPE_BOOLEAN)) {
107: davRange = new DAVBooleanRange(dsi, davPropEl);
108: } else if (sBase.equals(DAVRange.TYPE_FLOAT)) {
109: davRange = new DAVFloatRange(dsi, davPropEl);
110: } else if (sBase.equals(DAVRange.TYPE_DATE)) {
111: davRange = new DAVDateRange(dsi, davPropEl);
112: } else if (sBase.equals(DAVRange.TYPE_DATETIME)) {
113: davRange = new DAVDateRange(dsi, davPropEl);
114: } else if (sBase.equals(DAVRange.TYPE_URI)) {
115: davRange = new DAVURIRange(dsi, davPropEl);
116: }
117:
118: } else if (resourceTypeNodes.getLength() > 0) {
119:
120: Element resourceEl = XMLUtils
121: .getFirstElementChild((Element) resourceTypeNodes
122: .item(0));
123: String sLocalName = resourceEl.getLocalName();
124: if (sLocalName
125: .equals(HarmonisePropertiesManager.TAG_PROPERTY_RESOURCE)) {
126: davRange = new DAVPropertyRange(dsi, davPropEl);
127: } else if (sLocalName.equals(DAVRange.TAG_VALUE)
128: || sLocalName
129: .equals(HarmonisePropertiesManager.TAG_RESOURCE)
130: || sLocalName
131: .equals(HarmonisePropertiesManager.TAG_COLLECTION)) {
132:
133: NodeList nl = davPropEl.getElementsByTagNameNS(
134: NamespaceType.DAV.getURI(),
135: HarmonisePropertiesManager.TAG_HREF);
136:
137: //if there's no hrefs then just create a standard davresourcerange
138: if (nl.getLength() > 0) {
139: Element hrefEl = (Element) nl.item(0);
140: String hrefVal = hrefEl.getChildNodes().item(0)
141: .getNodeValue();
142:
143: //if the webdav root marker is in the string we can assume
144: //it's an absolute child range otherwise it's a relative
145: //child object range
146: if (hrefVal
147: .indexOf(HarmoniseNameResolver.WEBDAV_ROOT_MARKER) > 0) {
148: davRange = new DAVResourceRange(dsi,
149: davPropEl);
150: } else {
151: davRange = new DAVRelativeObjectRange(dsi,
152: davPropEl);
153: }
154:
155: } else {
156: davRange = new DAVResourceRange(dsi, davPropEl);
157: }
158:
159: }
160: }
161: }
162:
163: return davRange;
164: }
165:
166: }
|