source: trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSEntityResolver.java@ 5979

Last change on this file since 5979 was 5979, checked in by kjdon, 20 years ago

changed this completely

  • Property svn:keywords set to Author Date Id Revision
File size: 1.0 KB
Line 
1package org.greenstone.gsdl3.util;
2
3
4import org.xml.sax.InputSource;
5import org.xml.sax.EntityResolver;
6import java.io.File;
7import java.net.URL;
8
9// uses a class loader to find entities
10public class GSEntityResolver implements EntityResolver {
11
12 public InputSource resolveEntity (String public_id, String system_id) {
13
14 System.out.println("entity resolver for "+system_id);
15 String temp_id = system_id;
16 if (temp_id.startsWith("file://")) {
17 File f = new File(system_id);
18 if (f.exists()) {
19 return new InputSource(system_id);
20 } else {
21 temp_id = temp_id.substring(temp_id.lastIndexOf(File.separator)+1);
22 }
23 } else {
24 if (temp_id.indexOf(File.separatorChar)!= -1) {
25 temp_id = temp_id.substring(temp_id.lastIndexOf(File.separator)+1);
26 }
27 }
28
29 System.out.println("using class loader for "+temp_id);
30 URL url = ClassLoader.getSystemResource(temp_id);
31 if (url == null) {
32 System.out.println("class loader didn't find it");
33 return null;
34 }
35 return new InputSource("file://"+url.getFile());
36 }
37
38}
Note: See TracBrowser for help on using the repository browser.