Class XercesResolver

  • All Implemented Interfaces:
    javax.xml.transform.URIResolver, org.apache.xerces.xni.parser.XMLEntityResolver, org.w3c.dom.ls.LSResourceResolver, org.xml.sax.EntityResolver, org.xml.sax.ext.EntityResolver2, NamespaceResolver

    public class XercesResolver
    extends Resolver
    implements org.apache.xerces.xni.parser.XMLEntityResolver
    An extension of the Resolver that implements Xerces XMLEntityResolver.

    This is a separate class so that the depenency on Xerces can remain optional. You must have Xerces on your classpath to load this class, obviously. You must also explicitly configure the underlying XMLReader to use this resolver:

    xmlReader.setProperty("http://apache.org/xml/properties/internal/entity-resolver", resolver);

    This API relies on the input to the resolveEntity(XMLEntityDescription) method to work out what to resolve. If this API is in use, Xerces doesn't use any of the other resolver APIs.

    • Constructor Detail

      • XercesResolver

        public XercesResolver()
        Create a new XercesResolver.
      • XercesResolver

        public XercesResolver​(XMLResolverConfiguration config)
        Create a new XercesResolver with a particular configuration.
        Parameters:
        config - the configuration
      • XercesResolver

        public XercesResolver​(CatalogResolver resolver)
        Create a new XercesResolver with a particular catalog resolver.
        Parameters:
        resolver - the catalog resolver
    • Method Detail

      • resolveEntity

        public org.apache.xerces.xni.parser.XMLInputSource resolveEntity​(org.apache.xerces.xni.XMLResourceIdentifier resId)
        Resolve an entity.

        How the resolver functions depends on what subclass of XMLResourceIdentifier is passed in:

        XMLDTDDescription
        Identifies an attept to load a DTD.
        XMLEntityDescription
        Identifies an attept to load an entity (a parameter or general entity in the internal or external subset).
        XSDDescription
        Identifies an attept to load an XML Schema.

        If some other class is passed in, the method does its best. But if there are other possibilities, the code should really be extended to handle them explicitly.

        For Schema lookup, it's worth noting that the behavior is slightly different depending on whether or not a "system identifier" is provided for the schema. This can occur in two different ways: if the document author provides a schema location hint, that is provided as the system identifier for the schema. If the schema being resolved is being included or imported into another schema, then the href of the xs:import or xs:include is the "system identifier".

        If a schema location is provided, the method attempt to resolve it as a URI. In this case, it will not lookup the schema with its namespace. This is to prevent the case where an included or imported module is 404. If that fell back to using the namespace, you would create a loop.

        If the schema location is not provided, the namespace resolver API is used to find the schema.

        Specified by:
        resolveEntity in interface org.apache.xerces.xni.parser.XMLEntityResolver
        Parameters:
        resId - the resource identifier
        Returns:
        a resolved source, or null if none was found