Skip to content

Commit c6f23fc

Browse files
committed
add ctors to provide the HtmlElementsProvider
1 parent 3ce3fe1 commit c6f23fc

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/main/java/org/htmlunit/cyberneko/parsers/DOMFragmentParser.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.Reader;
2121

2222
import org.htmlunit.cyberneko.HTMLConfiguration;
23+
import org.htmlunit.cyberneko.HTMLElementsProvider;
2324
import org.htmlunit.cyberneko.xerces.parsers.Constants;
2425
import org.htmlunit.cyberneko.xerces.util.ErrorHandlerWrapper;
2526
import org.htmlunit.cyberneko.xerces.util.XMLChar;
@@ -94,6 +95,18 @@ public DOMFragmentParser() {
9495
parserConfiguration_.setDocumentHandler(this);
9596
}
9697

98+
/**
99+
* Ctor using a custom {@link HTMLElementsProvider}
100+
* @param htmlElementsProvider the custom {@link HTMLElementsProvider}
101+
*/
102+
public DOMFragmentParser(final HTMLElementsProvider htmlElementsProvider) {
103+
parserConfiguration_ = new HTMLConfiguration(htmlElementsProvider);
104+
parserConfiguration_.addRecognizedFeatures(RECOGNIZED_FEATURES);
105+
parserConfiguration_.addRecognizedProperties(RECOGNIZED_PROPERTIES);
106+
parserConfiguration_.setFeature("http://cyberneko.org/html/features/balance-tags/document-fragment", true);
107+
parserConfiguration_.setDocumentHandler(this);
108+
}
109+
97110
/**
98111
* Parses a document fragment.
99112
*

src/main/java/org/htmlunit/cyberneko/parsers/DOMParser.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,29 @@
1616
package org.htmlunit.cyberneko.parsers;
1717

1818
import org.htmlunit.cyberneko.HTMLConfiguration;
19+
import org.htmlunit.cyberneko.HTMLElementsProvider;
1920
import org.htmlunit.cyberneko.xerces.dom.DocumentImpl;
2021
import org.htmlunit.cyberneko.xerces.parsers.AbstractDOMParser;
2122

2223
/**
2324
* A DOM parser for HTML documents.
2425
*
2526
* @author Andy Clark
27+
* @author Ronald Brill
2628
*/
2729
public class DOMParser extends AbstractDOMParser {
2830

2931
/** Default constructor. */
3032
public DOMParser(final Class<? extends DocumentImpl> documentClass) {
3133
super(new HTMLConfiguration(), documentClass);
3234
}
35+
36+
/**
37+
* Ctor using a custom {@link HTMLElementsProvider}
38+
* @param htmlElementsProvider the custom {@link HTMLElementsProvider}
39+
* @param documentClass the {@link DocumentImpl} to be used
40+
*/
41+
public DOMParser(final HTMLElementsProvider htmlElementsProvider, final Class<? extends DocumentImpl> documentClass) {
42+
super(new HTMLConfiguration(htmlElementsProvider), documentClass);
43+
}
3344
}

src/main/java/org/htmlunit/cyberneko/parsers/SAXParser.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,27 @@
1616
package org.htmlunit.cyberneko.parsers;
1717

1818
import org.htmlunit.cyberneko.HTMLConfiguration;
19+
import org.htmlunit.cyberneko.HTMLElementsProvider;
1920
import org.htmlunit.cyberneko.xerces.parsers.AbstractSAXParser;
2021

2122
/**
2223
* A SAX parser for HTML documents.
2324
*
2425
* @author Andy Clark
26+
* @author Ronald Brill
2527
*/
2628
public class SAXParser extends AbstractSAXParser {
2729

2830
/** Default constructor. */
2931
public SAXParser() {
3032
super(new HTMLConfiguration());
3133
}
34+
35+
/**
36+
* Ctor using a custom {@link HTMLElementsProvider}
37+
* @param htmlElementsProvider the custom {@link HTMLElementsProvider}
38+
*/
39+
public SAXParser(final HTMLElementsProvider htmlElementsProvider) {
40+
super(new HTMLConfiguration(htmlElementsProvider));
41+
}
3242
}

0 commit comments

Comments
 (0)