KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > loader > DTDEntityResolver


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.loader;
6
7 import org.xml.sax.EntityResolver JavaDoc;
8 import org.xml.sax.InputSource JavaDoc;
9 import org.xml.sax.SAXException JavaDoc;
10
11 import java.io.IOException JavaDoc;
12 import java.io.InputStream JavaDoc;
13
14 import java.net.URL JavaDoc;
15
16
17 /**
18  * @author Hani Suleiman (hani@formicary.net)
19  * Date: Sep 14, 2003
20  * Time: 4:25:40 PM
21  */

22 public class DTDEntityResolver implements EntityResolver JavaDoc {
23     //~ Methods ////////////////////////////////////////////////////////////////
24

25     public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId) throws SAXException JavaDoc, IOException JavaDoc {
26         if (systemId == null) {
27             return null;
28         }
29
30         URL JavaDoc url = new URL JavaDoc(systemId);
31         String JavaDoc file = url.getFile();
32
33         if ((file != null) && (file.indexOf('/') > -1)) {
34             file = file.substring(file.lastIndexOf('/') + 1);
35         }
36
37         if ("www.opensymphony.com".equals(url.getHost())) {
38             InputStream JavaDoc is = getClass().getResourceAsStream("/META-INF/" + file);
39
40             if (is == null) {
41                 is = getClass().getResourceAsStream("/" + file);
42             }
43
44             if (is != null) {
45                 return new InputSource JavaDoc(is);
46             }
47         }
48
49         return null;
50     }
51 }
52
Popular Tags