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: package org.openharmonise.webdav.client.methods.dasl;
020:
021: import javax.xml.parsers.DocumentBuilderFactory;
022: import javax.xml.parsers.ParserConfigurationException;
023:
024: import org.openharmonise.commons.xml.*;
025: import org.openharmonise.commons.xml.namespace.*;
026: import org.openharmonise.webdav.client.*;
027: import org.w3c.dom.Document;
028: import org.w3c.dom.Element;
029:
030: /**
031: * Search method.
032: *
033: * @author Matthew Large
034: * @version $Revision: 1.1 $
035: *
036: */
037: public class Search extends AbstractWebDAVMethod {
038:
039: /**
040: * Method name.
041: */
042: public static String METHOD_NAME = "SEARCH";
043:
044: /**
045: * Root element of search XML.
046: */
047: private Element m_elSearch = null;
048:
049: /**
050: * Constructs new search method.
051: *
052: * @param sURL URL for request
053: */
054: public Search(String sURL) {
055: super (METHOD_NAME, sURL);
056: }
057:
058: /**
059: * Sets the search XML.
060: *
061: * @param elSearch Root search element
062: */
063: public void setSearchXML(Element elSearch) {
064: this .m_elSearch = elSearch;
065: }
066:
067: public byte[] getData() {
068:
069: DocumentBuilderFactory factory = DocumentBuilderFactory
070: .newInstance();
071: factory.setNamespaceAware(true);
072: Document xmlDoc = null;
073: try {
074: xmlDoc = factory.newDocumentBuilder().newDocument();
075: } catch (ParserConfigurationException e) {
076: e.printStackTrace();
077: }
078:
079: Element elSearchRequest = xmlDoc.createElementNS(
080: Search.WEBDAV_NAMESPACE, "searchrequest");
081: xmlDoc.appendChild(elSearchRequest);
082:
083: if (this .m_elSearch != null) {
084: elSearchRequest.appendChild(xmlDoc.importNode(
085: this .m_elSearch, true));
086: }
087:
088: XMLPrettyPrint printer = new XMLPrettyPrint();
089: printer.setNamespaceAware(true);
090:
091: String sXML = null;
092: try {
093: sXML = printer.printNode(xmlDoc.getDocumentElement());
094: } catch (NamespaceClashException e1) {
095: e1.printStackTrace();
096: }
097:
098: return sXML.getBytes();
099: }
100:
101: }
|