KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > controller > config > DTDEntityResolver


1 package com.jdon.controller.config;
2
3 import java.net.URL JavaDoc;
4 import org.xml.sax.EntityResolver JavaDoc;
5 import org.xml.sax.SAXException JavaDoc;
6 import java.io.InputStream JavaDoc;
7 import java.io.IOException JavaDoc;
8 import org.xml.sax.InputSource JavaDoc;
9
10 public class DTDEntityResolver implements EntityResolver JavaDoc {
11   //~ Methods ////////////////////////////////////////////////////////////////
12

13   public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId) throws
14       SAXException JavaDoc, IOException JavaDoc {
15     if (systemId == null) {
16       return null;
17     }
18
19     URL JavaDoc url = new URL JavaDoc(systemId);
20     String JavaDoc file = url.getFile();
21
22     if ( (file != null) && (file.indexOf('/') > -1)) {
23       file = file.substring(file.lastIndexOf('/') + 1);
24     }
25
26     if ("www.jdon.com".equals(url.getHost())) {
27       InputStream JavaDoc is = getClass().getResourceAsStream("/META-INF/" + file);
28
29       if (is == null) {
30         is = getClass().getResourceAsStream("/" + file);
31       }
32
33       if (is != null) {
34         return new InputSource JavaDoc(is);
35       }
36     }
37
38     return null;
39   }
40 }
41
Popular Tags