KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > invicta > util > DTDEntityResolver


1 package net.sf.invicta.util;
2  
3 import java.io.IOException JavaDoc;
4 import java.net.URL JavaDoc;
5
6 import org.xml.sax.EntityResolver JavaDoc;
7 import org.xml.sax.InputSource JavaDoc;
8 import org.xml.sax.SAXException JavaDoc;
9
10 /**
11  * Resolver of DTD files referenced in XML files that finds the DTD
12  * files in the JVM CLASSPATH
13  *
14  */

15 public class DTDEntityResolver implements EntityResolver JavaDoc {
16
17     /**
18      *
19      */

20     public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId)
21         throws SAXException JavaDoc, IOException JavaDoc {
22         if (systemId.endsWith("dtd")) {
23             int lastSlash = systemId.lastIndexOf("/");
24             if (lastSlash >= 0)
25                 systemId = systemId.substring(lastSlash + 1);
26             URL JavaDoc url = ClassLoader.getSystemResource(systemId);
27             if (url == null) {
28                 return null;
29             }
30             return new InputSource JavaDoc(url.toString());
31         } else {
32             return null;
33         }
34     }
35
36 }
37
Popular Tags