/*
* The contents of this file are subject to the
* Mozilla Public License Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights and
* limitations under the License.
*
* The Initial Developer of the Original Code is Simulacra Media Ltd.
* Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
*
* All Rights Reserved.
*
* Contributor(s):
*/
package org.openharmonise.webdav.client.methods.bind;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.openharmonise.commons.xml.*;
import org.openharmonise.commons.xml.namespace.*;
import org.openharmonise.webdav.client.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
/**
* Unbind method.
*
* @author Matthew Large
* @version $Revision: 1.1 $
*
*/
public class Unbind extends AbstractWebDAVMethod {
/**
* Method name.
*/
public static String METHOD_NAME = "UNBIND";
/**
* Unbind segment.
*/
private String m_sUnbindSegment = "";
/**
* Construcs a new unbind method.
*
* @param sURL URL for request
*/
public Unbind(String sURL) {
super(METHOD_NAME, null);
String sUnbindCollection = sURL.substring(0, sURL.lastIndexOf("/"));
super.setURL( sUnbindCollection );
m_sUnbindSegment = sURL.substring(sURL.lastIndexOf("/")+1);
}
public byte[] getData() {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document xmlDoc = null;
try {
xmlDoc = factory.newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Element elBind = xmlDoc.createElementNS( Bind.WEBDAV_NAMESPACE ,"unbind");
xmlDoc.appendChild(elBind);
Element elSEG = xmlDoc.createElementNS( Bind.WEBDAV_NAMESPACE, "segment");
Text txt = xmlDoc.createTextNode(this.m_sUnbindSegment);
elSEG.appendChild(txt);
elBind.appendChild(elSEG);
XMLPrettyPrint printer = new XMLPrettyPrint();
printer.setNamespaceAware(true);
String sXML = null;
try {
sXML = printer.printNode(xmlDoc.getDocumentElement());
} catch (NamespaceClashException e1) {
e1.printStackTrace();
}
return sXML.getBytes();
}
}
|