2
* Cobertura - http://cobertura.sourceforge.net/
4
* Copyright (C) 2005 Mark Doliner
6
* Cobertura is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published
8
* by the Free Software Foundation; either version 2 of the License,
9
* or (at your option) any later version.
11
* Cobertura is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with Cobertura; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22
package net.sourceforge.cobertura.reporting;
25
import java.io.FileInputStream;
26
import java.io.FileNotFoundException;
28
import org.xml.sax.InputSource;
29
import org.xml.sax.SAXException;
30
import org.xml.sax.helpers.DefaultHandler;
34
* This is a very simple XML EntityResolver. If
35
* you are parsing an XML document using a DocumentBuilder,
36
* and you set the DocumentBuilder's EntityResolver to an
37
* instance of this class, then we never attempt to resolve
38
* XML documents on the Internet. Instead we use a local
43
* This is done so that the XMLReportTest.java JUnit test will
44
* not fail when the test is run on a non-networked machine,
45
* or when webpages must be accessed through a proxy server.
48
public class JUnitXMLParserEntityResolver extends DefaultHandler
51
private final File DTD_DIRECTORY;
53
public JUnitXMLParserEntityResolver(File dtdDirectory)
55
this.DTD_DIRECTORY = dtdDirectory;
58
public InputSource resolveEntity(String publicId, String systemId)
61
System.out.println("systemId=" + systemId);
62
String systemIdBasename = systemId.substring(systemId.lastIndexOf('/'));
63
File localDtd = new File(this.DTD_DIRECTORY, systemIdBasename);
66
return new InputSource(new FileInputStream(localDtd));
68
catch (FileNotFoundException e)
70
System.out.println("Unable to open local DTD file "
71
+ localDtd.getAbsolutePath() + ", using " + systemId
75
InputSource source = null;
78
super.resolveEntity(publicId, systemId);
79
} catch (Exception exception) {
80
// apparently 1.5 throws an IOException here, but we can't catch it specifically if
81
// we're not on 1.5 (docs on both kind of say that they throw it)
82
// actual code on 1.4.2 has it remmed out so that it only throws SAXException
83
throw new SAXException(exception);