Skip to content

Commit 9bb33d0

Browse files
committed
XmlUtilsXercesHelper and XmlUtilsSunXercesHelper removed
1 parent 8e00b87 commit 9bb33d0

File tree

3 files changed

+12
-131
lines changed

3 files changed

+12
-131
lines changed

src/main/java/org/htmlunit/platform/Platform.java

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
import java.io.IOException;
1818
import java.io.InputStream;
1919
import java.lang.reflect.InvocationTargetException;
20-
import java.util.HashMap;
21-
import java.util.List;
22-
import java.util.Map;
2320

2421
import org.apache.commons.lang3.reflect.ConstructorUtils;
2522
import org.htmlunit.platform.canvas.rendering.AwtRenderingBackend;
@@ -30,9 +27,6 @@
3027
import org.htmlunit.platform.font.NoOpFontUtil;
3128
import org.htmlunit.platform.image.ImageData;
3229
import org.htmlunit.platform.image.NoOpImageData;
33-
import org.w3c.dom.Document;
34-
import org.w3c.dom.NamedNodeMap;
35-
import org.w3c.dom.Node;
3630

3731
/**
3832
* Singleton to handle JDK specific stuff.
@@ -47,78 +41,6 @@ public final class Platform {
4741

4842
private static FontUtil FontUtil_;
4943

50-
private static XmlUtilsHelperAPI HelperXerces_;
51-
private static XmlUtilsHelperAPI HelperSunXerces_;
52-
53-
static {
54-
try {
55-
HelperSunXerces_ = (XmlUtilsHelperAPI) Class.forName("org.htmlunit.platform.util.XmlUtilsSunXercesHelper")
56-
.getDeclaredConstructor().newInstance();
57-
}
58-
catch (final Exception | LinkageError ignored) {
59-
// ignore
60-
}
61-
62-
try {
63-
HelperXerces_ = (XmlUtilsHelperAPI) Class.forName("org.htmlunit.platform.util.XmlUtilsXercesHelper")
64-
.getDeclaredConstructor().newInstance();
65-
}
66-
catch (final Exception | LinkageError ignored) {
67-
// ignore
68-
}
69-
}
70-
71-
/**
72-
* Forward the call to the correct helper.
73-
*
74-
* @param namedNodeMap the node map
75-
* @param attributesOrderMap the order map
76-
* @param element the node
77-
* @param requiredIndex the required index
78-
* @return the index or requiredIndex
79-
*/
80-
public static int getIndex(final NamedNodeMap namedNodeMap, final Map<Integer, List<String>> attributesOrderMap,
81-
final Node element, final int requiredIndex) {
82-
if (HelperXerces_ != null) {
83-
final int result = HelperXerces_.getIndex(namedNodeMap, attributesOrderMap, element, requiredIndex);
84-
if (result != -1) {
85-
return result;
86-
}
87-
}
88-
if (HelperSunXerces_ != null) {
89-
final int result = HelperSunXerces_.getIndex(namedNodeMap, attributesOrderMap, element, requiredIndex);
90-
if (result != -1) {
91-
return result;
92-
}
93-
}
94-
95-
return requiredIndex;
96-
}
97-
98-
/**
99-
* Returns internal Xerces details about all elements in the specified document.
100-
* The id of the returned {@link Map} is the {@code nodeIndex} of an element, and the list
101-
* is the array of ordered attributes names.
102-
* @param document the document
103-
* @return the map of an element index with its ordered attribute names
104-
*/
105-
public static Map<Integer, List<String>> getAttributesOrderMap(final Document document) {
106-
if (HelperXerces_ != null) {
107-
final Map<Integer, List<String>> result = HelperXerces_.getAttributesOrderMap(document);
108-
if (result != null) {
109-
return result;
110-
}
111-
}
112-
if (HelperSunXerces_ != null) {
113-
final Map<Integer, List<String>> result = HelperSunXerces_.getAttributesOrderMap(document);
114-
if (result != null) {
115-
return result;
116-
}
117-
}
118-
119-
return new HashMap<>();
120-
}
121-
12244
/**
12345
* @param imageWidth the width of the image this backend is for
12446
* @param imageHeight the height of the image this backend is for

src/main/java/org/htmlunit/util/XmlUtils.java

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.io.Reader;
2323
import java.io.StringReader;
2424
import java.nio.charset.Charset;
25-
import java.util.List;
2625
import java.util.Locale;
2726
import java.util.Map;
2827

@@ -45,7 +44,6 @@
4544
import org.htmlunit.html.DomText;
4645
import org.htmlunit.html.ElementFactory;
4746
import org.htmlunit.html.Html;
48-
import org.htmlunit.platform.Platform;
4947
import org.htmlunit.xml.XmlPage;
5048
import org.w3c.dom.Attr;
5149
import org.w3c.dom.Document;
@@ -217,34 +215,18 @@ public int read(final char[] cbuf, final int off, final int len) throws IOExcept
217215
*/
218216
public static void appendChild(final SgmlPage page, final DomNode parent, final Node child,
219217
final boolean handleXHTMLAsHTML) {
220-
appendChild(page, parent, child, handleXHTMLAsHTML, null);
221-
}
222-
223-
/**
224-
* Recursively appends a {@link Node} child to {@link DomNode} parent.
225-
*
226-
* @param page the owner page of {@link DomElement}s to be created
227-
* @param parent the parent DomNode
228-
* @param child the child Node
229-
* @param handleXHTMLAsHTML if true elements from the XHTML namespace are handled as HTML elements instead of
230-
* DOM elements
231-
* @param attributesOrderMap (optional) the one returned by {@link #getAttributesOrderMap(Document)}
232-
*/
233-
public static void appendChild(final SgmlPage page, final DomNode parent, final Node child,
234-
final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) {
235218
final DocumentType documentType = child.getOwnerDocument().getDoctype();
236219
if (documentType != null && page instanceof XmlPage xmlPage) {
237220
final DomDocumentType domDoctype = new DomDocumentType(
238221
page, documentType.getName(), documentType.getPublicId(), documentType.getSystemId());
239222
xmlPage.setDocumentType(domDoctype);
240223
}
241-
final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML, attributesOrderMap);
224+
final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML);
242225
parent.appendChild(childXml);
243-
copy(page, child, childXml, handleXHTMLAsHTML, attributesOrderMap);
226+
copy(page, child, childXml, handleXHTMLAsHTML);
244227
}
245228

