1 19 package org.openharmonise.webdav.client; 20 21 import java.io.*; 22 import java.util.*; 23 24 import javax.xml.parsers.*; 25 26 import org.w3c.dom.*; 27 import org.xml.sax.*; 28 29 import HTTPClient.*; 30 31 39 public class WebDAVResponse { 40 41 44 private HTTPResponse m_response = null; 45 46 49 private List m_aMultiStatusResponses = new ArrayList(); 50 51 54 private String m_sURL = null; 55 56 63 public WebDAVResponse(HTTPResponse response) throws IOException, ModuleException { 64 super(); 65 this.m_response = response; 66 this.processResponse(); 67 } 68 69 78 public int getStatusCode() throws IOException, ModuleException { 79 return this.m_response.getStatusCode(); 80 } 81 82 89 public byte[] getResponseData() throws IOException, ModuleException { 90 return this.m_response.getData(); 91 } 92 93 98 public Document getResponseXML() throws IOException { 99 Document document = null; 100 try { 101 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 102 factory.setNamespaceAware(true); 103 document = factory.newDocumentBuilder().parse( new InputSource( new InputStreamReader( new ByteArrayInputStream(this.m_response.getData()), "UTF-8" ) ) ); 104 } catch (SAXException e) { 105 e.printStackTrace(System.out); 106 } catch (ParserConfigurationException e) { 107 e.printStackTrace(System.out); 108 } catch (FactoryConfigurationError e) { 109 e.printStackTrace(System.out); 110 } catch (ModuleException e) { 111 e.printStackTrace(); 112 } 113 114 return document; 115 } 116 117 124 private void processResponse() throws IOException, ModuleException { 125 if( this.getStatusCode()==207 ) { 126 this.processMultiStatusResponse(); 127 } 128 } 129 130 135 public List getMultiStatusResponses() { 136 return this.m_aMultiStatusResponses; 137 } 138 139 145 private void processMultiStatusResponse() throws IOException { 146 Document xml = this.getResponseXML(); 147 if(xml!=null) { 148 Element elMultiStatus = xml.getDocumentElement(); 149 150 NodeList nl = elMultiStatus.getChildNodes(); 151 for(int i=0; i<nl.getLength(); i++) { 152 if( nl.item(i).getNodeType()==Node.ELEMENT_NODE ) { 153 Element elTemp = (Element)nl.item(i); 154 MultiStatusResponse multi = new MultiStatusResponse(); 155 multi.populate(elTemp); 156 this.m_aMultiStatusResponses.add(multi); 157 } 158 } 159 } 160 161 } 162 163 168 public String getURL() { 169 return this.m_sURL; 170 } 171 172 177 protected void setURL(String sURL) { 178 this.m_sURL = sURL; 179 } 180 181 187 public String getHeader(String sName) { 188 String sReturn = null; 189 try { 190 sReturn = this.m_response.getHeader(sName); 191 } catch (IOException e) { 192 e.printStackTrace(); 193 } catch (ModuleException e) { 194 e.printStackTrace(); 195 } 196 return sReturn; 197 } 198 } 199 | Popular Tags |