Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple impl to try to use https://github.com/HtmlUnit/htmlunit-neko SAX parser (see #282) #333

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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