Skip to content

Commit

Permalink
simple impl to try to use https://github.com/HtmlUnit/htmlunit-neko S…
Browse files Browse the repository at this point in the history
…AX parser (see flyingsaucerproject#282)
  • Loading branch information
rbri committed Jun 2, 2024
1 parent 6a13c76 commit 291c2fa
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ public class XMLResource extends AbstractResource {
private Document document;
private static final XMLResourceBuilder XML_RESOURCE_BUILDER;
private static boolean useConfiguredParser;
private static boolean useHtmlUnitCyberNekoParser;

static {
XML_RESOURCE_BUILDER = new XMLResourceBuilder();
useConfiguredParser = true;
useHtmlUnitCyberNekoParser = true;
}

private XMLResource(InputStream stream) {
Expand Down Expand Up @@ -115,8 +117,8 @@ void setDocument(Document document) {

public static XMLReader newXMLReader() {
XMLReader xmlReader = null;
String xmlReaderClass = Configuration.valueFor("xr.load.xml-reader");

String xmlReaderClass = Configuration.valueFor("xr.load.xml-reader");
//TODO: if it doesn't find the parser, note that in a static boolean--otherwise
// you get exceptions on every load
try {
Expand All @@ -143,6 +145,17 @@ public static XMLReader newXMLReader() {
+ xmlReaderClass + ". Please check classpath. Use value 'default' in " +
"FS configuration if necessary. Will now try JDK default.", ex);
}

xmlReaderClass = "org.htmlunit.cyberneko.parsers.SAXParser";
if (xmlReaderClass != null && XMLResource.useHtmlUnitCyberNekoParser) {
try {
xmlReader = XMLReaderFactory.createXMLReader(xmlReaderClass);
} catch (Exception ex) {
XMLResource.useHtmlUnitCyberNekoParser = false;
// no need for logging here
}
}

if (xmlReader == null) {
try {
// JDK default
Expand Down Expand Up @@ -189,7 +202,7 @@ private XMLResource createXMLResource(XMLResource target) {

target.setElapsedLoadTime(end - start);
XRLog.load("Loaded document in ~" + target.getElapsedLoadTime() + "ms");

target.setDocument(document);
return target;
}
Expand Down

0 comments on commit 291c2fa

Please sign in to comment.