public TestReport runImpl() throws Exception { Handler h = new Handler(); TestReport report = null; // cdata-sections == false Document doc = newSVGDoc(); DOMConfiguration conf = ((AbstractDocument) doc).getDomConfig(); conf.setParameter("cdata-sections", Boolean.FALSE); Element e = doc.getDocumentElement(); e.appendChild(doc.createTextNode("abc")); e.appendChild(doc.createCDATASection("def")); e.appendChild(doc.createTextNode("ghi")); ((AbstractDocument) doc).normalizeDocument(); if (!(e.getFirstChild().getNodeType() == Node.TEXT_NODE && e.getFirstChild().getNodeValue().equals("abcdefghi") && e.getFirstChild() == e.getLastChild())) { if (report == null) { report = reportError("Document.normalizeDocument test failed"); } report.addDescriptionEntry("DOMConfiguration parameter", "cdata-sections == false"); } // comments == false doc = newSVGDoc(); conf = ((AbstractDocument) doc).getDomConfig(); conf.setParameter("comments", Boolean.FALSE); e = doc.getDocumentElement(); e.appendChild(doc.createTextNode("abc")); e.appendChild(doc.createComment("def")); e.appendChild(doc.createTextNode("ghi")); ((AbstractDocument) doc).normalizeDocument(); if (!(e.getFirstChild().getNodeType() == Node.TEXT_NODE && e.getFirstChild().getNodeValue().equals("abcghi") && e.getFirstChild() == e.getLastChild())) { if (report == null) { report = reportError("Document.normalizeDocument test failed"); } report.addDescriptionEntry("DOMConfiguration parameter", "comments == false"); } // element-content-whitespace == false doc = newSVGDoc(); conf = ((AbstractDocument) doc).getDomConfig(); conf.setParameter("element-content-whitespace", Boolean.FALSE); e = doc.getDocumentElement(); e.appendChild(doc.createTextNode(" ")); e.appendChild(doc.createElementNS(SVG_NAMESPACE_URI, "g")); e.appendChild(doc.createTextNode(" ")); ((AbstractDocument) doc).normalizeDocument(); if (!(e.getFirstChild().getNodeType() == Node.ELEMENT_NODE && e.getFirstChild().getNodeName().equals("g") && e.getFirstChild() == e.getLastChild())) { if (report == null) { report = reportError("Document.normalizeDocument test failed"); } report.addDescriptionEntry( "DOMConfiguration parameter", "element-content-whitespace == false"); } // split-cdata-sections == true doc = newSVGDoc(); conf = ((AbstractDocument) doc).getDomConfig(); conf.setParameter("split-cdata-sections", Boolean.TRUE); conf.setParameter("error-handler", h); e = doc.getDocumentElement(); e.appendChild(doc.createCDATASection("before ]]> after")); ((AbstractDocument) doc).normalizeDocument(); if (!(e.getFirstChild().getNodeType() == Node.CDATA_SECTION_NODE && e.getFirstChild().getNodeValue().equals("before ]]") && e.getFirstChild().getNextSibling().getNodeType() == Node.CDATA_SECTION_NODE && e.getFirstChild().getNextSibling().getNodeValue().equals("> after") && e.getFirstChild().getNextSibling() == e.getLastChild() && h.get("cdata-sections-splitted") == 1)) { if (report == null) { report = reportError("Document.normalizeDocument test failed"); } report.addDescriptionEntry("DOMConfiguration parameter", "split-cdata-sections == true"); } // well-formed doc = newSVGDoc(); ((AbstractDocument) doc).setStrictErrorChecking(false); conf = ((AbstractDocument) doc).getDomConfig(); conf.setParameter("error-handler", h); e = doc.getDocumentElement(); e.appendChild(doc.createComment("before -- after")); e.appendChild(doc.createComment("ends in a dash -")); e.setAttribute("*", "blah"); e.appendChild(doc.createProcessingInstruction("abc", "def?>")); ((AbstractDocument) doc).normalizeDocument(); if (!(h.get("wf-invalid-character-in-node-name") == 1 && h.get("wf-invalid-character") == 3)) { if (report == null) { report = reportError("Document.normalizeDocument test failed"); } report.addDescriptionEntry("DOMConfiguration parameter", "well-formed == true"); } // namespaces doc = newDoc(); e = doc.createElementNS(null, "root"); doc.appendChild(e); Element e2 = doc.createElementNS(null, "parent"); e.appendChild(e2); e2.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:ns", "http://www.example.org/ns1"); e2.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:bar", "http://www.example.org/ns2"); Element e3 = doc.createElementNS("http://www.example.org/ns1", "ns:child1"); e2.appendChild(e3); e3.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:ns", "http://www.example.org/ns2"); e3 = doc.createElementNS("http://www.example.org/ns2", "ns:child2"); e2.appendChild(e3); ((AbstractDocument) doc).normalizeDocument(); Attr a = e3.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "ns"); if (!(a != null && a.getNodeName().equals("xmlns:ns") && a.getNodeValue().equals("http://www.example.org/ns2"))) { if (report == null) { report = reportError("Document.normalizeDocument test failed"); } report.addDescriptionEntry("DOMConfiguration parameter", "namespaces == true, test 1"); } doc = newDoc(); e = doc.createElementNS(null, "root"); doc.appendChild(e); e2 = doc.createElementNS("http://www.example.org/ns1", "ns:child1"); e.appendChild(e2); e2.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:ns", "http://www.example.org/ns1"); e3 = doc.createElementNS("http://www.example.org/ns1", "ns:child2"); e2.appendChild(e3); e2 = (Element) ((AbstractDocument) doc).renameNode(e2, "http://www.example.org/ns2", "ns:child1"); ((AbstractDocument) doc).normalizeDocument(); a = e2.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "ns"); Attr a2 = e3.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "ns"); if (!(a != null && a.getNodeName().equals("xmlns:ns") && a.getNodeValue().equals("http://www.example.org/ns2") && a2 != null && a2.getNodeName().equals("xmlns:ns") && a2.getNodeValue().equals("http://www.example.org/ns1"))) { if (report == null) { report = reportError("Document.normalizeDocument test failed"); } report.addDescriptionEntry("DOMConfiguration parameter", "namespaces == true, test 2"); } doc = newDoc(); e = doc.createElementNS(null, "root"); doc.appendChild(e); e2 = doc.createElementNS("http://www.example.org/ns1", "child1"); e.appendChild(e2); e2.setAttributeNS("http://www.example.org/ns2", "blah", "hi"); ((AbstractDocument) doc).normalizeDocument(); a = e2.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "xmlns"); a2 = e2.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "NS1"); if (!(a != null && a.getNodeValue().equals("http://www.example.org/ns1") && a2 != null && a2.getNodeValue().equals("http://www.example.org/ns2"))) { if (report == null) { report = reportError("Document.normalizeDocument test failed"); } report.addDescriptionEntry("DOMConfiguration parameter", "namespaces == true, test 3"); } // namespace-declarations == false doc = newDoc(); e = doc.createElementNS(null, "ex:root"); e.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:ex", "http://www.example.org/ns1"); conf = ((AbstractDocument) doc).getDomConfig(); conf.setParameter("namespace-declarations", Boolean.FALSE); doc.appendChild(e); ((AbstractDocument) doc).normalizeDocument(); if (!(e.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "ex") == null)) { if (report == null) { report = reportError("Document.normalizeDocument test failed"); } report.addDescriptionEntry("DOMConfiguration parameter", "namespace-declarations == false"); } if (report == null) { return reportSuccess(); } return report; }