1 23 24 package org.apache.webdav.lib; 25 26 import java.io.StringWriter ; 27 import java.util.List ; 28 29 import org.apache.webdav.lib.util.DOMUtils; 30 import org.apache.webdav.lib.util.PropertyWriter; 31 import org.jdom.input.DOMBuilder; 32 import org.jdom.output.Format; 33 import org.jdom.output.XMLOutputter; 34 import org.w3c.dom.Element ; 35 36 41 public class BaseProperty implements Property { 42 43 44 46 47 50 public BaseProperty(ResponseEntity response, Element element) { 51 this.element = element; 52 this.response = response; 53 } 54 55 56 58 59 62 protected ResponseEntity response; 63 64 65 68 protected Element element; 69 70 71 73 74 81 public String getName() { 82 return element.getTagName(); 83 } 84 85 86 93 public String getLocalName() { 94 return DOMUtils.getElementLocalName(element); 95 } 96 97 98 105 public String getNamespaceURI() { 106 return DOMUtils.getElementNamespaceURI(element); 107 } 108 109 110 113 public Element getElement() { 114 return element; 115 } 116 117 118 127 public String getPropertyAsString() { 128 StringBuffer text = new StringBuffer (); 129 DOMBuilder builder = new DOMBuilder(); 130 XMLOutputter outputter = new XMLOutputter( Format.getPrettyFormat() ); 131 org.jdom.Element e = builder.build( element ); 132 List children = e.getChildren(); 133 if ( children.size() > 0 ) { 134 text.append( outputter.outputString( children ) ); 135 } 136 text.append( e.getTextTrim() ); 137 return text.toString(); 138 } 139 140 141 144 public int getStatusCode() { 145 149 163 Element status = DOMUtils.getFirstElement(element.getParentNode().getParentNode(),"DAV:", "status"); 164 if (status != null) { 165 return DOMUtils.parseStatus(DOMUtils.getTextValue(status)); 166 } 167 168 return response.getStatusCode(); 169 } 170 171 172 176 public String getOwningURL() { 177 return response.getHref(); 178 } 179 180 181 184 public String toString () { 185 StringWriter tmp = new StringWriter (); 186 PropertyWriter propertyWriter = new PropertyWriter(tmp, true); 187 propertyWriter.print(element); 188 return tmp.getBuffer().toString(); 189 } 190 191 192 } 193 | Popular Tags |