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 RemoveAttributeTest 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 protected String targetAttr; 46 47 public RemoveAttributeTest(String file, 48 String root, 49 String id, 50 String attr) { 51 testFileName = file; 52 rootTag = root; 53 targetId = id; 54 targetAttr = attr; 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 try { 85 e.removeAttribute(targetAttr); 86 } catch (DOMException ex) { 87 DefaultTestReport report = new DefaultTestReport(this); 88 report.setErrorCode(TestReport.ERROR_TEST_FAILED); 89 report.addDescriptionEntry("exception.message", 90 ex.getMessage()); 91 report.setPassed(false); 92 return report; 93 } 94 return reportSuccess(); 95 } 96 } 97 | Popular Tags |