Changeset 10087


Ignore:
Timestamp:
2005-06-14T11:09:41+12:00 (19 years ago)
Author:
kjdon
Message:

can now specify a class loader to use instead of the default - which is the class loader that loaded this class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSEntityResolver.java

    r8078 r10087  
    88
    99// uses a class loader to find entities
     10// The class loader to use can be set by setClassLoader(), otherwise it will use the class loader that loaded itself. For the Tomcat webapp, this will be the webapp class loader, not the system class loader. the webapp classloader knows about the classes in the WEB-INF/classes dir, the system classloader knows about the ones on the classpath. The system class loader is a parent to web app classloader, so this will be used as well.
     11
    1012public class GSEntityResolver implements EntityResolver {
    1113
     14    ClassLoader class_loader = null;
     15   
     16    public void setClassLoader(ClassLoader loader) {
     17    this.class_loader = loader;
     18    }
     19   
    1220    public InputSource resolveEntity (String public_id, String system_id) {
    1321   
     
    2634        }
    2735    }
    28    
    29     //System.out.println("using class loader for "+temp_id);
    30     URL url = ClassLoader.getSystemResource(temp_id);
     36    // try using a class loader
     37    if (this.class_loader==null) {
     38        this.class_loader = this.getClass().getClassLoader();
     39    }
     40    URL url = class_loader.getResource(temp_id);
    3141    if (url == null) {
    32         //System.out.println("class loader didn't find it");
    3342        return null;
    3443    }
    3544    return new InputSource("file://"+url.getFile());
    3645    }
    37 
    3846}
Note: See TracChangeset for help on using the changeset viewer.