1 28 29 33 package net.sf.jasperreports.engine.xml; 34 35 import java.io.InputStream ; 36 import java.net.URL ; 37 38 import org.apache.commons.digester.Digester; 39 import org.xml.sax.InputSource ; 40 import org.xml.sax.XMLReader ; 41 42 43 47 public class JRXmlDigester extends Digester 48 { 49 50 51 54 56 57 60 public JRXmlDigester() 61 { 62 super(); 63 } 64 65 66 69 public JRXmlDigester(XMLReader xmlReader) 70 { 71 super(xmlReader); 72 } 73 74 75 78 public InputSource resolveEntity( 79 String pubId, 80 String systemId 81 ) 82 { 83 InputSource inputSource = null; 84 85 if (systemId != null) 86 { 87 String 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 (systemId); 106 } 107 108 109 ClassLoader clsLoader = Thread.currentThread().getContextClassLoader(); 110 111 URL url = null; 112 if (clsLoader != null) 113 { 114 url = clsLoader.getResource(dtd); 115 } 116 if (url == null) 117 { 118 clsLoader = JRXmlDigester.class.getClassLoader(); 125 } 126 127 InputStream 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 (is); 140 } 141 } 142 143 return inputSource; 144 } 145 146 147 } 148 | Popular Tags |