protected Builder newBuilder(XMLReader parser, boolean validate) {
return new Builder(parser, validate, null);
}
private XMLReader createParser(boolean w3cSchemaParser) {
XMLReader parser;
for (int i = 0; i < PARSERS.length; i++) {
try {
parser = XMLReaderFactory.createXMLReader(PARSERS[i]);
if (w3cSchemaParser && ENABLE_PARSER_GRAMMAR_POOLS) {
String clazz = (String) PARSER_GRAMMAR_POOLS.get(PARSERS[i]);
if (clazz != null) {
// This improves performance and, more importantly, prevents xerces
// bugs/exceptions when the Builder is used more than once (at least for
// xerces-2.6.2). But it would lead to xerces bugs in non-validating mode with DTDs,
// at least for xerces-2.7.1, so in this case we're not enabling it.
// See http://xml.apache.org/xerces2-j/faq-grammars.html
// See http://www-106.ibm.com/developerworks/xml/library/x-perfap3.html
parser.setProperty("http://apache.org/xml/properties/internal/grammar-pool",
ClassLoaderUtil.newInstance(clazz));
}
}
setupFeaturesAndProps(parser);
//parser.setProperty("http://apache.org/xml/properties/input-buffer-size", new Integer(8192));
if (DEBUG) System.err.println("using XMLReader=" + parser.getClass().getName());
return parser;
} catch (SAXException ex) {
// keep on trying
} catch (NoClassDefFoundError err) {
// keep on trying
} catch (Exception err) {
// keep on trying
}
}
try { // SAX default
parser = XMLReaderFactory.createXMLReader();
setupFeaturesAndProps(parser);
if (DEBUG) System.err.println("using default SAX XMLReader=" + parser.getClass().getName());
return parser;
} catch (Exception ex) {
// keep on trying
}
try { // JAXP default
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
parser = factory.newSAXParser().getXMLReader();
setupFeaturesAndProps(parser);
if (DEBUG) System.err.println("using default JAXP XMLReader=" + parser.getClass().getName());
return parser;
} catch (Exception ex) {
throw new XMLException(
"Could not find or create a suitable SAX2 parser" +
" - check your classpath",