1 19 package org.enhydra.zeus.source; 20 21 import java.io.InputStream ; 22 import java.io.InputStreamReader ; 23 import java.io.IOException ; 24 import java.io.Reader ; 25 26 import org.enhydra.zeus.Source; 28 29 import org.jdom.Document; 31 import org.jdom.JDOMException; 32 import org.jdom.input.SAXBuilder; 33 34 51 public class StreamSource extends BaseSource { 52 53 54 private Reader reader; 55 56 57 private Document document; 58 59 73 public StreamSource(InputStream inputStream, String systemID) { 74 if (inputStream == null) { 75 throw new IllegalArgumentException ("A StreamSource cannot " + 76 "have a null InputStream."); 77 } 78 79 this.reader = new InputStreamReader (inputStream); 80 setSystemID(systemID); 81 } 82 83 96 public StreamSource(InputStream inputStream) { 97 this(inputStream, null); 98 } 99 100 114 public StreamSource(Reader reader, String systemID) { 115 if (reader == null) { 116 throw new IllegalArgumentException ("A StreamSource cannot " + 117 "have a null Reader."); 118 } 119 120 this.reader = reader; 121 setSystemID(systemID); 122 } 123 124 137 public StreamSource(Reader reader) { 138 this(reader, null); 139 } 140 141 152 public Document getDocument() throws IOException { 153 try { 154 SAXBuilder builder = new SAXBuilder(); 155 if (entityResolver != null) { 156 builder.setEntityResolver(entityResolver); 157 } 158 if (reader != null) { 159 document = builder.build(reader); 160 } else { 161 throw new IOException ("No source to read XML from!"); 162 } 163 164 return document; 165 } catch (JDOMException e) { 166 throw new IOException (e.getMessage()); 167 } 168 } 169 } 170 | Popular Tags |