Commit 3df1f11f authored by Thomas Mortagne's avatar Thomas Mortagne
Browse files

XCOMMONS-2175: Get rid of Xerces dependency

parent a041da15
......@@ -19,18 +19,17 @@
*/
package org.xwiki.xml.internal.html.filter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.xerces.util.DOMUtil;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.xwiki.component.annotation.Component;
import org.xwiki.xml.html.filter.AbstractHTMLFilter;
import org.xwiki.xml.internal.html.FontTagTransformation;
......@@ -59,9 +58,12 @@ public void filter(Document document, Map<String, String> cleaningParameters)
Element span = document.createElement(TAG_SPAN);
moveChildren(fontTag, span);
Map<String, String> attributes =
Arrays.stream(DOMUtil.getAttrs(fontTag)).collect(Collectors.toMap(Attr::getName,
Attr::getValue));
Map<String, String> attributes = new HashMap<>();
NamedNodeMap domAttributes = fontTag.getAttributes();
for (int i = 0; i < domAttributes.getLength(); ++i) {
Attr domAttribute = (Attr) domAttributes.item(i);
attributes.put(domAttribute.getName(), domAttribute.getValue());
}
(new FontTagTransformation()).applyTagTransformations(attributes).forEach(span::setAttribute);
......
......@@ -23,15 +23,17 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.FileUtils;
import org.apache.html.dom.HTMLDocumentImpl;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.html.HTMLElement;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSInput;
import org.xml.sax.SAXException;
......@@ -287,17 +289,22 @@ void createDomDocument()
}
@Test
void serializeNode()
void serializeNode() throws ParserConfigurationException
{
HTMLDocumentImpl node = new HTMLDocumentImpl();
String serialize = XMLUtils.serialize(node, false);
DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
String serialize = XMLUtils.serialize(document, false);
assertEquals("", serialize);
Element body = node.createElement("body");
node.setBody((HTMLElement) body);
Element html = document.createElement("html");
document.appendChild(html);
Element body = document.createElement("body");
html.appendChild(body);
body.setAttribute("class", "toto");
serialize = XMLUtils.serialize(node, false);
assertEquals("<HTML><HEAD/><BODY class=\"toto\"/></HTML>", serialize);
serialize = XMLUtils.serialize(document, false);
assertEquals("<html><body class=\"toto\"/></html>", serialize);
}
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment