java.lang.Object | +--org.xml.sax.EntityResolver | +--org.xml.sax.ext.EntityResolver2All Implemented Interfaces:
org.xml.sax.InputSource | getExternalSubset(java.lang.String name, java.lang.String baseURI) Allows applications to provide an external subset for documents that don't explicitly define one. |
org.xml.sax.InputSource | resolveEntity(java.lang.String name, java.lang.String publicId, java.lang.String baseURI, java.lang.String systemId) Allows applications to map references to external entities into input sources, or tell the parser it should use conventional URI resolution. |
public InputSource getExternalSubset(java.lang.String name, java.lang.String baseURI)
This method can also be used with documents that have no DOCTYPE declaration. When the root element is encountered, but no DOCTYPE declaration has been seen, this method is invoked. If it returns a value for the external subset, that root element is declared to be the root element, giving the effect of splicing a DOCTYPE declaration at the end the prolog of a document that could not otherwise be valid. The sequence of parser callbacks in that case logically resembles this:
... comments and PIs from the prolog (as usual) startDTD ("rootName", source.getPublicId (), source.getSystemId ()); startEntity ("[dtd]"); ... declarations, comments, and PIs from the external subset endEntity ("[dtd]"); endDTD (); ... then the rest of the document (as usual) startElement (..., "rootName", ...);
Note that the InputSource gets no further resolution. Implementations of this method may wish to invoke #resolveEntity resolveEntity() to gain benefits such as use of local caches of DTD entities. Also, this method will never be used by a (non-validating) processor that is not including external parameter entities.
Uses for this method include facilitating data validation when interoperating with XML processors that would always require undesirable network accesses for external entities, or which for other reasons adopt a "no DTDs" policy. Non-validation motives include forcing documents to include DTDs so that attributes are handled consistently. For example, an XPath processor needs to know which attibutes have type "ID" before it can process a widely used type of reference.
Warning: Returning an external subset modifies the input document. By providing definitions for general entities, it can make a malformed document appear to be well formed.
name
- Identifies the document root element.baseURI
- The document's base URI, serving as an additional
hint for selecting the external subset.SAXException
- Any SAX exception, possibly wrapping
another exception.IOException
- Probably indicating a failure to create
a new InputStream or Reader, or an illegal URL.public InputSource resolveEntity(java.lang.String name, java.lang.String publicId, java.lang.String baseURI, java.lang.String systemId)
Parsers configured to use this resolver method will call it to determine the input source to use for any external entity being included because of a reference in the XML text. That excludes the document entity, and any external entity returned by #getExternalSubset getExternalSubset(). When a (non-validating) processor is configured not to include a class of entities (parameter or general) through use of feature flags, this method is not invoked for such entities.
Note that the entity naming scheme used here is the same one used in the LexicalHandler, or in the org.xml.sax.ContentHandler#skippedEntity ContentHandler.skippedEntity() method.
name
- Identifies the external entity being resolved.publicId
- The public identifier of the external entity being
referenced (normalized as required by the XML specification), or
null if none was supplied.baseURI
- The URI with respect to which relative systemIDs
are interpreted.systemId
- The system identifier of the external entity
being referenced; either a relative or absolute URI.SAXException
- Any SAX exception, possibly wrapping
another exception.IOException
- Probably indicating a failure to create
a new InputStream or Reader, or an illegal URL.
If a SAX application requires the customized handling which this interface defines for external entities, it must ensure that it uses an XMLReader with the http://xml.org/sax/features/use-entity-resolver2 feature flag set to true (which is its default value when the feature is recognized). If that flag is unrecognized, or its value is false, or the resolver does not implement this interface, then only the EntityResolver method will be used.
That supports three categories of application that modify entity resolution. Old Style applications won't know about this interface; they will provide an EntityResolver. Transitional Mode provide an EntityResolver2 and automatically get the benefit of its methods in any systems (parsers or other tools) supporting it, due to polymorphism. Both Old Style and Transitional Mode applications will work with any SAX2 parser. New style applications will fail to run except on SAX2 parsers that support this particular feature. They will insist that feature flag have a value of "true", and the EntityResolver2 implementation they provide might throw an exception if the original SAX 1.0 style entity resolution method is invoked.