1 package com.ibm.webdav; 2 3 17 18 import org.w3c.dom.*; 19 20 30 public abstract class Response extends Object implements java.io.Serializable 31 { 32 33 public static String HTTPVersion = "HTTP/1.1"; 34 35 36 protected Document document = null; 37 private String resource = null; private String description = null; 39 41 public Response() { 42 } 43 49 public Response(Document document) throws ServerException { 50 this.document = document; 51 } 52 57 public Response(String url) { 58 resource = url; 59 } 60 63 public abstract Element asXML(); 64 68 public String getDescription() { 69 return description; 70 } 71 74 public String getResource() { 75 return resource; 76 } 77 81 public abstract boolean isOK(); 82 86 public void setDescription(String value) { 87 description = value; 88 } 89 93 public void setDocument(Document document) { 94 this.document = document; 95 } 96 98 protected void setResource(String url) { 99 resource = url; 100 } 101 106 public abstract PropertyResponse toPropertyResponse(); 107 113 public String toString() { 114 122 return printNode(asXML()); 123 } 124 125 130 public static String printNode( Node node ) { 131 StringBuffer sBuffer = new StringBuffer (); 132 133 if( node.getNodeType() == Node.TEXT_NODE ) { 134 sBuffer.append( node.getNodeValue() ) ; 135 } 136 else if( node.getNodeType() == Node.CDATA_SECTION_NODE ) { 137 sBuffer.append("<![CDATA["); 138 sBuffer.append( node.getNodeValue() ) ; 139 sBuffer.append("]]>\n"); 140 } 141 else if( node.getNodeType() == Node.ELEMENT_NODE ) { 142 Element el = (Element)node ; 143 144 sBuffer.append( "<" + el.getTagName() ) ; 145 146 NamedNodeMap attribs = el.getAttributes() ; 147 for( int i=0 ; i < attribs.getLength() ; i++ ) { 148 Attr nextAtt = (Attr)attribs.item(i) ; 149 sBuffer.append( " " + nextAtt.getName() + "=\"" + nextAtt.getValue() + "\"" ) ; 150 } 151 152 NodeList nodes = node.getChildNodes() ; 153 154 if( nodes.getLength() == 0 ) { 155 sBuffer.append("/>\n") ; 156 } 157 else { 158 sBuffer.append(">\n") ; 159 160 for( int i = 0 ; i < nodes.getLength() ; i++ ) { 161 sBuffer.append(printNode(nodes.item(i) )) ; 162 } 163 sBuffer.append( "</" + el.getTagName() + ">\n" ) ; 164 } 165 } 166 167 return(sBuffer.toString()); 168 } 169 } 170 | Popular Tags |