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