/** Map publicid to a resource accessible by a classloader. */ public void registerCatalogEntry(String publicId, String resourceName, ClassLoader loader) { if (id2resource == null) id2resource = new Hashtable(17); id2resource.put(publicId, resourceName); if (loader != null) { if (id2loader == null) id2loader = new Hashtable(17); id2loader.put(publicId, loader); } }
// return the resource as a stream private InputStream mapResource(String publicId) { if (publicId == null || id2resource == null) return null; String resourceName = (String) id2resource.get(publicId); ClassLoader loader = null; if (resourceName == null) return null; if (id2loader != null) loader = (ClassLoader) id2loader.get(publicId); if (loader == null) return ClassLoader.getSystemResourceAsStream(resourceName); return loader.getResourceAsStream(resourceName); }
/** SAX entity resolver */ public InputSource resolveEntity(String name, String uri) throws IOException, SAXException { InputSource retval; String mappedURI = name2uri(name); InputStream stream = mapResource(name); // prefer explicit URI mappings, then bundled resources... if (mappedURI != null) { retval = new InputSource(mappedURI); retval.setPublicId(name); return retval; } else if (stream != null) { uri = "java:resource:" + (String) id2resource.get(name); // NOI18N retval = new InputSource(stream); retval.setPublicId(name); return retval; } else { return null; } }
// maps the public ID to an alternate URI, if one is registered private String name2uri(String publicId) { if (publicId == null || id2uri == null) return null; return (String) id2uri.get(publicId); }
public void registerCatalogEntry(String publicId, String uri) { if (id2uri == null) id2uri = new Hashtable(17); id2uri.put(publicId, uri); }