01: /*
02: * The contents of this file are subject to the
03: * Mozilla Public License Version 1.1 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
09: * 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;
22: import javax.xml.parsers.ParserConfigurationException;
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;
28: import org.w3c.dom.Element;
29: import org.w3c.dom.Text;
30:
31: /**
32: * Unbind method.
33: *
34: * @author Matthew Large
35: * @version $Revision: 1.1 $
36: *
37: */
38: public class Unbind extends AbstractWebDAVMethod {
39:
40: /**
41: * Method name.
42: */
43: public static String METHOD_NAME = "UNBIND";
44:
45: /**
46: * Unbind segment.
47: */
48: private String m_sUnbindSegment = "";
49:
50: /**
51: * Construcs a new unbind method.
52: *
53: * @param sURL URL for request
54: */
55: public Unbind(String sURL) {
56: super (METHOD_NAME, null);
57: String sUnbindCollection = sURL.substring(0, sURL
58: .lastIndexOf("/"));
59: super .setURL(sUnbindCollection);
60: m_sUnbindSegment = sURL.substring(sURL.lastIndexOf("/") + 1);
61: }
62:
63: public byte[] getData() {
64:
65: DocumentBuilderFactory factory = DocumentBuilderFactory
66: .newInstance();
67: factory.setNamespaceAware(true);
68: Document xmlDoc = null;
69: try {
70: xmlDoc = factory.newDocumentBuilder().newDocument();
71: } catch (ParserConfigurationException e) {
72: e.printStackTrace();
73: }
74:
75: Element elBind = xmlDoc.createElementNS(Bind.WEBDAV_NAMESPACE,
76: "unbind");
77: xmlDoc.appendChild(elBind);
78:
79: Element elSEG = xmlDoc.createElementNS(Bind.WEBDAV_NAMESPACE,
80: "segment");
81: Text txt = xmlDoc.createTextNode(this .m_sUnbindSegment);
82: elSEG.appendChild(txt);
83: elBind.appendChild(elSEG);
84:
85: XMLPrettyPrint printer = new XMLPrettyPrint();
86: printer.setNamespaceAware(true);
87:
88: String sXML = null;
89: try {
90: sXML = printer.printNode(xmlDoc.getDocumentElement());
91: } catch (NamespaceClashException e1) {
92: e1.printStackTrace();
93: }
94:
95: return sXML.getBytes();
96: }
97:
98: }
|