1 18 package org.apache.batik.dom.svg; 19 20 import java.io.File ; 21 import java.net.URL ; 22 23 import org.w3c.dom.DOMImplementation ; 24 import org.w3c.dom.Document ; 25 import org.w3c.dom.Element ; 26 import org.w3c.dom.NamedNodeMap ; 27 import org.w3c.dom.Node ; 28 29 import org.apache.batik.test.AbstractTest; 30 import org.apache.batik.test.DefaultTestReport; 31 import org.apache.batik.test.TestReport; 32 import org.apache.batik.util.XMLResourceDescriptor; 33 34 40 public class ImportNodeTest extends AbstractTest { 41 protected String testFileName; 42 protected String targetId; 43 44 public ImportNodeTest(String file, String id) { 45 testFileName = file; 46 targetId = id; 47 } 48 49 public TestReport runImpl() throws Exception { 50 String parser = 51 XMLResourceDescriptor.getXMLParserClassName(); 52 53 SAXSVGDocumentFactory df = new SAXSVGDocumentFactory(parser); 54 55 File f = (new File (testFileName)); 56 URL url = f.toURL(); 57 Document doc = df.createDocument(url.toString(), 58 url.openStream()); 59 60 Element e = doc.getElementById(targetId); 61 62 if (e == null){ 63 DefaultTestReport report = new DefaultTestReport(this); 64 report.setErrorCode("error.get.element.by.id.failed"); 65 report.addDescriptionEntry("entry.key.id", targetId); 66 report.setPassed(false); 67 return report; 68 } 69 70 DOMImplementation di = SVGDOMImplementation.getDOMImplementation(); 71 Document d = di.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, 72 "svg", null); 73 74 75 Element celt = (Element )d.importNode(e, true); 76 77 NamedNodeMap attrs = e.getAttributes(); 78 79 for (int i = 0; i < attrs.getLength(); i++) { 80 Node attr = attrs.item(i); 81 String ns = attr.getNamespaceURI(); 82 String name = (ns == null) 83 ? attr.getNodeName() 84 : attr.getLocalName(); 85 String val = attr.getNodeValue(); 86 String val2 = celt.getAttributeNS(ns, name); 87 if (!val.equals(val2)) { 88 DefaultTestReport report = new DefaultTestReport(this); 89 report.setErrorCode("error.attr.comparison.failed"); 90 report.addDescriptionEntry("entry.attr.name", name); 91 report.addDescriptionEntry("entry.attr.value1", val); 92 report.addDescriptionEntry("entry.attr.value2", val2); 93 report.setPassed(false); 94 return report; 95 } 96 } 97 98 return reportSuccess(); 99 } 100 } 101 | Popular Tags |