Top Description Fields Constructors Methods
org.apache.xerces.util

public Class XMLCatalogResolver

extends Object
implements XMLEntityResolver, EntityResolver2, LSResourceResolver
Class Inheritance
All Implemented Interfaces
org.w3c.dom.ls.LSResourceResolver, org.xml.sax.ext.EntityResolver2, org.xml.sax.EntityResolver, org.apache.xerces.xni.parser.XMLEntityResolver
Imports
java.io.IOException, javax.xml.parsers.SAXParserFactory, org.apache.xerces.dom.DOMInputImpl, org.apache.xerces.jaxp.SAXParserFactoryImpl, org.apache.xerces.xni.XMLResourceIdentifier, .XNIException, org.apache.xerces.xni.parser.XMLEntityResolver, .XMLInputSource, org.apache.xml.resolver.Catalog, .CatalogManager, org.apache.xml.resolver.readers.OASISXMLCatalogReader, .SAXCatalogReader, org.w3c.dom.ls.LSInput, .LSResourceResolver, org.xml.sax.InputSource, .SAXException, org.xml.sax.ext.EntityResolver2

The catalog resolver handles the resolution of external identifiers and URI references through XML catalogs. This component supports XML catalogs defined by the OASIS XML Catalogs Specification. It encapsulates the XML Commons resolver. An instance of this class may be registered on the parser as a SAX entity resolver, as a DOM LSResourceResolver or as an XNI entity resolver by setting the property (http://apache.org/xml/properties/internal/entity-resolver).

It is intended that this class may be used standalone to perform catalog resolution outside of a parsing context. It may be shared between several parsers and the application.

Author
Michael Glavassevich, IBM
Version
$Id: XMLCatalogResolver.java 699892 2008-09-28 21:08:27Z mrglavas $

Field Summary

Modifier and TypeField and Description
private Catalog
fCatalog

Internal catalog structure.

private boolean
fCatalogsChanged

Indicates whether the list of catalogs has changed since it was processed.

private String[]
fCatalogsList

An array of catalog URIs.

private boolean
fPreferPublic

Application specified prefer public setting.

private CatalogManager
fResolverCatalogManager

Internal catalog manager for Apache catalogs.

private boolean
fUseLiteralSystemId

Indicates whether the application desires that the parser or some other component performing catalog resolution should use the literal system identifier instead of the expanded system identifier.

Constructor Summary

AccessConstructor and Description
public
XMLCatalogResolver()

Constructs a catalog resolver with a default configuration.

public
XMLCatalogResolver(String[]
an ordered array list of absolute URIs
catalogs
)

Constructs a catalog resolver with the given list of entry files.

public
XMLCatalogResolver(String[]
an ordered array list of absolute URIs
catalogs
,
boolean
the prefer public setting
preferPublic
)

Constructs a catalog resolver with the given list of entry files and the preference for whether system or public matches are preferred.

Method Summary

Modifier and TypeMethod and Description
private void
attachReaderToCatalog(Catalog catalog)

Attaches the reader to the catalog.

public final synchronized void
clear()

Forces the cache of catalog mappings to be cleared.

public final synchronized String[]

Returns:

the initial list of catalog entry files
getCatalogList
()

Returns the initial list of catalog entry files.

public InputSource
getExternalSubset(String
the identifier of the document root element
name
,
String
the document's base URI
baseURI
)

Implements org.xml.sax.ext.EntityResolver2.getExternalSubset.

Locates an external subset for documents which do not explicitly provide one.

public final boolean

Returns:

the prefer public setting
getPreferPublic
()

Returns the preference for whether system or public matches are preferred.

public final boolean

Returns:

the preference for using literal system identifiers for catalog resolution
getUseLiteralSystemId
()

Returns the preference for whether the literal system identifier should be used when resolving system identifiers when both it and the expanded system identifier are available.

private void
init(String[] catalogs, boolean preferPublic)

Initialization.

private void
parseCatalogs()

Instruct the Catalog to parse each of the catalogs in the list.

public InputSource
resolveEntity(String
the public identifier, or null if none was supplied
publicId
,
String
the system identifier
systemId
)

Implements org.xml.sax.EntityResolver.resolveEntity.

Resolves an external entity.

public InputSource
resolveEntity(String
the identifier of the external entity
name
,
String
the public identifier, or null if none was supplied
publicId
,
String
the URI with respect to which relative systemIDs are interpreted.
baseURI
,
String
the system identifier
systemId
)

Implements org.xml.sax.ext.EntityResolver2.resolveEntity.

Resolves an external entity.

public XMLInputSource
resolveEntity(XMLResourceIdentifier
location of the XML resource to resolve
resourceIdentifier
)

Implements org.apache.xerces.xni.parser.XMLEntityResolver.resolveEntity.

Resolves an external entity.

public String
resolveIdentifier(XMLResourceIdentifier
the identifier to resolve
resourceIdentifier
)

Resolves an identifier using the catalog.

public final synchronized String

Returns:

the mapped URI or null if no mapping was found in the catalog
resolvePublic
(String
the public identifier to locate in the catalog
publicId
,
String
the system identifier to locate in the catalog
systemId
)

Returns the URI mapping in the catalog for the given external identifier or null if no mapping exists.

public LSInput
resolveResource(String
the type of the resource being resolved
type
,
String
the namespace of the resource being resolved, or null if none was supplied
namespaceURI
,
String
the public identifier of the resource being resolved, or null if none was supplied
publicId
,
String
the system identifier of the resource being resolved, or null if none was supplied
systemId
,
String
the absolute base URI of the resource being parsed, or null if there is no base URI
baseURI
)

Implements org.w3c.dom.ls.LSResourceResolver.resolveResource.

Resolves a resource using the catalog.

public final synchronized String

Returns:

the mapped URI or null if no mapping was found in the catalog
resolveSystem
(String
the system identifier to locate in the catalog
systemId
)

Returns the URI mapping in the catalog for the given external identifier or null if no mapping exists.

public final synchronized String

Returns:

the mapped URI or null if no mapping was found in the catalog
resolveURI
(String
the URI to locate in the catalog
uri
)

Returns the URI mapping in the catalog for the given URI reference or null if no mapping exists.

public final synchronized void
setCatalogList(String[]
an ordered array list of absolute URIs
catalogs
)

Sets the initial list of catalog entry files.

public final void
setPreferPublic(boolean
the prefer public setting
preferPublic
)

Sets the preference for whether system or public matches are preferred.

public final void
setUseLiteralSystemId(boolean
the preference for using literal system identifiers for catalog resolution
useLiteralSystemId
)

Sets the preference for whether the literal system identifier should be used when resolving system identifiers when both it and the expanded system identifier are available.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fCatalogback to summary
private Catalog fCatalog

Internal catalog structure.

fCatalogsChangedback to summary
private boolean fCatalogsChanged

Indicates whether the list of catalogs has changed since it was processed.

fCatalogsListback to summary
private String[] fCatalogsList

An array of catalog URIs.

fPreferPublicback to summary
private boolean fPreferPublic

Application specified prefer public setting.

fResolverCatalogManagerback to summary
private CatalogManager fResolverCatalogManager

Internal catalog manager for Apache catalogs.

fUseLiteralSystemIdback to summary
private boolean fUseLiteralSystemId

Indicates whether the application desires that the parser or some other component performing catalog resolution should use the literal system identifier instead of the expanded system identifier.

Constructor Detail

XMLCatalogResolverback to summary
public XMLCatalogResolver()

Constructs a catalog resolver with a default configuration.

XMLCatalogResolverback to summary
public XMLCatalogResolver(String[] catalogs)

Constructs a catalog resolver with the given list of entry files.

Parameters
catalogs:String[]

an ordered array list of absolute URIs

XMLCatalogResolverback to summary
public XMLCatalogResolver(String[] catalogs, boolean preferPublic)

Constructs a catalog resolver with the given list of entry files and the preference for whether system or public matches are preferred.

Parameters
catalogs:String[]

an ordered array list of absolute URIs

preferPublic:boolean

the prefer public setting

Method Detail

attachReaderToCatalogback to summary
private void attachReaderToCatalog(Catalog catalog)

Attaches the reader to the catalog.

clearback to summary
public final synchronized void clear()

Forces the cache of catalog mappings to be cleared.

getCatalogListback to summary
public final synchronized String[] getCatalogList()

Returns the initial list of catalog entry files.

Returns:String[]

the initial list of catalog entry files

getExternalSubsetback to summary
public InputSource getExternalSubset(String name, String baseURI) throws SAXException, IOException

Implements org.xml.sax.ext.EntityResolver2.getExternalSubset.

Locates an external subset for documents which do not explicitly provide one. This method always returns null. It should be overrided if other behaviour is required.

Parameters
name:String

the identifier of the document root element

baseURI:String

the document's base URI

Returns:InputSource

Doc from org.xml.sax.ext.EntityResolver2.getExternalSubset.

An InputSource object describing the new external subset to be used by the parser, or null to indicate that no external subset is provided.

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
IOException:
thrown if some i/o error occurs
getPreferPublicback to summary
public final boolean getPreferPublic()

Returns the preference for whether system or public matches are preferred. This is used in the absence of any occurrence of the prefer attribute on the catalog entry of a catalog. If this property has not yet been explicitly set its value is true.

Returns:boolean

the prefer public setting

getUseLiteralSystemIdback to summary
public final boolean getUseLiteralSystemId()

Returns the preference for whether the literal system identifier should be used when resolving system identifiers when both it and the expanded system identifier are available. If this property has not yet been explicitly set its value is true.

Returns:boolean

the preference for using literal system identifiers for catalog resolution

See Also
setUseLiteralSystemId
initback to summary
private void init(String[] catalogs, boolean preferPublic)

Initialization. Create a CatalogManager and set all the properties upfront. This prevents JVM wide system properties or a property file somewhere in the environment from affecting the behaviour of this catalog resolver.

parseCatalogsback to summary
private void parseCatalogs() throws IOException

Instruct the Catalog to parse each of the catalogs in the list. Only the first catalog will actually be parsed immediately. The others will be queued and read if they are needed later.

resolveEntityback to summary
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException

Implements org.xml.sax.EntityResolver.resolveEntity.

Resolves an external entity. If the entity cannot be resolved, this method should return null. This method returns an input source if an entry was found in the catalog for the given external identifier. It should be overridden if other behaviour is required.

Parameters
publicId:String

the public identifier, or null if none was supplied

systemId:String

the system identifier

Returns:InputSource

Doc from org.xml.sax.EntityResolver.resolveEntity.

An InputSource object describing the new input source, or null to request that the parser open a regular URI connection to the system identifier.

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
IOException:
thrown if some i/o error occurs
resolveEntityback to summary
public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException

Implements org.xml.sax.ext.EntityResolver2.resolveEntity.

Resolves an external entity. If the entity cannot be resolved, this method should return null. This method returns an input source if an entry was found in the catalog for the given external identifier. It should be overridden if other behaviour is required.

Parameters
name:String

the identifier of the external entity

publicId:String

the public identifier, or null if none was supplied

baseURI:String

the URI with respect to which relative systemIDs are interpreted.

systemId:String

the system identifier

Returns:InputSource

Doc from org.xml.sax.ext.EntityResolver2.resolveEntity.

An InputSource object describing the new input source to be used by the parser. Returning null directs the parser to resolve the system ID against the base URI and open a connection to resulting URI.

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
IOException:
thrown if some i/o error occurs
resolveEntityback to summary
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException

Implements org.apache.xerces.xni.parser.XMLEntityResolver.resolveEntity.

Resolves an external entity. If the entity cannot be resolved, this method should return null. This method only calls resolveIdentifier and returns an input source if an entry was found in the catalog. It should be overridden if other behaviour is required.

Parameters
resourceIdentifier:XMLResourceIdentifier

location of the XML resource to resolve

Exceptions
XNIException:
thrown on general error
IOException:
thrown if some i/o error occurs
resolveIdentifierback to summary
public String resolveIdentifier(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException

Resolves an identifier using the catalog. This method interprets that the namespace of the identifier corresponds to uri entries in the catalog. Where both a namespace and an external identifier exist, the namespace takes precedence.

Parameters
resourceIdentifier:XMLResourceIdentifier

the identifier to resolve

Exceptions
IOException:
thrown if some i/o error occurs
XNIException:
thrown on general error
resolvePublicback to summary
public final synchronized String resolvePublic(String publicId, String systemId) throws IOException

Returns the URI mapping in the catalog for the given external identifier or null if no mapping exists. Public identifiers are normalized before comparison.

Parameters
publicId:String

the public identifier to locate in the catalog

systemId:String

the system identifier to locate in the catalog

Returns:String

the mapped URI or null if no mapping was found in the catalog

Exceptions
IOException:
if an i/o error occurred while reading the catalog
resolveResourceback to summary
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI)

Implements org.w3c.dom.ls.LSResourceResolver.resolveResource.

Resolves a resource using the catalog. This method interprets that the namespace URI corresponds to uri entries in the catalog. Where both a namespace and an external identifier exist, the namespace takes precedence.

Parameters
type:String

the type of the resource being resolved

namespaceURI:String

the namespace of the resource being resolved, or null if none was supplied

publicId:String

the public identifier of the resource being resolved, or null if none was supplied

systemId:String

the system identifier of the resource being resolved, or null if none was supplied

baseURI:String

the absolute base URI of the resource being parsed, or null if there is no base URI

Returns:LSInput

Doc from org.w3c.dom.ls.LSResourceResolver.resolveResource.

A LSInput object describing the new input source, or null to request that the parser open a regular URI connection to the resource.

resolveSystemback to summary
public final synchronized String resolveSystem(String systemId) throws IOException

Returns the URI mapping in the catalog for the given external identifier or null if no mapping exists. If the system identifier is an URN in the publicid namespace it is converted into a public identifier by URN "unwrapping" as specified in the XML Catalogs specification.

Parameters
systemId:String

the system identifier to locate in the catalog

Returns:String

the mapped URI or null if no mapping was found in the catalog

Exceptions
IOException:
if an i/o error occurred while reading the catalog
resolveURIback to summary
public final synchronized String resolveURI(String uri) throws IOException

Returns the URI mapping in the catalog for the given URI reference or null if no mapping exists. URI comparison is case sensitive. If the URI reference is an URN in the publicid namespace it is converted into a public identifier by URN "unwrapping" as specified in the XML Catalogs specification and then resolution is performed following the semantics of external identifier resolution.

Parameters
uri:String

the URI to locate in the catalog

Returns:String

the mapped URI or null if no mapping was found in the catalog

Exceptions
IOException:
if an i/o error occurred while reading the catalog
setCatalogListback to summary
public final synchronized void setCatalogList(String[] catalogs)

Sets the initial list of catalog entry files. If there were any catalog mappings cached from the previous list they will be replaced by catalog mappings from the new list the next time the catalog is queried.

Parameters
catalogs:String[]

an ordered array list of absolute URIs

setPreferPublicback to summary
public final void setPreferPublic(boolean preferPublic)

Sets the preference for whether system or public matches are preferred. This is used in the absence of any occurrence of the prefer attribute on the catalog entry of a catalog.

Parameters
preferPublic:boolean

the prefer public setting

setUseLiteralSystemIdback to summary
public final void setUseLiteralSystemId(boolean useLiteralSystemId)

Sets the preference for whether the literal system identifier should be used when resolving system identifiers when both it and the expanded system identifier are available.

The literal system identifier is the URI as it was provided before absolutization. It may be embedded within an entity. It may be provided externally or it may be the result of redirection. For example, redirection may have come from the protocol level through HTTP or from an application's entity resolver.

The expanded system identifier is an absolute URI which is the result of resolving the literal system identifier against a base URI.

Parameters
useLiteralSystemId:boolean

the preference for using literal system identifiers for catalog resolution