本文整理匯總了Java中javax.xml.transform.Source.getClass方法的典型用法代碼示例。如果您正苦於以下問題:Java Source.getClass方法的具體用法?Java Source.getClass怎麽用?Java Source.getClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.transform.Source
的用法示例。
在下文中一共展示了Source.getClass方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createSourceReader
import javax.xml.transform.Source; //導入方法依賴的package包/類
public static XMLStreamReader createSourceReader(Source source, boolean rejectDTDs, String charsetName) {
try {
if (source instanceof StreamSource) {
StreamSource streamSource = (StreamSource) source;
InputStream is = streamSource.getInputStream();
if (is != null) {
// Wrap input stream in Reader if charset is specified
if (charsetName != null) {
return XMLStreamReaderFactory.create(
source.getSystemId(), new InputStreamReader(is, charsetName), rejectDTDs);
}
else {
return XMLStreamReaderFactory.create(
source.getSystemId(), is, rejectDTDs);
}
}
else {
Reader reader = streamSource.getReader();
if (reader != null) {
return XMLStreamReaderFactory.create(
source.getSystemId(), reader, rejectDTDs);
}
else {
return XMLStreamReaderFactory.create(
source.getSystemId(), new URL(source.getSystemId()).openStream(), rejectDTDs );
}
}
}
else if (source.getClass() == fastInfosetSourceClass) {
return FastInfosetUtil.createFIStreamReader((InputStream)
fastInfosetSource_getInputStream.invoke(source));
}
else if (source instanceof DOMSource) {
DOMStreamReader dsr = new DOMStreamReader();
dsr.setCurrentNode(((DOMSource) source).getNode());
return dsr;
}
else if (source instanceof SAXSource) {
// TODO: need SAX to StAX adapter here -- Use transformer for now
Transformer tx = XmlUtil.newTransformer();
DOMResult domResult = new DOMResult();
tx.transform(source, domResult);
return createSourceReader(
new DOMSource(domResult.getNode()),
rejectDTDs);
}
else {
throw new XMLReaderException("sourceReader.invalidSource",
source.getClass().getName());
}
}
catch (Exception e) {
throw new XMLReaderException(e);
}
}