org.tm4j.net
Class URILocatorResolver

java.lang.Object
  extended byorg.tm4j.net.URILocatorResolver
All Implemented Interfaces:
LocatorResolver

public class URILocatorResolver
extends java.lang.Object
implements LocatorResolver

A generic URI locator resolver. Uses a plugin architecture to handle different URI protocols. The steps in resolution are as follows: 1. If the Locator is not an instance of URILocator, a LocatorResolutionException is thrown 2. If a LocatorResolver is registered for the scheme of the URILocator, then this resolver is invoked and the resulting InputStream returned 3. If there is no LocatorResolver found for the scheme, then the address is used to construct a java.net.URL object and an attempt is made to open a connection to the URL using the standard Java mechanism

If provided with a CatalogResolver (either at construction or via setCatalogResolver(CatalogResolver), resolution of Locator addresses will be attempted prior to opening a resource.

See Also:
URILocator, LocatorResolutionException, URL, URLConnection

Field Summary
protected  org.apache.xml.resolver.tools.CatalogResolver m_catalogResolver
          XML catalog resolution service.
 
Constructor Summary
URILocatorResolver()
          A default constructor establishing a URILocatorResolver.
URILocatorResolver(org.apache.xml.resolver.tools.CatalogResolver resolver)
          A constructor establishing a URILocatorResolver that provides XML catalog resolution.
 
Method Summary
 LocatorResolver addResolver(java.lang.String scheme, LocatorResolver resolver)
          Adds a new protocol resolver to this resolver.
 java.io.InputStream resolve(Locator loc)
          Opens an InputStream from the resource specified by the Locator's address.
 void setCatalogResolver(org.apache.xml.resolver.tools.CatalogResolver resolver)
          Set the CatalogResolver used with this URILocatorResolver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_catalogResolver

protected org.apache.xml.resolver.tools.CatalogResolver m_catalogResolver
XML catalog resolution service.

Constructor Detail

URILocatorResolver

public URILocatorResolver()
A default constructor establishing a URILocatorResolver. No XML catalog resolution is provided.


URILocatorResolver

public URILocatorResolver(org.apache.xml.resolver.tools.CatalogResolver resolver)
A constructor establishing a URILocatorResolver that provides XML catalog resolution.

Parameters:
resolver - the CatalogResolver to be used.
Method Detail

setCatalogResolver

public void setCatalogResolver(org.apache.xml.resolver.tools.CatalogResolver resolver)
Set the CatalogResolver used with this URILocatorResolver.

Parameters:
resolver - the CatalogResolver to be used.

addResolver

public LocatorResolver addResolver(java.lang.String scheme,
                                   LocatorResolver resolver)
Adds a new protocol resolver to this resolver.

Parameters:
scheme - The URI scheme handled by the resolver.
resolver - The LocatorResolver capable of providing an InputStream for URIs using the scheme scheme
Returns:
The previously registered resolver for scheme or null if there was no previously registered resolver for this scheme.

resolve

public java.io.InputStream resolve(Locator loc)
                            throws java.io.IOException,
                                   LocatorResolutionException
Opens an InputStream from the resource specified by the Locator's address. If a CatalogResolver is active, attempts to resolve the address (a system identifier) prior to resolving the Locator.

Specified by:
resolve in interface LocatorResolver
Parameters:
loc - the locator for which an input stream is to be opened.
Throws:
LocatorResolutionException - if the locator could not be resolved correctly.
java.io.IOException - if an unexpected condition occurred while attempting to open the input stream.