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 32 import com.wutka.dtd.DTD; 34 import com.wutka.dtd.DTDParser; 35 36 53 public class StreamDTDSource extends DTDSource { 54 55 56 private Reader reader; 57 58 59 private DTD dtd; 60 61 75 public StreamDTDSource(InputStream inputStream, String systemID) { 76 if (inputStream == null) { 77 throw new IllegalArgumentException ("A StreamDTDSource cannot " + 78 "have a null InputStream."); 79 } 80 81 this.reader = new InputStreamReader (inputStream); 82 setSystemID(systemID); 83 } 84 85 98 public StreamDTDSource(InputStream inputStream) { 99 this(inputStream, null); 100 } 101 102 116 public StreamDTDSource(Reader reader, String systemID) { 117 if (reader == null) { 118 throw new IllegalArgumentException ("A StreamDTDSource cannot " + 119 "have a null Reader."); 120 } 121 122 this.reader = reader; 123 setSystemID(systemID); 124 } 125 126 139 public StreamDTDSource(Reader reader) { 140 this(reader, null); 141 } 142 143 155 public DTD getDTD() throws IOException { 156 DTDParser dtdParser = new DTDParser(reader); 157 DTD dtd = dtdParser.parse(true); 158 159 Object items[] = dtd.getItems(); 161 if (items.length == 0) { 162 throw new IOException ("A viable DTD could not be obtained from " + 163 "the supplied input source."); 164 } 165 166 return dtd; 167 } 168 } 169 | Popular Tags |