import java.io.InputStream;
import java.io.StringWriter;
import java.net.URI;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Test;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
public class Bug5446Test extends XMLTestCase {
private static final XMLOutputFactory XML_FACTORY;
- private static final DocumentBuilderFactory BUILDERFACTORY;
static {
XML_FACTORY = XMLOutputFactory.newFactory();
- XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
-
- BUILDERFACTORY = DocumentBuilderFactory.newInstance();
- BUILDERFACTORY.setNamespaceAware(true);
- BUILDERFACTORY.setCoalescing(true);
- BUILDERFACTORY.setIgnoringElementContentWhitespace(true);
- BUILDERFACTORY.setIgnoringComments(true);
+ XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);
}
- private QNameModule fooModuleQName;
- private QName rootQName;
- private QName ipAddressQName;
- private SchemaContext schemaContext;
+ private final QNameModule fooModuleQName;
+ private final QName rootQName;
+ private final QName ipAddressQName;
+ private final SchemaContext schemaContext;
public Bug5446Test() throws Exception {
fooModuleQName = QNameModule.create(new URI("foo"), SimpleDateFormatUtil.getRevisionFormat()
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setNormalize(true);
- String expectedXMLString = toString(doc.getDocumentElement().getElementsByTagName("root").item(0));
+ String expectedXMLString = toString(doc.getDocumentElement());
String serializationResultXMLString = toString(serializationResult.getNode());
assertXMLEqual(expectedXMLString, serializationResultXMLString);
private static DOMResult writeNormalizedNode(final ContainerNode normalized, final SchemaContext context)
throws IOException, XMLStreamException {
- final Document doc = getDocument();
+ final Document doc = UntrustedXML.newDocumentBuilder().newDocument();
final DOMResult result = new DOMResult(doc);
NormalizedNodeWriter normalizedNodeWriter = null;
NormalizedNodeStreamWriter normalizedNodeStreamWriter = null;
}
private static Document readXmlToDocument(final InputStream xmlContent) throws IOException, SAXException {
- final DocumentBuilder dBuilder;
- try {
- dBuilder = BUILDERFACTORY.newDocumentBuilder();
- } catch (final ParserConfigurationException e) {
- throw new RuntimeException("Failed to parse XML document", e);
- }
- final Document doc = dBuilder.parse(xmlContent);
-
+ final Document doc = UntrustedXML.newDocumentBuilder().parse(xmlContent);
doc.getDocumentElement().normalize();
return doc;
}
throw new RuntimeException("Unable to serialize xml element " + xml, e);
}
}
-
- private static Document getDocument() {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- Document doc = null;
- try {
- DocumentBuilder bob = dbf.newDocumentBuilder();
- doc = bob.newDocument();
- } catch (ParserConfigurationException e) {
- throw new RuntimeException(e);
- }
- return doc;
- }
}