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.Document ; 24 import org.w3c.dom.Element ; 25 import org.w3c.dom.NamedNodeMap ; 26 import org.w3c.dom.Node ; 27 28 import org.apache.batik.test.AbstractTest; 29 import org.apache.batik.test.DefaultTestReport; 30 import org.apache.batik.test.TestReport; 31 import org.apache.batik.util.XMLResourceDescriptor; 32 33 34 40 public class CloneNodeTest extends AbstractTest { 41 protected String testFileName; 42 protected String targetId; 43 44 public CloneNodeTest(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 Element celt = (Element )e.cloneNode(true); 71 72 NamedNodeMap attrs = e.getAttributes(); 73 74 for (int i = 0; i < attrs.getLength(); i++) { 75 Node attr = attrs.item(i); 76 String ns = attr.getNamespaceURI(); 77 String name = (ns == null) 78 ? attr.getNodeName() 79 : attr.getLocalName(); 80 String val = attr.getNodeValue(); 81 String val2 = celt.getAttributeNS(ns, name); 82 if (!val.equals(val2)) { 83 DefaultTestReport report = new DefaultTestReport(this); 84 report.setErrorCode("error.attr.comparison.failed"); 85 report.addDescriptionEntry("entry.attr.name", name); 86 report.setPassed(false); 87 return report; 88 } 89 } 90 91 return reportSuccess(); 92 } 93 } 94 | Popular Tags |