| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Cobertura example source code file (

This example Cobertura source code file ( is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Cobertura tags/keywords

defaulthandler, dtd_directory, exception, file, file, fileinputstream, filenotfoundexception, inputsource, inputsource, io, junitxmlparserentityresolver, junitxmlparserentityresolver, sax, saxexception, saxexception, string

The Cobertura source code

 * Cobertura -
 * Copyright (C) 2005 Mark Doliner
 * Cobertura is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 * Cobertura is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Cobertura; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA

package net.sourceforge.cobertura.reporting;


import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

 * <p>
 * This is a very simple XML EntityResolver.  If
 * you are parsing an XML document using a DocumentBuilder,
 * and you set the DocumentBuilder's EntityResolver to an
 * instance of this class, then we never attempt to resolve
 * XML documents on the Internet.  Instead we use a local
 * copy of the DTD.
 * </p>
 * <p>
 * This is done so that the JUnit test will
 * not fail when the test is run on a non-networked machine,
 * or when webpages must be accessed through a proxy server.
 * </p>
public class JUnitXMLParserEntityResolver extends DefaultHandler

	private final File DTD_DIRECTORY;

	public JUnitXMLParserEntityResolver(File dtdDirectory)
		this.DTD_DIRECTORY = dtdDirectory;

	public InputSource resolveEntity(String publicId, String systemId)
			throws SAXException
		System.out.println("systemId=" + systemId);
		String systemIdBasename = systemId.substring(systemId.lastIndexOf('/'));
		File localDtd = new File(this.DTD_DIRECTORY, systemIdBasename);
			return new InputSource(new FileInputStream(localDtd));
		catch (FileNotFoundException e)
			System.out.println("Unable to open local DTD file "
					+ localDtd.getAbsolutePath() + ", using " + systemId
					+ " instead.");

		InputSource source = null;

		try {
			super.resolveEntity(publicId, systemId);
		} catch (Exception exception) {
			// apparently 1.5 throws an IOException here, but we can't catch it specifically if
			//	we're not on 1.5 (docs on both kind of say that they throw it)
			//	actual code on 1.4.2 has it remmed out so that it only throws SAXException  
			throw new SAXException(exception);

		return source;


Other Cobertura examples (source code examples)

Here is a short list of links related to this Cobertura source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.