KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > xml > JRXmlDigester


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28
29 /*
30  * Contributors:
31  * Artur Biesiadowski - abies@users.sourceforge.net
32  */

33 package net.sf.jasperreports.engine.xml;
34
35 import java.io.InputStream JavaDoc;
36 import java.net.URL JavaDoc;
37
38 import org.apache.commons.digester.Digester;
39 import org.xml.sax.InputSource JavaDoc;
40 import org.xml.sax.XMLReader JavaDoc;
41
42
43 /**
44  * @author Teodor Danciu (teodord@users.sourceforge.net)
45  * @version $Id: JRXmlDigester.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
46  */

47 public class JRXmlDigester extends Digester
48 {
49
50
51     /**
52      *
53      */

54     //private static boolean wasWarning = false;
55

56
57     /**
58      *
59      */

60     public JRXmlDigester()
61     {
62         super();
63     }
64
65
66     /**
67      *
68      */

69     public JRXmlDigester(XMLReader JavaDoc xmlReader)
70     {
71         super(xmlReader);
72     }
73
74
75     /**
76      *
77      */

78     public InputSource JavaDoc resolveEntity(
79         String JavaDoc pubId,
80         String JavaDoc systemId
81         )
82     {
83         InputSource JavaDoc inputSource = null;
84
85         if (systemId != null)
86         {
87             String JavaDoc dtd = null;
88             
89             if (
90                 systemId.equals("http://jasperreports.sourceforge.net/dtds/jasperreport.dtd") ||
91                 systemId.equals("http://www.jasperreports.com/dtds/jasperreport.dtd")
92                 )
93             {
94                 dtd = "net/sf/jasperreports/engine/dtds/jasperreport.dtd";
95             }
96             else if (
97                 systemId.equals("http://jasperreports.sourceforge.net/dtds/jasperprint.dtd") ||
98                 systemId.equals("http://www.jasperreports.com/dtds/jasperprint.dtd")
99                 )
100             {
101                 dtd = "net/sf/jasperreports/engine/dtds/jasperprint.dtd";
102             }
103             else
104             {
105                 return new InputSource JavaDoc(systemId);
106             }
107             
108
109             ClassLoader JavaDoc clsLoader = Thread.currentThread().getContextClassLoader();
110
111             URL JavaDoc url = null;
112             if (clsLoader != null)
113             {
114                 url = clsLoader.getResource(dtd);
115             }
116             if (url == null)
117             {
118                 //if (!wasWarning)
119
//{
120
// if (log.isWarnEnabled())
121
// log.warn("Failure using Thread.currentThread().getContextClassLoader() in JRXmlDigester class. Using JRXmlDigester.class.getClassLoader() instead.");
122
// wasWarning = true;
123
//}
124
clsLoader = JRXmlDigester.class.getClassLoader();
125             }
126             
127             InputStream JavaDoc is;
128             if (clsLoader == null)
129             {
130                 is = JRXmlDigester.class.getResourceAsStream("/" + dtd);
131             }
132             else
133             {
134                 is = clsLoader.getResourceAsStream(dtd);
135             }
136             
137             if (is != null)
138             {
139                 inputSource = new InputSource JavaDoc(is);
140             }
141         }
142
143         return inputSource;
144     }
145
146     
147 }
148
Popular Tags