001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028:
029: /*
030: * Contributors:
031: * Artur Biesiadowski - abies@users.sourceforge.net
032: */
033: package net.sf.jasperreports.engine.xml;
034:
035: import java.io.InputStream;
036: import java.net.URL;
037:
038: import org.apache.commons.digester.Digester;
039: import org.xml.sax.InputSource;
040: import org.xml.sax.XMLReader;
041:
042: /**
043: * @author Teodor Danciu (teodord@users.sourceforge.net)
044: * @version $Id: JRXmlDigester.java 1759 2007-06-20 16:47:34Z lucianc $
045: */
046: public class JRXmlDigester extends Digester {
047:
048: /**
049: *
050: */
051: //private static boolean wasWarning = false;
052:
053: /**
054: *
055: */
056: public JRXmlDigester() {
057: super ();
058: }
059:
060: /**
061: *
062: */
063: public JRXmlDigester(XMLReader xmlReader) {
064: super (xmlReader);
065: }
066:
067: /**
068: *
069: */
070: public InputSource resolveEntity(String pubId, String systemId) {
071: InputSource inputSource = null;
072:
073: if (systemId != null) {
074: String dtd = null;
075:
076: if (JRXmlConstants.JASPERREPORT_SYSTEM_ID.equals(systemId)) {
077: dtd = JRXmlConstants.JASPERREPORT_DTD;
078: } else if (JRXmlConstants.JASPERPRINT_SYSTEM_ID
079: .equals(systemId)) {
080: dtd = JRXmlConstants.JASPERPRINT_DTD;
081: } else if (JRXmlConstants.JASPERTEMPLATE_SYSTEM_ID
082: .equals(systemId)) {
083: dtd = JRXmlConstants.JASPERTEMPLATE_DTD;
084: } else {
085: return new InputSource(systemId);
086: }
087:
088: ClassLoader clsLoader = Thread.currentThread()
089: .getContextClassLoader();
090:
091: URL url = null;
092: if (clsLoader != null) {
093: url = clsLoader.getResource(dtd);
094: }
095: if (url == null) {
096: //if (!wasWarning)
097: //{
098: // if (log.isWarnEnabled())
099: // log.warn("Failure using Thread.currentThread().getContextClassLoader() in JRXmlDigester class. Using JRXmlDigester.class.getClassLoader() instead.");
100: // wasWarning = true;
101: //}
102: clsLoader = JRXmlDigester.class.getClassLoader();
103: }
104:
105: InputStream is;
106: if (clsLoader == null) {
107: is = JRXmlDigester.class.getResourceAsStream("/" + dtd);
108: } else {
109: is = clsLoader.getResourceAsStream(dtd);
110: }
111:
112: if (is != null) {
113: inputSource = new InputSource(is);
114: }
115: }
116:
117: return inputSource;
118: }
119:
120: }
|