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.
| Method from org.apache.xerces.util.XMLCatalogResolver Detail: |
public final synchronized void clear() {
fCatalog = null;
}
|
public final synchronized String[] getCatalogList() {
return (fCatalogsList != null)
? (String[]) fCatalogsList.clone() : null;
}
|
public InputSource getExternalSubset(String name,
String baseURI) throws IOException, SAXException {
return null;
}
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.
|
public final boolean getPreferPublic() {
return fPreferPublic;
}
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.
|
public final boolean getUseLiteralSystemId() {
return fUseLiteralSystemId;
}
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.
|
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
String resolvedId = resolveIdentifier(resourceIdentifier);
if (resolvedId != null) {
return new XMLInputSource(resourceIdentifier.getPublicId(),
resolvedId,
resourceIdentifier.getBaseSystemId());
}
return null;
}
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.
|
public InputSource resolveEntity(String publicId,
String systemId) throws IOException, SAXException {
String resolvedId = null;
if (publicId != null && systemId != null) {
resolvedId = resolvePublic(publicId, systemId);
}
else if (systemId != null) {
resolvedId = resolveSystem(systemId);
}
if (resolvedId != null) {
InputSource source = new InputSource(resolvedId);
source.setPublicId(publicId);
return source;
}
return null;
}
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.
|
public InputSource resolveEntity(String name,
String publicId,
String baseURI,
String systemId) throws IOException, SAXException {
String resolvedId = null;
if (!getUseLiteralSystemId() && baseURI != null) {
// Attempt to resolve the system identifier against the base URI.
try {
URI uri = new URI(new URI(baseURI), systemId);
systemId = uri.toString();
}
// Ignore the exception. Fallback to the literal system identifier.
catch (URI.MalformedURIException ex) {}
}
if (publicId != null && systemId != null) {
resolvedId = resolvePublic(publicId, systemId);
}
else if (systemId != null) {
resolvedId = resolveSystem(systemId);
}
if (resolvedId != null) {
InputSource source = new InputSource(resolvedId);
source.setPublicId(publicId);
return source;
}
return null;
}
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.
|
public String resolveIdentifier(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
String resolvedId = null;
// The namespace is useful for resolving namespace aware
// grammars such as XML schema. Let it take precedence over
// the external identifier if one exists.
String namespace = resourceIdentifier.getNamespace();
if (namespace != null) {
resolvedId = resolveURI(namespace);
}
// Resolve against an external identifier if one exists. This
// is useful for resolving DTD external subsets and other
// external entities. For XML schemas if there was no namespace
// mapping we might be able to resolve a system identifier
// specified as a location hint.
if (resolvedId == null) {
String publicId = resourceIdentifier.getPublicId();
String systemId = getUseLiteralSystemId()
? resourceIdentifier.getLiteralSystemId()
: resourceIdentifier.getExpandedSystemId();
if (publicId != null && systemId != null) {
resolvedId = resolvePublic(publicId, systemId);
}
else if (systemId != null) {
resolvedId = resolveSystem(systemId);
}
}
return resolvedId;
}
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.
|
public final synchronized String resolvePublic(String publicId,
String systemId) throws IOException {
if (fCatalogsChanged) {
parseCatalogs();
fCatalogsChanged = false;
}
return (fCatalog != null)
? fCatalog.resolvePublic(publicId, systemId) : null;
}
Returns the URI mapping in the catalog for the given
external identifier or null if no mapping
exists. Public identifiers are normalized before
comparison.
|
public LSInput resolveResource(String type,
String namespaceURI,
String publicId,
String systemId,
String baseURI) {
String resolvedId = null;
try {
// The namespace is useful for resolving namespace aware
// grammars such as XML schema. Let it take precedence over
// the external identifier if one exists.
if (namespaceURI != null) {
resolvedId = resolveURI(namespaceURI);
}
if (!getUseLiteralSystemId() && baseURI != null) {
// Attempt to resolve the system identifier against the base URI.
try {
URI uri = new URI(new URI(baseURI), systemId);
systemId = uri.toString();
}
// Ignore the exception. Fallback to the literal system identifier.
catch (URI.MalformedURIException ex) {}
}
// Resolve against an external identifier if one exists. This
// is useful for resolving DTD external subsets and other
// external entities. For XML schemas if there was no namespace
// mapping we might be able to resolve a system identifier
// specified as a location hint.
if (resolvedId == null) {
if (publicId != null && systemId != null) {
resolvedId = resolvePublic(publicId, systemId);
}
else if (systemId != null) {
resolvedId = resolveSystem(systemId);
}
}
}
// Ignore IOException. It cannot be thrown from this method.
catch (IOException ex) {}
if (resolvedId != null) {
return new DOMInputImpl(publicId, resolvedId, baseURI);
}
return null;
}
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.
|
public final synchronized String resolveSystem(String systemId) throws IOException {
if (fCatalogsChanged) {
parseCatalogs();
fCatalogsChanged = false;
}
return (fCatalog != null)
? fCatalog.resolveSystem(systemId) : null;
}
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.
|
public final synchronized String resolveURI(String uri) throws IOException {
if (fCatalogsChanged) {
parseCatalogs();
fCatalogsChanged = false;
}
return (fCatalog != null)
? fCatalog.resolveURI(uri) : null;
}
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.
|
public final synchronized void setCatalogList(String[] catalogs) {
fCatalogsChanged = true;
fCatalogsList = (catalogs != null)
? (String[]) catalogs.clone() : null;
}
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.
|
public final void setPreferPublic(boolean preferPublic) {
fPreferPublic = preferPublic;
fResolverCatalogManager.setPreferPublic(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.
|
public final void setUseLiteralSystemId(boolean useLiteralSystemId) {
fUseLiteralSystemId = 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.
|