1 21 22 package net.sourceforge.cobertura.reporting; 23 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.FileNotFoundException ; 27 28 import org.xml.sax.InputSource ; 29 import org.xml.sax.SAXException ; 30 import org.xml.sax.helpers.DefaultHandler ; 31 32 48 public class JUnitXMLParserEntityResolver extends DefaultHandler 49 { 50 51 private final File DTD_DIRECTORY; 52 53 public JUnitXMLParserEntityResolver(File dtdDirectory) 54 { 55 this.DTD_DIRECTORY = dtdDirectory; 56 } 57 58 public InputSource resolveEntity(String publicId, String systemId) 59 throws SAXException 60 { 61 System.out.println("systemId=" + systemId); 62 String systemIdBasename = systemId.substring(systemId.lastIndexOf('/')); 63 File localDtd = new File (this.DTD_DIRECTORY, systemIdBasename); 64 try 65 { 66 return new InputSource (new FileInputStream (localDtd)); 67 } 68 catch (FileNotFoundException e) 69 { 70 System.out.println("Unable to open local DTD file " 71 + localDtd.getAbsolutePath() + ", using " + systemId 72 + " instead."); 73 } 74 75 InputSource source = null; 76 77 try { 78 super.resolveEntity(publicId, systemId); 79 } catch (Exception exception) { 80 throw new SAXException (exception); 84 } 85 86 return source; 87 } 88 89 } 90 | Popular Tags |