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.namespace.*;
024: import org.openharmonise.rm.resources.metadata.properties.ranges.*;
025: import org.w3c.dom.*;
026:
027: import com.ibm.webdav.*;
028:
029: /**
030: * A subclass of <code>DAVRange</code> which handles
031: * String property ranges.
032: *
033: * @author Michael Bell
034: * @version $Revision: 1.2 $
035: * @since November 20, 2003
036: */
037: public class DAVStringRange extends DAVRange {
038:
039: /**
040: * @param dsi
041: * @param davPropEl
042: */
043: public DAVStringRange(AbstractDataStoreInterface dsi,
044: Element davPropEl) throws WebDAVException {
045: super (dsi, new StringRange(), davPropEl);
046: }
047:
048: /**
049: * @param dsi
050: */
051: public DAVStringRange(AbstractDataStoreInterface dsi) {
052: super (dsi);
053: }
054:
055: /**
056: * @param dsi
057: * @param range
058: */
059: public DAVStringRange(AbstractDataStoreInterface dsi, Range range) {
060: super (dsi, range);
061: }
062:
063: /**
064: * Adds range details for to the given range element for string ranges.
065: *
066: * @param rangeEl
067: * @param range
068: * @param doc
069: * @throws WebDAVException
070: */
071: protected void addRangeDetails(Element rangeEl, Range range,
072: Document doc) throws WebDAVException {
073:
074: StringRange strRange = (StringRange) range;
075:
076: Element restrEl = doc.createElementNS(NamespaceType.XML_SCHEMA
077: .getURI(), TAG_RESTRICTION);
078: restrEl.setPrefix(NamespaceType.XML_SCHEMA.getPrefix());
079:
080: restrEl.setAttributeNS(NamespaceType.XML_SCHEMA.getURI(),
081: ATTRIB_PREFIXED_BASE, TYPE_STRING);
082:
083: restrEl.setAttribute("xmlns:"
084: + NamespaceType.XML_SCHEMA.getPrefix(),
085: NamespaceType.XML_SCHEMA.getURI());
086:
087: int nMin = strRange.getMinLength();
088: if (nMin >= 0) {
089:
090: Element minEl = doc.createElementNS(
091: NamespaceType.XML_SCHEMA.getURI(), TAG_MINLENGTH);
092: minEl.setPrefix(NamespaceType.XML_SCHEMA.getPrefix());
093:
094: minEl.appendChild(doc.createTextNode(String.valueOf(nMin)));
095:
096: restrEl.appendChild(minEl);
097: }
098:
099: int nMax = strRange.getMaxLength();
100: if (nMax >= 0) {
101:
102: Element maxEl = doc.createElementNS(
103: NamespaceType.XML_SCHEMA.getURI(), TAG_MAXLENGTH);
104: maxEl.setPrefix(NamespaceType.XML_SCHEMA.getPrefix());
105:
106: maxEl.appendChild(doc.createTextNode(String.valueOf(nMax)));
107:
108: restrEl.appendChild(maxEl);
109: }
110:
111: rangeEl.appendChild(restrEl);
112: }
113:
114: /* (non-Javadoc)
115: * @see org.openharmonise.dav.server.property.ranges.DAVRange#populate(org.w3c.dom.Element)
116: */
117: public void populate(Element propEl) throws WebDAVException {
118: StringRange range = (StringRange) m_range;
119:
120: try {
121: NodeList maxNodes = propEl.getElementsByTagNameNS(
122: NamespaceType.XML_SCHEMA.getURI(), TAG_MAXLENGTH);
123:
124: if (maxNodes.getLength() > 0) {
125: String sVal = maxNodes.item(0).getChildNodes().item(0)
126: .getNodeValue();
127: range.setMaxLength(Integer.parseInt(sVal));
128: }
129:
130: NodeList minNodes = propEl.getElementsByTagNameNS(
131: NamespaceType.XML_SCHEMA.getURI(), TAG_MINLENGTH);
132:
133: if (minNodes.getLength() > 0) {
134: String sVal = minNodes.item(0).getChildNodes().item(0)
135: .getNodeValue();
136: range.setMinLength(Integer.parseInt(sVal));
137: }
138: } catch (InvalidRangeRestrictionException e) {
139: throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
140: "Invalid range restriction");
141: }
142: }
143: }
|