Пример #1
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;
      }
    }
Пример #2
0
    public InputSource resolveEntity(String publicId, String systemId)
        throws SAXException, IOException {
      final InputSource is = new InputSource();
      is.setSystemId(systemId);
      is.setPublicId(publicId);
      final URL url = URLFactory.createURL(systemId);

      // Would be nice to support XML Catalogs or similar here. See:
      // http://xerces.apache.org/xerces2-j/faq-xcatalogs.html
      if (url.getProtocol().equals("http")) {
        logger.warn(
            "XML entity resolver for public id: "
                + publicId
                + " is accessing external entity via HTTP: "
                + url.toExternalForm());
      }

      is.setByteStream(url.openConnection().getInputStream());
      return is;
    }