本文整理汇总了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);
}
}