Class SystemIdResolver

  • All Implemented Interfaces:
    EntityResolver, EntityResolver2

    public final class SystemIdResolver
    extends Object
    implements EntityResolver, EntityResolver2
    This is a helper class to support resolving of XIncludes or other hrefs inside XML files on top of a ResourceLoader. Just plug this class on top of a ResourceLoader and pass it as EntityResolver to SAX parsers or via wrapper methods as URIResolver to XSL transformers or XMLResolver to STAX parsers. The resolver handles special SystemIds with an URI scheme of solrres: that point to resources. To produce such systemIds when you initially call the parser, use createSystemIdFromResourceName(java.lang.String) which produces a SystemId that can be included along the InputStream coming from ResourceLoader.openResource(java.lang.String).

    In general create the InputSource to be passed to the parser like:

      InputSource is = new InputSource(loader.openSchema(name));
      final DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      db.setEntityResolver(new SystemIdResolver(loader));
      Document doc = db.parse(is);