KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > webdav > client > methods > bind > Unbind


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.bind;
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 import org.w3c.dom.Text JavaDoc;
30
31
32 /**
33  * Unbind method.
34  *
35  * @author Matthew Large
36  * @version $Revision: 1.1 $
37  *
38  */

39 public class Unbind extends AbstractWebDAVMethod {
40
41     /**
42      * Method name.
43      */

44     public static String JavaDoc METHOD_NAME = "UNBIND";
45     
46     /**
47      * Unbind segment.
48      */

49     private String JavaDoc m_sUnbindSegment = "";
50
51     /**
52      * Construcs a new unbind method.
53      *
54      * @param sURL URL for request
55      */

56     public Unbind(String JavaDoc sURL) {
57         super(METHOD_NAME, null);
58         String JavaDoc sUnbindCollection = sURL.substring(0, sURL.lastIndexOf("/"));
59         super.setURL( sUnbindCollection );
60         m_sUnbindSegment = sURL.substring(sURL.lastIndexOf("/")+1);
61     }
62
63     public byte[] getData() {
64         
65         DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
66         factory.setNamespaceAware(true);
67         Document JavaDoc xmlDoc = null;
68         try {
69             xmlDoc = factory.newDocumentBuilder().newDocument();
70         } catch (ParserConfigurationException JavaDoc e) {
71             e.printStackTrace();
72         }
73         
74         Element JavaDoc elBind = xmlDoc.createElementNS( Bind.WEBDAV_NAMESPACE ,"unbind");
75         xmlDoc.appendChild(elBind);
76         
77         Element JavaDoc elSEG = xmlDoc.createElementNS( Bind.WEBDAV_NAMESPACE, "segment");
78         Text JavaDoc txt = xmlDoc.createTextNode(this.m_sUnbindSegment);
79         elSEG.appendChild(txt);
80         elBind.appendChild(elSEG);
81         
82         
83         
84         XMLPrettyPrint printer = new XMLPrettyPrint();
85         printer.setNamespaceAware(true);
86         
87         String JavaDoc sXML = null;
88         try {
89             sXML = printer.printNode(xmlDoc.getDocumentElement());
90         } catch (NamespaceClashException e1) {
91             e1.printStackTrace();
92         }
93         
94         return sXML.getBytes();
95     }
96
97 }
98
Popular Tags