1 package com.ibm.webdav; 2 3 17 import org.w3c.dom.*; 18 import java.io.*; 19 import javax.xml.parsers.*; 20 21 26 public class PropertyValue extends Object implements java.io.Serializable 27 { 28 30 public Element value = null; 31 32 35 public int status = WebDAVStatus.SC_OK; 36 42 public PropertyValue(Element value, int status) { 43 this.value = value; 44 this.status = status; 45 } 46 50 public int getStatus() 51 { 52 return status; 53 } 54 57 public Element getValue() { 58 return value; 59 } 60 63 static public String nodeToString( Element el ) { 64 65 return XMLUtility.printNode(el); 66 } 67 72 private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { 73 status = in.readInt(); 74 int size = in.readInt(); 75 byte[] buffer = new byte[size]; 76 in.readFully(buffer); 77 ByteArrayInputStream is = new ByteArrayInputStream(buffer); 78 Document contents = null; 79 80 try { 81 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 82 factory.setNamespaceAware(true); 83 DocumentBuilder docbuilder = factory.newDocumentBuilder(); 84 contents = docbuilder.parse(new org.xml.sax.InputSource (is)); 85 } catch(Exception e) { 86 throw new IOException(e.getMessage()); 87 } 88 89 value = contents.getDocumentElement(); 90 } 91 95 public String toContentString() { 96 Element el = (Element)value; 97 NodeList children = el.getChildNodes(); 98 String retval = ""; 100 101 for(int i=0;i<children.getLength();i++) { 102 Node child = (Node)children.item(i); 103 retval += XMLUtility.printNode( child ); 104 } 105 return retval; 106 } 107 110 public String toString() { 111 StringWriter s = new StringWriter(); 112 PrintWriter pout = new PrintWriter(s); 113 try { 114 pout.print(XMLUtility.printNode(value)); 115 pout.flush(); 117 s.write(" (" + status + ")"); 118 s.close(); 119 } catch (IOException exc) { 120 } 121 return s.toString(); 122 } 123 127 private void writeObject(java.io.ObjectOutputStream out) throws IOException { 128 Document document = null; 129 130 try { 131 document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); 132 } catch(Exception e) { 133 throw new IOException(e.getMessage()); 134 } 135 document.appendChild(value); 138 ByteArrayOutputStream os = new ByteArrayOutputStream(); 139 PrintWriter pw = new PrintWriter(os, false); 140 pw.print(XMLUtility.printNode(document.getDocumentElement())); 142 out.writeInt(status); 143 out.writeInt(os.size()); 144 out.write(os.toByteArray()); 145 } 146 } 147 | Popular Tags |