1 18 package org.apache.batik.dom; 19 20 import org.w3c.dom.*; 21 22 import java.io.*; 23 import java.net.*; 24 import org.apache.batik.dom.util.*; 25 import org.apache.batik.util.*; 26 27 import org.apache.batik.test.*; 28 29 35 public class HasChildNodesTest extends AbstractTest { 36 public static String ERROR_GET_ELEMENT_BY_ID_FAILED 37 = "error.get.element.by.id.failed"; 38 39 public static String ENTRY_KEY_ID 40 = "entry.key.id"; 41 42 protected String testFileName; 43 protected String rootTag; 44 protected String targetId; 45 46 public HasChildNodesTest(String file, 47 String root, 48 String id) { 49 testFileName = file; 50 rootTag = root; 51 targetId = id; 52 } 53 54 public TestReport runImpl() throws Exception { 55 String parser = 56 XMLResourceDescriptor.getXMLParserClassName(); 57 58 DocumentFactory df 59 = new SAXDocumentFactory 60 (GenericDOMImplementation.getDOMImplementation(), parser); 61 62 File f = (new File(testFileName)); 63 URL url = f.toURL(); 64 Document doc = df.createDocument(null, 65 rootTag, 66 url.toString(), 67 url.openStream()); 68 69 70 Element e = doc.getElementById(targetId); 71 72 if (e == null){ 73 DefaultTestReport report = new DefaultTestReport(this); 74 report.setErrorCode(ERROR_GET_ELEMENT_BY_ID_FAILED); 75 report.addDescriptionEntry(ENTRY_KEY_ID, 76 targetId); 77 report.setPassed(false); 78 return report; 79 } 80 81 while (e.hasChildNodes()) { 82 e.removeChild(e.getFirstChild()); 83 } 84 85 return reportSuccess(); 86 } 87 } 88 | Popular Tags |