Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

EntityListResolver



The EntityListResolver class manage entity resolution in XML files. It implements all the following interfaces: This class offer a framework to resolve resources encountered in XML files (including XML Schemas).

Note that this class is able to resolve sibling entities of an entity which has been resolved. For example, if the following systemID is resolved:
  • "http://location/refXSD.xsd" => "D:/myFiles/schemas/refXSD.xsd"
Then upon encountering the following entity (for example referred to in refXSD.xsd):
  • "http://location/childSchema.xsd"
The resolver will look for the following resource:
  • "D:/myFiles/schemas/childSchema.xsd"

Caching resources

By default the resolver does not cache aleady resolved entities or resources. However it is possible to set the resolver to cache them by setting the EntityListResolver.cacheSources(boolean).

Note that you can configure this behavior in the XMLSAXParser or the ResolverSAXHandler by setting the InputSourceCaching.setInputSourceCaching(short):
By default the EntityListResolver will not cache the resources or entities.

Overriding the resolver behavior

There are several ways to override the behavior of the resolver:

Overriding the interfaces implemented methods

There are several interfaces implemented methods whihc can be overriden:

Overriding the resolveURI method

The EntityListResolver.resolveURI(String) method is called to get the actual systemId or baseURI, from the ones provided in each methods which use a systemId or baseURI.

The default implementation of the method just return the input String, but it is possible to override this method, for example to interpret a symbolic link to get to the actual URI. For example:

Example

Let's define an XMLSAXParser:
   EntityListResolver resolver = new EntityListResolver();
   URL xsd = new URL(<URL of an XSD>);
   resolver.addResolvedSystemID("http://location/refXSD.xsd", xsd);

   XMLSAXParser parser = new XMLSAXParser();
   parser.setEntityListResolver(resolver);
During the parsing of an XML file:
  • Schema locations with a "http://location/refXSD.xsd" location will be resolved to the specified XSD
  • XML inclusions with a "http://location/refXSD.xsd" location will be resolved to the specified XSD

Notes

  1. ^ Which means that if a resource or entity has been already encountered and produced an InputSource, the resulting InputSource will be reused of possible, regardless of how the associated EntityListResolver.cacheSources(boolean) has been configured
  2. ^ Which means that if a resource or entity will always produce a new InputSource, regardless of how the associated EntityListResolver.cacheSources(boolean) has been configured

See also


Categories: packages | xml

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences