1 19 package org.openharmonise.webdav.client.methods.order; 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 import javax.xml.parsers.DocumentBuilderFactory ; 25 import javax.xml.parsers.ParserConfigurationException ; 26 27 import org.openharmonise.commons.xml.*; 28 import org.openharmonise.commons.xml.namespace.*; 29 import org.openharmonise.webdav.client.*; 30 import org.w3c.dom.Document ; 31 import org.w3c.dom.Element ; 32 import org.w3c.dom.Text ; 33 34 35 42 public class OrderPatch extends AbstractWebDAVMethod { 43 44 47 public static String METHOD_NAME = "ORDERPATCH"; 48 49 52 private ArrayList m_aOrderedPaths = null; 53 54 59 public OrderPatch(String sURL) { 60 super(METHOD_NAME, sURL); 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 elOrderPatch = xmlDoc.createElementNS( OrderPatch.WEBDAV_NAMESPACE ,"orderpatch"); 75 xmlDoc.appendChild(elOrderPatch); 76 77 if( this.m_aOrderedPaths!=null && this.m_aOrderedPaths.size()!=0 ) { 78 for (int i = 0; i < this.m_aOrderedPaths.size(); i++) { 79 String sPath = (String ) this.m_aOrderedPaths.get(i); 80 Element elOrderMember = xmlDoc.createElementNS( OrderPatch.WEBDAV_NAMESPACE, "order-member"); 81 82 Element elSegment = xmlDoc.createElementNS( OrderPatch.WEBDAV_NAMESPACE, "segment"); 83 Text txtSegment = xmlDoc.createTextNode( sPath.substring(sPath.lastIndexOf("/")+1) ); 84 85 Element elPosition = xmlDoc.createElementNS( OrderPatch.WEBDAV_NAMESPACE, "position"); 86 Element elPositionDetail = xmlDoc.createElementNS( OrderPatch.WEBDAV_NAMESPACE, "last"); 87 88 elSegment.appendChild(txtSegment); 89 elOrderMember.appendChild(elSegment); 90 elPosition.appendChild(elPositionDetail); 91 elOrderMember.appendChild(elPosition); 92 elOrderPatch.appendChild(elOrderMember); 93 } 94 } 95 96 XMLPrettyPrint printer = new XMLPrettyPrint(); 97 printer.setNamespaceAware(true); 98 99 String sXML = ""; 100 try { 101 sXML = sXML + printer.printNode(xmlDoc.getDocumentElement()); 102 } catch (NamespaceClashException e1) { 103 e1.printStackTrace(); 104 } 105 106 return sXML.getBytes(); 107 } 108 109 114 public void setOrderedPaths(List aOrderedPaths) { 115 m_aOrderedPaths = (ArrayList ) aOrderedPaths; 116 } 117 118 public static void main(String [] args) { 119 OrderPatch method = new OrderPatch("/ete/ete"); 120 121 ArrayList aPaths = new ArrayList (); 122 aPaths.add("/webdav/Documents/orderdir/1stFile"); 123 aPaths.add("/webdav/Documents/orderdir/2ndFile"); 124 aPaths.add("/webdav/Documents/orderdir/3rdFile"); 125 aPaths.add("/webdav/Documents/orderdir/4thFile"); 126 127 method.setOrderedPaths(aPaths); 128 129 String sData = new String (method.getData()); 130 } 131 132 } 133 | Popular Tags |