/** Creates a SAX parser.
*
* <p>See {@link #parse} for hints on setting an entity resolver.
*
* @param validate if true, a validating parser is returned
* @param namespaceAware if true, a namespace aware parser is returned
*
* @throws FactoryConfigurationError Application developers should never need to directly catch errors of this type.
* @throws SAXException if a parser fulfilling given parameters can not be created
*
* @return XMLReader configured according to passed parameters
*/
public static synchronized XMLReader createXMLReader(boolean validate, boolean namespaceAware)
throws SAXException {
SAXParserFactory factory = saxes[validate ? 0 : 1][namespaceAware ? 0 : 1];
if (factory == null) {
try {
factory = SAXParserFactory.newInstance();
} catch (FactoryConfigurationError err) {
Exceptions.attachMessage(
err,
"Info about thread context classloader: " + // NOI18N
Thread.currentThread().getContextClassLoader()
);
throw err;
}
factory.setValidating(validate);
factory.setNamespaceAware(namespaceAware);
saxes[validate ? 0 : 1][namespaceAware ? 0 : 1] = factory;
}
try {
return factory.newSAXParser().getXMLReader();
} catch (ParserConfigurationException ex) {
throw new SAXException("Cannot create parser satisfying configuration parameters", ex); //NOI18N
}
}
XMLUtil.java 文件源码
java
阅读 32
收藏 0
点赞 0
评论 0
项目:incubator-netbeans
作者:
评论列表
文章目录