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, 21 years ago

changed this completely

  • Property svn:keywords set to Author Date Id Revision
File size: 1.0 KB
RevLine 
[5433]1package org.greenstone.gsdl3.util;
2
3
4import org.xml.sax.InputSource;
5import org.xml.sax.EntityResolver;
6import java.io.File;
[5962]7import java.net.URL;
[5434]8
[5962]9// uses a class loader to find entities
[5433]10public class GSEntityResolver implements EntityResolver {
11
12 public InputSource resolveEntity (String public_id, String system_id) {
[5962]13
14 System.out.println("entity resolver for "+system_id);
[5979]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);
[5433]22 }
[5962]23 } else {
[5979]24 if (temp_id.indexOf(File.separatorChar)!= -1) {
25 temp_id = temp_id.substring(temp_id.lastIndexOf(File.separator)+1);
26 }
[5962]27 }
[5979]28
29 System.out.println("using class loader for "+temp_id);
30 URL url = ClassLoader.getSystemResource(temp_id);
[5962]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());
[5433]36 }
[5979]37
[5433]38}
Note: See TracBrowser for help on using the repository browser.