001: /*
002: * (C) Copyright Simulacra Media Ltd, 2004. All rights reserved.
003: *
004: * The program is provided "AS IS" without any warranty express or
005: * implied, including the warranty of non-infringement and the implied
006: * warranties of merchantibility and fitness for a particular purpose.
007: * Simulacra Media Ltd will not be liable for any damages suffered by you as a result
008: * of using the Program. In no event will Simulacra Media Ltd be liable for any
009: * special, indirect or consequential damages or lost profits even if
010: * Simulacra Media Ltd has been advised of the possibility of their occurrence.
011: * Simulacra Media Ltd will not be liable for any third party claims against you.
012: */
013:
014: package com.ibm.webdav.basicsearch;
015:
016: import com.ibm.webdav.*;
017:
018: import java.util.*;
019: import java.util.logging.*;
020: import java.util.logging.Level;
021:
022: import javax.xml.parsers.*;
023:
024: import org.w3c.dom.*;
025:
026: /**
027: * BasicSearchSchema implements <code>SearchSchema</code> for the
028: * DASL basic search format.
029: *
030: * @author Michael Bell
031: * @version $Revision: 1.1 $
032: *
033: */
034: public class BasicSearchSchema implements SearchSchema {
035: public static final String TAG_SCHEMA = "D:basicsearchschema";
036: public static final String TAG_PROPDESC = "D:propdesc";
037: public static final String TAG_ANY_OTHER_PROP = "D:any-other-property";
038: public static final String TAG_PROP = "D:prop";
039: public static final String TAG_DATATYPE = "D:datatype";
040: public static final String TAG_SEARCHABLE = "D:searchable";
041: public static final String TAG_SELECTABLE = "D:selectable";
042: public static final String TAG_SORTABLE = "D:sortable";
043: public static final String TAG_OPDESC = "D:opdesc";
044: public static final String TAG_OPERAND_PROP = "D:operand-property";
045: public static final String TAG_OPERAND_LIT = "D:operand-literal";
046: public static final String TAG_PROPERTIES = "D:properties";
047: public static final String TAG_OPERATORS = "D:operators";
048: private static final String DAV_NAMESPACE = "DAV:";
049: private Hashtable m_propdescs = new Hashtable();
050: private Hashtable m_operators = new Hashtable();
051: protected Document m_document = null;
052:
053: private static final Logger m_logger = Logger
054: .getLogger(BasicSearchSchema.class.getName());
055:
056: public BasicSearchSchema() {
057: try {
058: m_document = DocumentBuilderFactory.newInstance()
059: .newDocumentBuilder().newDocument();
060: } catch (Exception e) {
061: m_logger.log(Level.WARNING, e.getMessage(), e);
062: }
063: }
064:
065: public void addAnyOtherPropertyDescription(boolean bSearchable,
066: boolean bSelectable, boolean bSortable) throws Exception {
067: Element el = m_document.createElementNS(
068: BasicSearchSchema.DAV_NAMESPACE,
069: BasicSearchSchema.TAG_ANY_OTHER_PROP);
070: addPropertyDescription(el, null, bSearchable, bSelectable,
071: bSortable);
072: }
073:
074: public void addPropertyDescription(Element propertyEl,
075: Element datatypeDef, boolean bSearchable,
076: boolean bSelectable, boolean bSortable) throws Exception {
077: String sPropname = propertyEl.getTagName();
078:
079: Element propdescEl = m_document.createElementNS(DAV_NAMESPACE,
080: BasicSearchSchema.TAG_PROPDESC);
081: Element propEl = m_document.createElementNS(DAV_NAMESPACE,
082: BasicSearchSchema.TAG_PROP);
083:
084: propEl.appendChild(m_document.importNode(propertyEl, true));
085: propdescEl.appendChild(propEl);
086:
087: if (datatypeDef != null) {
088: Element datatypeEl = m_document.createElementNS(
089: BasicSearchSchema.DAV_NAMESPACE,
090: BasicSearchSchema.TAG_DATATYPE);
091:
092: datatypeEl.appendChild(m_document.importNode(datatypeDef,
093: true));
094: propdescEl.appendChild(datatypeEl);
095: }
096:
097: if (bSearchable == true) {
098: Element searchableEl = m_document.createElementNS(
099: BasicSearchSchema.DAV_NAMESPACE,
100: BasicSearchSchema.TAG_SEARCHABLE);
101: propdescEl.appendChild(searchableEl);
102: }
103:
104: if (bSelectable == true) {
105: Element selectableEl = m_document.createElementNS(
106: BasicSearchSchema.DAV_NAMESPACE,
107: BasicSearchSchema.TAG_SELECTABLE);
108: propdescEl.appendChild(selectableEl);
109: }
110:
111: if (bSortable == true) {
112: Element sortableEl = m_document.createElementNS(
113: BasicSearchSchema.DAV_NAMESPACE,
114: BasicSearchSchema.TAG_SORTABLE);
115: propdescEl.appendChild(sortableEl);
116: }
117:
118: m_propdescs.put(sPropname, propdescEl);
119: }
120:
121: public void addOperator(Element OpEl, boolean bIncludeLiteral)
122: throws Exception {
123: String sOpName = OpEl.getTagName();
124: Element opdescEl = m_document.createElementNS(
125: BasicSearchSchema.DAV_NAMESPACE,
126: BasicSearchSchema.TAG_OPDESC);
127: opdescEl.appendChild(m_document.importNode(OpEl, true));
128:
129: Element operandPropEl = m_document.createElementNS(
130: BasicSearchSchema.DAV_NAMESPACE,
131: BasicSearchSchema.TAG_OPERAND_PROP);
132: opdescEl.appendChild(operandPropEl);
133:
134: if (bIncludeLiteral == true) {
135: Element operandLitEl = m_document.createElementNS(
136: BasicSearchSchema.DAV_NAMESPACE,
137: BasicSearchSchema.TAG_OPERAND_LIT);
138: opdescEl.appendChild(operandLitEl);
139: }
140:
141: m_operators.put(sOpName, opdescEl);
142: }
143:
144: public Element asXML() {
145: Element schemaEl = m_document.createElementNS(
146: BasicSearchSchema.DAV_NAMESPACE, TAG_SCHEMA);
147: Element propertiesEl = m_document.createElementNS(
148: BasicSearchSchema.DAV_NAMESPACE,
149: BasicSearchSchema.TAG_PROPERTIES);
150:
151: for (Iterator i = m_propdescs.values().iterator(); i.hasNext();) {
152: Element tempEl = (Element) i.next();
153: //if(tempEl.getOwnerDocument().equals(this.m_document)
154: propertiesEl.appendChild(tempEl);
155: }
156:
157: schemaEl.appendChild(propertiesEl);
158:
159: Element operatorsEl = m_document.createElementNS(
160: BasicSearchSchema.DAV_NAMESPACE,
161: BasicSearchSchema.TAG_OPERATORS);
162:
163: for (Iterator i = m_operators.values().iterator(); i.hasNext();) {
164: operatorsEl.appendChild((Element) i.next());
165: }
166:
167: schemaEl.appendChild(operatorsEl);
168:
169: return schemaEl;
170: }
171: }
|