Exemplo n.º 1
0
    /** 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);
      }
    }
Exemplo n.º 2
0
    // 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);
    }
Exemplo n.º 3
0
    /** 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;
      }
    }
Exemplo n.º 4
0
    // 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);
    }
Exemplo n.º 5
0
 public void registerCatalogEntry(String publicId, String uri) {
   if (id2uri == null) id2uri = new Hashtable(17);
   id2uri.put(publicId, uri);
 }