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.rm.resources.metadata.properties.ranges.*;
026: import org.w3c.dom.Document;
027: import org.w3c.dom.Element;
028:
029: import com.ibm.webdav.WebDAVException;
030:
031: /**
032: * A subclass of <code>DAVRange</code> which handles
033: * float property ranges.
034: *
035: * @author Michael Bell
036: * @version $Revision: 1.2 $
037: * @since November 20, 2003
038: */
039: public class DAVFloatRange extends DAVRange {
040:
041: /**
042: * @param dsi
043: */
044: public DAVFloatRange(AbstractDataStoreInterface dsi) {
045: super (dsi, new FloatRange());
046:
047: }
048:
049: /**
050: * @param dsi
051: * @param range
052: */
053: public DAVFloatRange(AbstractDataStoreInterface dsi, Range range) {
054: super (dsi, range);
055:
056: }
057:
058: /**
059: * @param dsi
060: * @param davPropEl
061: */
062: public DAVFloatRange(AbstractDataStoreInterface dsi,
063: Element davPropEl) throws WebDAVException {
064: super (dsi, new FloatRange(), davPropEl);
065: }
066:
067: /* (non-Javadoc)
068: * @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)
069: */
070: protected void addRangeDetails(Element rangeEl, Range range,
071: Document doc) throws WebDAVException {
072: Element restrEl = doc.createElementNS(NamespaceType.XML_SCHEMA
073: .getURI(), TAG_RESTRICTION);
074: restrEl.setPrefix(NamespaceType.XML_SCHEMA.getPrefix());
075:
076: String sType = null;
077: sType = TYPE_FLOAT;
078:
079: restrEl.setAttributeNS(NamespaceType.XML_SCHEMA.getURI(),
080: ATTRIB_PREFIXED_BASE, sType);
081:
082: restrEl.setAttribute("xmlns:"
083: + NamespaceType.XML_SCHEMA.getPrefix(),
084: NamespaceType.XML_SCHEMA.getURI());
085:
086: FloatRange floatRange = (FloatRange) range;
087:
088: if (floatRange.hasMin() == true) {
089: String sTag = TAG_MININCLUSIVE;
090: if (floatRange.isMinExclusive() == true) {
091: sTag = TAG_MINEXCLUSIVE;
092: }
093:
094: Element minEl = doc.createElementNS(
095: NamespaceType.XML_SCHEMA.getURI(), sTag);
096: minEl.setPrefix(NamespaceType.XML_SCHEMA.getPrefix());
097: minEl.appendChild(doc.createTextNode(String
098: .valueOf(floatRange.getMin())));
099:
100: restrEl.appendChild(minEl);
101: }
102:
103: if (floatRange.hasMax() == true) {
104: String sTag = TAG_MAXINCLUSIVE;
105: if (floatRange.isMaxExclusive() == true) {
106: sTag = TAG_MAXEXCLUSIVE;
107: }
108:
109: Element maxEl = doc.createElementNS(
110: NamespaceType.XML_SCHEMA.getURI(), sTag);
111: maxEl.setPrefix(NamespaceType.XML_SCHEMA.getPrefix());
112: maxEl.appendChild(doc.createTextNode(String
113: .valueOf(floatRange.getMax())));
114: restrEl.appendChild(maxEl);
115: }
116:
117: restrEl.setAttributeNS(NamespaceType.XML_SCHEMA.getURI(),
118: ATTRIB_PREFIXED_BASE, sType);
119:
120: restrEl.setAttribute("xmlns:"
121: + NamespaceType.XML_SCHEMA.getPrefix(),
122: NamespaceType.XML_SCHEMA.getURI());
123:
124: rangeEl.appendChild(restrEl);
125:
126: rangeEl.appendChild(restrEl);
127: }
128:
129: /* (non-Javadoc)
130: * @see org.openharmonise.dav.server.property.ranges.DAVRange#populate(org.w3c.dom.Element)
131: */
132: public void populate(Element propEl) throws WebDAVException {
133: FloatRange range = (FloatRange) m_range;
134:
135: Element restrEl = XMLUtils.getFirstNamedChild(propEl,
136: TAG_RESTRICTION);
137:
138: Element maxEl = XMLUtils.getFirstNamedChild(restrEl,
139: TAG_MAXEXCLUSIVE);
140:
141: if (maxEl != null) {
142: String sVal = maxEl.getChildNodes().item(0).getNodeValue();
143: range.setMax(Float.parseFloat(sVal), true);
144: }
145:
146: maxEl = XMLUtils.getFirstNamedChild(restrEl, TAG_MAXINCLUSIVE);
147:
148: if (maxEl != null) {
149: String sVal = maxEl.getChildNodes().item(0).getNodeValue();
150: range.setMax(Float.parseFloat(sVal), false);
151: }
152:
153: Element minEl = XMLUtils.getFirstNamedChild(restrEl,
154: TAG_MINEXCLUSIVE);
155:
156: if (minEl != null) {
157: String sVal = minEl.getChildNodes().item(0).getNodeValue();
158: range.setMin(Float.parseFloat(sVal), true);
159: }
160:
161: minEl = XMLUtils.getFirstNamedChild(restrEl, TAG_MININCLUSIVE);
162:
163: if (minEl != null) {
164: String sVal = minEl.getChildNodes().item(0).getNodeValue();
165: range.setMin(Float.parseFloat(sVal), false);
166: }
167:
168: }
169:
170: }
|