2222import java .io .Reader ;
2323import java .io .StringReader ;
2424import java .nio .charset .Charset ;
25- import java .util .List ;
2625import java .util .Locale ;
2726import java .util .Map ;
2827
4544import org .htmlunit .html .DomText ;
4645import org .htmlunit .html .ElementFactory ;
4746import org .htmlunit .html .Html ;
48- import org .htmlunit .platform .Platform ;
4947import org .htmlunit .xml .XmlPage ;
5048import org .w3c .dom .Attr ;
5149import 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}
0 commit comments