1 6 7 10 package javax.xml.transform.sax; 11 12 import javax.xml.transform.Source ; 13 import javax.xml.transform.stream.StreamSource ; 14 15 import org.xml.sax.InputSource ; 16 import org.xml.sax.XMLReader ; 17 18 30 public class SAXSource implements Source { 31 32 37 public static final String FEATURE = 38 "http://javax.xml.transform.sax.SAXSource/feature"; 39 40 50 public SAXSource() { } 51 52 63 public SAXSource(XMLReader reader, InputSource inputSource) { 64 this.reader = reader; 65 this.inputSource = inputSource; 66 } 67 68 80 public SAXSource(InputSource inputSource) { 81 this.inputSource = inputSource; 82 } 83 84 89 public void setXMLReader(XMLReader reader) { 90 this.reader = reader; 91 } 92 93 98 public XMLReader getXMLReader() { 99 return reader; 100 } 101 102 107 public void setInputSource(InputSource inputSource) { 108 this.inputSource = inputSource; 109 } 110 111 116 public InputSource getInputSource() { 117 return inputSource; 118 } 119 120 134 public void setSystemId(String systemId) { 135 136 if (null == inputSource) { 137 inputSource = new InputSource (systemId); 138 } else { 139 inputSource.setSystemId(systemId); 140 } 141 } 142 143 149 public String getSystemId() { 150 151 if (inputSource == null) { 152 return null; 153 } else { 154 return inputSource.getSystemId(); 155 } 156 } 157 158 161 private XMLReader reader; 162 163 167 private InputSource inputSource; 168 169 177 public static InputSource sourceToInputSource(Source source) { 178 179 if (source instanceof SAXSource ) { 180 return ((SAXSource ) source).getInputSource(); 181 } else if (source instanceof StreamSource ) { 182 StreamSource ss = (StreamSource ) source; 183 InputSource isource = new InputSource (ss.getSystemId()); 184 185 isource.setByteStream(ss.getInputStream()); 186 isource.setCharacterStream(ss.getReader()); 187 isource.setPublicId(ss.getPublicId()); 188 189 return isource; 190 } else { 191 return null; 192 } 193 } 194 } 195 196 | Popular Tags |