1 19 package org.openharmonise.webdav.client; 20 21 import java.io.UnsupportedEncodingException ; 22 import java.net.URLDecoder ; 23 24 import javax.xml.parsers.DocumentBuilderFactory ; 25 import javax.xml.parsers.FactoryConfigurationError ; 26 import javax.xml.parsers.ParserConfigurationException ; 27 28 import org.w3c.dom.Document ; 29 import org.w3c.dom.Element ; 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.NodeList ; 32 import org.w3c.dom.Text ; 33 34 42 public class MultiStatusResponse { 43 44 private int m_nStatus = -1; 45 private String m_sURI = null; 46 private String m_sResponseDescription = null; 47 48 private Element m_elResponseXML = null; 49 50 public MultiStatusResponse() { 51 super(); 52 } 53 54 59 public int getStatus() { 60 return this.m_nStatus; 61 } 62 63 68 public String getURI() { 69 try { 70 return URLDecoder.decode(this.m_sURI, "UTF-8"); 71 } catch (UnsupportedEncodingException e) { 72 e.printStackTrace(); 73 } 74 return null; 75 } 76 77 82 public String getResponseDescription() { 83 return this.m_sResponseDescription; 84 } 85 86 91 public Element getResponseXML() { 92 return this.m_elResponseXML; 93 } 94 95 100 public void populate(Element elResponse) { 101 this.m_elResponseXML = elResponse; 102 NodeList nl = elResponse.getChildNodes(); 103 for (int i = 0; i < nl.getLength(); i++) { 104 if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) { 105 Element elTemp = (Element ) nl.item(i); 106 107 if (elTemp.getLocalName().equals("href")) { 108 this.m_sURI = elTemp.getFirstChild().getNodeValue(); 109 } else if (elTemp.getLocalName().equals("status")) { 110 String sStatus = elTemp.getFirstChild().getNodeValue(); 111 sStatus = sStatus.substring(sStatus.indexOf(" ") + 1); 112 sStatus = sStatus.substring(0, sStatus.indexOf(" ")); 113 this.m_nStatus = Integer.parseInt(sStatus); 114 } else if (elTemp.getLocalName().equals("propstat")) { 115 NodeList nl2 = elTemp.getChildNodes(); 116 for (int j = 0; j < nl2.getLength(); j++) { 117 if (nl2.item(j).getNodeType() == Node.ELEMENT_NODE) { 118 Element elTemp2 = (Element ) nl2.item(j); 119 120 if (elTemp2.getLocalName().equals("status")) { 121 String sStatus = elTemp2.getFirstChild().getNodeValue(); 122 sStatus = sStatus.substring(sStatus.indexOf(" ") + 1); 123 sStatus = sStatus.substring(0, sStatus.indexOf(" ")); 124 this.m_nStatus = Integer.parseInt(sStatus); 125 } else if (elTemp2.getLocalName().equals("responsedescription")) { 126 this.m_sResponseDescription = elTemp2.getFirstChild().getNodeValue(); 127 } 128 } 129 } 130 } else if (elTemp.getLocalName().equals("responsedescription")) { 131 this.m_sResponseDescription = elTemp.getFirstChild().getNodeValue(); 132 } 133 } 134 } 135 } 136 137 public static void main(String [] args) { 138 MultiStatusResponse multi = new MultiStatusResponse(); 139 140 Document xmlDoc = null; 141 try { 142 DocumentBuilderFactory factory = 143 DocumentBuilderFactory.newInstance(); 144 factory.setNamespaceAware(true); 145 146 xmlDoc = factory.newDocumentBuilder().newDocument(); 147 } catch (ParserConfigurationException e) { 148 e.printStackTrace(); 149 } catch (FactoryConfigurationError e) { 150 e.printStackTrace(); 151 } 152 Element elResp = 153 xmlDoc.createElementNS( 154 WebDAVConnection.WEBDAV_NAMESPACE, 155 "response"); 156 157 Element elHREF = 158 xmlDoc.createElementNS(WebDAVConnection.WEBDAV_NAMESPACE, "href"); 159 Text txt = xmlDoc.createTextNode("http://www.sim.com"); 160 elHREF.appendChild(txt); 161 elResp.appendChild(elHREF); 162 163 Element elPropStat = 164 xmlDoc.createElementNS( 165 WebDAVConnection.WEBDAV_NAMESPACE, 166 "propstat"); 167 elResp.appendChild(elPropStat); 168 169 Element elStatus = 170 xmlDoc.createElementNS(WebDAVConnection.WEBDAV_NAMESPACE, "status"); 171 txt = xmlDoc.createTextNode("HTTP/1.1 200 OK"); 172 elStatus.appendChild(txt); 173 elPropStat.appendChild(elStatus); 174 175 multi.populate(elResp); 176 } 177 178 } 179 | Popular Tags |