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 Bind extends AbstractWebDAVMethod { 40 41 44 public static String METHOD_NAME = "BIND"; 45 46 49 private String m_sBindSourceURI = ""; 50 51 54 private String m_sBindDestinationCollection = ""; 55 56 59 private String m_sBindDestinationSegment = ""; 60 61 64 private String m_sRootElementName = "bind"; 65 66 71 public Bind(String sURL) { 72 this(METHOD_NAME, sURL); 73 } 74 75 81 protected Bind(String sMethod, String sURL) { 82 super(sMethod, null); 83 this.m_sBindSourceURI=sURL; 84 } 85 86 91 protected void setRootElementName(String sRootElementName) { 92 this.m_sRootElementName = sRootElementName; 93 } 94 95 public void setDestination(String sDestination) { 96 m_sBindDestinationCollection = sDestination.substring(0, sDestination.lastIndexOf("/")); 97 super.setURL( m_sBindDestinationCollection ); 98 m_sBindDestinationSegment = sDestination.substring(sDestination.lastIndexOf("/")+1); 99 } 100 101 106 public String getBindDestination() { 107 return m_sBindDestinationCollection + "/" + m_sBindDestinationSegment; 108 } 109 110 public byte[] getData() { 111 112 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 113 factory.setNamespaceAware(true); 114 Document xmlDoc = null; 115 try { 116 xmlDoc = factory.newDocumentBuilder().newDocument(); 117 } catch (ParserConfigurationException e) { 118 e.printStackTrace(); 119 } 120 121 Element elBind = xmlDoc.createElementNS( Bind.WEBDAV_NAMESPACE , m_sRootElementName); 122 xmlDoc.appendChild(elBind); 123 124 Element elHREF = xmlDoc.createElementNS( Bind.WEBDAV_NAMESPACE, "href"); 125 Text txt = xmlDoc.createTextNode(this.m_sBindSourceURI); 126 elHREF.appendChild(txt); 127 elBind.appendChild(elHREF); 128 129 Element elSEG = xmlDoc.createElementNS( Bind.WEBDAV_NAMESPACE, "segment"); 130 txt = xmlDoc.createTextNode(this.m_sBindDestinationSegment); 131 elSEG.appendChild(txt); 132 elBind.appendChild(elSEG); 133 134 135 136 XMLPrettyPrint printer = new XMLPrettyPrint(); 137 printer.setNamespaceAware(true); 138 139 String sXML = null; 140 try { 141 sXML = printer.printNode(xmlDoc.getDocumentElement()); 142 } catch (NamespaceClashException e1) { 143 e1.printStackTrace(); 144 } 145 146 return sXML.getBytes(); 147 } 148 149 } 150 | Popular Tags |