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.*;
027:
028: import com.ibm.webdav.*;
029:
030: /**
031: * Class to handle the mapping between Harmonise BooleanRange and how it will be
032: * representing in DAV.
033: *
034: * @author Michael Bell
035: * @version $Revision: 1.2 $
036: * @since November 20, 2003
037: */
038: public class DAVBooleanRange extends DAVRange {
039:
040: private static final String ATTRIB_FALSELABEL = "falseLabel";
041: private static final String ATTRIB_TRUELABEL = "trueLabel";
042:
043: /**
044: * @param dsi
045: */
046: public DAVBooleanRange(AbstractDataStoreInterface dsi) {
047: super (dsi, new BooleanRange());
048: }
049:
050: /**
051: * @param dsi
052: * @param range
053: */
054: public DAVBooleanRange(AbstractDataStoreInterface dsi, Range range) {
055: super (dsi, range);
056: }
057:
058: /**
059: * @param dsi
060: * @param davPropEl
061: */
062: public DAVBooleanRange(AbstractDataStoreInterface dsi,
063: Element davPropEl) throws WebDAVException {
064: super (dsi, new BooleanRange(), davPropEl);
065: }
066:
067: /**
068: * Adds range details for to the given range element for boolean ranges
069: *
070: * @param rangeEl
071: * @param range
072: * @param doc
073: * @throws WebDAVException
074: */
075: protected void addRangeDetails(Element rangeEl, Range range,
076: Document doc) {
077: BooleanRange brange = (BooleanRange) range;
078: Element restrEl = doc.createElementNS(NamespaceType.XML_SCHEMA
079: .getURI(), TAG_RESTRICTION);
080: restrEl.setPrefix(NamespaceType.XML_SCHEMA.getPrefix());
081:
082: restrEl.setAttributeNS(NamespaceType.XML_SCHEMA.getURI(),
083: ATTRIB_PREFIXED_BASE, TYPE_BOOLEAN);
084:
085: restrEl.setAttribute("xmlns:"
086: + NamespaceType.XML_SCHEMA.getPrefix(),
087: NamespaceType.XML_SCHEMA.getURI());
088:
089: Element labelsEl = doc.createElementNS(NamespaceType.OHRM
090: .getURI(), TAG_LABELS);
091:
092: labelsEl.setAttribute(
093: "xmlns:" + NamespaceType.OHRM.getPrefix(),
094: NamespaceType.OHRM.getURI());
095:
096: labelsEl.setPrefix(NamespaceType.OHRM.getPrefix());
097:
098: labelsEl
099: .setAttributeNS(NamespaceType.OHRM.getURI(),
100: NamespaceType.OHRM.getPrefix() + ":"
101: + ATTRIB_TRUELABEL, brange
102: .getTrueLabel());
103: labelsEl.setAttributeNS(NamespaceType.OHRM.getURI(),
104: NamespaceType.OHRM.getPrefix() + ":"
105: + ATTRIB_FALSELABEL, brange.getFalseLabel());
106:
107: restrEl.appendChild(labelsEl);
108:
109: rangeEl.appendChild(restrEl);
110: }
111:
112: /* (non-Javadoc)
113: * @see org.openharmonise.dav.server.property.ranges.DAVRange#populate(org.w3c.dom.Element)
114: */
115: public void populate(Element propEl) throws WebDAVException {
116: BooleanRange range = (BooleanRange) m_range;
117:
118: Element restrEl = XMLUtils.getFirstNamedChild(propEl,
119: TAG_RESTRICTION);
120:
121: String base = restrEl.getAttributeNS(NamespaceType.XML_SCHEMA
122: .getURI(), "base");
123:
124: if (base.equals(restrEl.getPrefix() + ":boolean") == false) {
125: throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
126: "Invalid base type for this range");
127: }
128:
129: Element labelsEl = XMLUtils.getFirstNamedChild(restrEl,
130: TAG_LABELS);
131:
132: if (labelsEl != null) {
133: String sTrueVal = labelsEl.getAttributeNS(
134: NamespaceType.OHRM.getURI(), ATTRIB_TRUELABEL);
135:
136: range.setTrueLabel(sTrueVal);
137: String sFalseVal = labelsEl.getAttributeNS(
138: NamespaceType.OHRM.getURI(), ATTRIB_FALSELABEL);
139:
140: range.setFalseLabel(sFalseVal);
141: }
142:
143: }
144:
145: }
|