1 16 17 package org.apache.xerces.util; 18 19 import java.io.InputStream ; 20 import java.io.Reader ; 21 22 import org.apache.xerces.xni.parser.XMLInputSource; 23 import org.xml.sax.InputSource ; 24 import org.xml.sax.XMLReader ; 25 26 31 public final class SAXInputSource extends XMLInputSource { 32 33 private XMLReader fXMLReader; 34 private InputSource fInputSource; 35 36 public SAXInputSource() { 37 this(null); 38 } 39 40 public SAXInputSource(InputSource inputSource) { 41 this(null, inputSource); 42 } 43 44 public SAXInputSource(XMLReader reader, InputSource inputSource) { 45 super(inputSource != null ? inputSource.getPublicId() : null, 46 inputSource != null ? inputSource.getSystemId() : null, null); 47 if (inputSource != null) { 48 setByteStream(inputSource.getByteStream()); 49 setCharacterStream(inputSource.getCharacterStream()); 50 setEncoding(inputSource.getEncoding()); 51 } 52 fInputSource = inputSource; 53 fXMLReader = reader; 54 } 55 56 public void setXMLReader(XMLReader reader) { 57 fXMLReader = reader; 58 } 59 60 public XMLReader getXMLReader() { 61 return fXMLReader; 62 } 63 64 public void setInputSource(InputSource inputSource) { 65 if (inputSource != null) { 66 setPublicId(inputSource.getPublicId()); 67 setSystemId(inputSource.getSystemId()); 68 setByteStream(inputSource.getByteStream()); 69 setCharacterStream(inputSource.getCharacterStream()); 70 setEncoding(inputSource.getEncoding()); 71 } 72 else { 73 setPublicId(null); 74 setSystemId(null); 75 setByteStream(null); 76 setCharacterStream(null); 77 setEncoding(null); 78 } 79 fInputSource = inputSource; 80 } 81 82 public InputSource getInputSource() { 83 return fInputSource; 84 } 85 86 91 public void setPublicId(String publicId) { 92 super.setPublicId(publicId); 93 if (fInputSource == null) { 94 fInputSource = new InputSource(); 95 } 96 fInputSource.setPublicId(publicId); 97 } 99 104 public void setSystemId(String systemId) { 105 super.setSystemId(systemId); 106 if (fInputSource == null) { 107 fInputSource = new InputSource(); 108 } 109 fInputSource.setSystemId(systemId); 110 } 112 121 public void setByteStream(InputStream byteStream) { 122 super.setByteStream(byteStream); 123 if (fInputSource == null) { 124 fInputSource = new InputSource(); 125 } 126 fInputSource.setByteStream(byteStream); 127 } 129 140 public void setCharacterStream(Reader charStream) { 141 super.setCharacterStream(charStream); 142 if (fInputSource == null) { 143 fInputSource = new InputSource(); 144 } 145 fInputSource.setCharacterStream(charStream); 146 } 148 153 public void setEncoding(String encoding) { 154 super.setEncoding(encoding); 155 if (fInputSource == null) { 156 fInputSource = new InputSource(); 157 } 158 fInputSource.setEncoding(encoding); 159 } 161 } | Popular Tags |