1 19 package org.openharmonise.webdav.client.methods; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 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 33 34 41 public class PropFind extends AbstractWebDAVMethod { 42 43 46 public static String METHOD_NAME = "PROPFIND"; 47 48 51 private ArrayList m_properties = new ArrayList (5); 52 53 58 public PropFind(String sURL) { 59 super(METHOD_NAME, sURL); 60 } 61 62 public byte[] getData() { 63 64 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 65 factory.setNamespaceAware(true); 66 Document xmlDoc = null; 67 try { 68 xmlDoc = factory.newDocumentBuilder().newDocument(); 69 } catch (ParserConfigurationException e) { 70 e.printStackTrace(); 71 } 72 73 Element elPropFind = xmlDoc.createElementNS( PropPatch.WEBDAV_NAMESPACE ,"propfind"); 74 xmlDoc.appendChild(elPropFind); 75 76 if( this.m_properties.size()==0 ) { 77 Element elAllProp = xmlDoc.createElementNS( PropPatch.WEBDAV_NAMESPACE ,"allprop"); 78 elPropFind.appendChild(elAllProp); 79 } else { 80 Element elProp = xmlDoc.createElementNS( PropPatch.WEBDAV_NAMESPACE, "prop"); 81 elPropFind.appendChild(elProp); 82 Iterator itor = this.m_properties.iterator(); 83 while(itor.hasNext()) { 84 PropFindProperty prop = (PropFindProperty)itor.next(); 85 Element elProperty = xmlDoc.createElementNS( prop.getNamespaceURI(), prop.getName()); 86 elProp.appendChild(elProperty); 87 } 88 } 89 90 XMLPrettyPrint printer = new XMLPrettyPrint(); 91 printer.setNamespaceAware(true); 92 93 String sXML = ""; 94 try { 95 sXML = sXML + printer.printNode(xmlDoc.getDocumentElement()); 96 } catch (NamespaceClashException e1) { 97 e1.printStackTrace(); 98 } 99 100 return sXML.getBytes(); 101 } 102 103 109 public void addProperty(String sNamespaceURI, String sName) { 110 this.m_properties.add( new PropFindProperty(sNamespaceURI, sName) ); 111 } 112 113 } 114 | Popular Tags |