246-
private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML,
247-
final Map<Integer, List<String>> attributesOrderMap) {
229+
private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML) {
248230
if (source.getNodeType() == Node.TEXT_NODE) {
249231
return new DomText(page, source.getNodeValue());
250232
}
@@ -264,7 +246,7 @@ private static DomNode createFrom(final SgmlPage page, final Node source, final
264246
if (handleXHTMLAsHTML && Html.XHTML_NAMESPACE.equals(ns)) {
265247
final ElementFactory factory = page.getWebClient().getPageCreator().getHtmlParser().getFactory(localName);
266248
return factory.createElementNS(page, ns, localName,
267-
namedNodeMapToSaxAttributes(source.getAttributes(), attributesOrderMap, source));
249+
namedNodeMapToSaxAttributes(source.getAttributes()));
268250
}
269251
final NamedNodeMap nodeAttributes = source.getAttributes();
270252
if (page != null && page.isHtmlPage()) {
@@ -282,13 +264,12 @@ private static DomNode createFrom(final SgmlPage page, final Node source, final
282264
if (Html.SVG_NAMESPACE.equals(namespaceURI)) {
283265
return page.getWebClient().getPageCreator().getHtmlParser().getSvgFactory()
284266
.createElementNS(page, namespaceURI, qualifiedName,
285-
namedNodeMapToSaxAttributes(nodeAttributes, attributesOrderMap, source));
267+
namedNodeMapToSaxAttributes(nodeAttributes));
286268
}
287269

288270
final OrderedFastHashMap<String, DomAttr> attributes = new OrderedFastHashMap<>();
289271
for (int i = 0; i < nodeAttributes.getLength(); i++) {
290-
final int orderedIndex = Platform.getIndex(nodeAttributes, attributesOrderMap, source, i);
291-
final Attr attribute = (Attr) nodeAttributes.item(orderedIndex);
272+
final Attr attribute = (Attr) nodeAttributes.item(i);
292273
final String attributeNamespaceURI = attribute.getNamespaceURI();
293274
final String attributeQualifiedName;
294275
if (attribute.getPrefix() == null) {
@@ -306,13 +287,11 @@ private static DomNode createFrom(final SgmlPage page, final Node source, final
306287
return new DomElement(namespaceURI, qualifiedName, page, attributes);
307288
}
308289

309-
private static Attributes namedNodeMapToSaxAttributes(final NamedNodeMap attributesMap,
310-
final Map<Integer, List<String>> attributesOrderMap, final Node element) {
290+
private static Attributes namedNodeMapToSaxAttributes(final NamedNodeMap attributesMap) {
311291
final AttributesImpl attributes = new AttributesImpl();
312292
final int length = attributesMap.getLength();
313293
for (int i = 0; i < length; i++) {
314-
final int orderedIndex = Platform.getIndex(attributesMap, attributesOrderMap, element, i);
315-
final Node attr = attributesMap.item(orderedIndex);
294+
final Node attr = attributesMap.item(i);
316295
attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(),
317296
attr.getNodeName(), null, attr.getNodeValue());
318297
}
@@ -329,15 +308,15 @@ private static Attributes namedNodeMapToSaxAttributes(final NamedNodeMap attribu
329308
* DOM elements
330309
*/
331310
private static void copy(final SgmlPage page, final Node source, final DomNode dest,
332-
final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) {
311+
final boolean handleXHTMLAsHTML) {
333312
final NodeList nodeChildren = source.getChildNodes();
334313
for (int i = 0; i < nodeChildren.getLength(); i++) {
335314
final Node child = nodeChildren.item(i);
336315
switch (child.getNodeType()) {
337316
case Node.ELEMENT_NODE:
338-
final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML, attributesOrderMap);
317+
final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML);
339318
dest.appendChild(childXml);
340-
copy(page, child, childXml, handleXHTMLAsHTML, attributesOrderMap);
319+
copy(page, child, childXml, handleXHTMLAsHTML);
341320
break;
342321

343322
case Node.TEXT_NODE:
@@ -414,15 +393,4 @@ public static String lookupPrefix(final DomElement element, final String namespa
414393
}
415394
return null;
416395
}
417-
418-
/**
419-
* Returns internal Xerces details about all elements in the specified document.
420-
* The id of the returned {@link Map} is the {@code nodeIndex} of an element, and the list
421-
* is the array of ordered attributes names.
422-
* @param document the document
423-
* @return the map of an element index with its ordered attribute names
424-
*/
425-
public static Map<Integer, List<String>> getAttributesOrderMap(final Document document) {
426-
return Platform.getAttributesOrderMap(document);
427-
}
428396
}

src/main/java/org/htmlunit/xml/XmlPage.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import java.io.IOException;
2020
import java.nio.charset.Charset;
2121
import java.util.HashMap;
22-
import java.util.List;
23-
import java.util.Map;
2422

2523
import javax.xml.parsers.ParserConfigurationException;
2624

@@ -143,15 +141,8 @@ public XmlPage(final WebResponse webResponse, final WebWindow enclosingWindow, f
143141
}
144142
}
145143

146-
final Map<Integer, List<String>> attributesOrderMap;
147-
if (node_ != null) {
148-
attributesOrderMap = XmlUtils.getAttributesOrderMap(node_.getOwnerDocument());
149-
}
150-
else {
151-
attributesOrderMap = null;
152-
}
153144
for (Node node = node_; node != null; node = node.getNextSibling()) {
154-
XmlUtils.appendChild(this, this, node, handleXHTMLAsHTML, attributesOrderMap);
145+
XmlUtils.appendChild(this, this, node, handleXHTMLAsHTML);
155146
}
156147
}
157148

0 commit comments

Comments
 (0)