1 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 39 public class Unbind extends AbstractWebDAVMethod { 40 41 44 public static String METHOD_NAME = "UNBIND"; 45 46 49 private String m_sUnbindSegment = ""; 50 51 56 public Unbind(String sURL) { 57 super(METHOD_NAME, null); 58 String 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 factory = DocumentBuilderFactory.newInstance(); 66 factory.setNamespaceAware(true); 67 Document xmlDoc = null; 68 try { 69 xmlDoc = factory.newDocumentBuilder().newDocument(); 70 } catch (ParserConfigurationException e) { 71 e.printStackTrace(); 72 } 73 74 Element elBind = xmlDoc.createElementNS( Bind.WEBDAV_NAMESPACE ,"unbind"); 75 xmlDoc.appendChild(elBind); 76 77 Element elSEG = xmlDoc.createElementNS( Bind.WEBDAV_NAMESPACE, "segment"); 78 Text 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 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 |