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 AppendChildTest extends AbstractTest { 36 public static String ERROR_GET_ELEMENT_BY_ID_FAILED 37 = "error.get.element.by.id.failed"; 38 39 public static String ERROR_EXCEPTION_NOT_THROWN 40 = "error.exception.not.thrown"; 41 42 public static String ENTRY_KEY_ID 43 = "entry.key.id"; 44 45 protected String testFileName; 46 protected String rootTag; 47 protected String targetId; 48 49 public AppendChildTest(String file, 50 String root, 51 String id) { 52 testFileName = file; 53 rootTag = root; 54 targetId = id; 55 } 56 57 public TestReport runImpl() throws Exception { 58 String parser = 59 XMLResourceDescriptor.getXMLParserClassName(); 60 61 DocumentFactory df 62 = new SAXDocumentFactory 63 (GenericDOMImplementation.getDOMImplementation(), parser); 64 65 File f = (new File(testFileName)); 66 URL url = f.toURL(); 67 Document doc = df.createDocument(null, 68 rootTag, 69 url.toString(), 70 url.openStream()); 71 72 73 Element e = doc.getElementById(targetId); 74 75 if (e == null){ 76 DefaultTestReport report = new DefaultTestReport(this); 77 report.setErrorCode(ERROR_GET_ELEMENT_BY_ID_FAILED); 78 report.addDescriptionEntry(ENTRY_KEY_ID, 79 targetId); 80 report.setPassed(false); 81 return report; 82 } 83 84 Document otherDocument = df.createDocument(null, 85 rootTag, 86 url.toString(), 87 url.openStream()); 88 89 DocumentFragment docFrag = otherDocument.createDocumentFragment(); 90 try { 91 docFrag.appendChild(doc.getDocumentElement()); 92 } catch (DOMException ex) { 93 return reportSuccess(); 94 } 95 96 DefaultTestReport report = new DefaultTestReport(this); 97 report.setErrorCode(ERROR_EXCEPTION_NOT_THROWN); 98 report.setPassed(false); 99 return report; 100 } 101 } 102 | Popular Tags |