KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > webdav > client > methods > dasl > Search


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.webdav.client.methods.dasl;
20
21 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
22 import javax.xml.parsers.ParserConfigurationException JavaDoc;
23
24 import org.openharmonise.commons.xml.*;
25 import org.openharmonise.commons.xml.namespace.*;
26 import org.openharmonise.webdav.client.*;
27 import org.w3c.dom.Document JavaDoc;
28 import org.w3c.dom.Element JavaDoc;
29
30
31 /**
32  * Search method.
33  *
34  * @author Matthew Large
35  * @version $Revision: 1.1 $
36  *
37  */

38 public class Search extends AbstractWebDAVMethod {
39
40     /**
41      * Method name.
42      */

43     public static String JavaDoc METHOD_NAME = "SEARCH";
44     
45     /**
46      * Root element of search XML.
47      */

48     private Element JavaDoc m_elSearch = null;
49     
50     /**
51      * Constructs new search method.
52      *
53      * @param sURL URL for request
54      */

55     public Search(String JavaDoc sURL) {
56         super(METHOD_NAME, sURL);
57     }
58     
59     /**
60      * Sets the search XML.
61      *
62      * @param elSearch Root search element
63      */

64     public void setSearchXML(Element JavaDoc elSearch) {
65         this.m_elSearch = elSearch;
66     }
67
68     public byte[] getData() {
69         
70         DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
71         factory.setNamespaceAware(true);
72         Document JavaDoc xmlDoc = null;
73         try {
74             xmlDoc = factory.newDocumentBuilder().newDocument();
75         } catch (ParserConfigurationException JavaDoc e) {
76             e.printStackTrace();
77         }
78         
79         Element JavaDoc elSearchRequest = xmlDoc.createElementNS( Search.WEBDAV_NAMESPACE , "searchrequest");
80         xmlDoc.appendChild(elSearchRequest);
81         
82         if( this.m_elSearch!=null ) {
83             elSearchRequest.appendChild( xmlDoc.importNode(this.m_elSearch, true) );
84         }
85         
86         XMLPrettyPrint printer = new XMLPrettyPrint();
87         printer.setNamespaceAware(true);
88         
89         String JavaDoc sXML = null;
90         try {
91             sXML = printer.printNode(xmlDoc.getDocumentElement());
92         } catch (NamespaceClashException e1) {
93             e1.printStackTrace();
94         }
95         
96         return sXML.getBytes();
97     }
98
99 }
100
Popular Tags