org.inria.ns.reflex.xml
Class FileResolver

java.lang.Object
  extended by org.inria.ns.reflex.xml.FileResolver
All Implemented Interfaces:
URIResolver, EntityResolver

public final class FileResolver
extends Object
implements EntityResolver, URIResolver

A FileResolver provides various resolvers for external identifiers and URI references.

Any resolution is based on the file systems known by the underlying implementation without performing catalog lookup.

Some static methods provides error handling while resolving.

resolvePath(String, Object, XFile) allows to resolve a relative path regarding a xml:base.

Author:
Philippe Poulard

Field Summary
static EntityResolver EXTERNAL_IDENTITY_RESOLVER
          Resolve external identifiers without catalog lookup ; support many URI schemes.
static URIResolver URI_REFERENCE_RESOLVER
          Resolve URI references without catalog lookup ; support many URI schemes.
 
Method Summary
 Source resolve(String href, String base)
          Resolve an URI reference.
static Source resolve(String href, String base, ErrorListener errorListener)
          Resolve an URI reference.
 InputSource resolveEntity(String publicId, String systemId)
          Resolve an external identifier.
static InputSource resolveEntity(String publicId, String systemId, ErrorHandler errorHandler)
          Resolve an external identifiers.
static XFile resolvePath(String path, Object node, XFile baseFile)
          Resolve a path to a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXTERNAL_IDENTITY_RESOLVER

public static final EntityResolver EXTERNAL_IDENTITY_RESOLVER
Resolve external identifiers without catalog lookup ; support many URI schemes.


URI_REFERENCE_RESOLVER

public static final URIResolver URI_REFERENCE_RESOLVER
Resolve URI references without catalog lookup ; support many URI schemes.

Method Detail

resolveEntity

public static final InputSource resolveEntity(String publicId,
                                              String systemId,
                                              ErrorHandler errorHandler)
                                       throws SAXException,
                                              IOException
Resolve an external identifiers. Support many URI schemes. No catalog lookup is performed.

Parameters:
publicId - The public ID of the external identifier.
systemId - The system ID of the external identifier.
errorHandler - An error handler that report warning when an I/O error occurs ; may be null.
Returns:
An input source, or null if an I/O error has been reported by the error handler.
Throws:
SAXException - May be thrown if no error handler is supplied.
IOException - May be thrown if no error handler is supplied.

resolve

public static final Source resolve(String href,
                                   String base,
                                   ErrorListener errorListener)
                            throws TransformerException
Resolve an URI reference. Support many URI schemes. No catalog lookup is performed.

Parameters:
href - The URI to resolve.
base - The base URI, if any.
errorListener - An error listener that report warning when an I/O error occurs ; may be null.
Returns:
An XML source, or null if an I/O error has been reported by the error listener.
Throws:
TransformerException - May be thrown if no error listener is supplied.

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws SAXException,
                                 IOException
Resolve an external identifier. Support many URI schemes. No catalog lookup is performed.

Specified by:
resolveEntity in interface EntityResolver
Parameters:
publicId - The public ID of the external identifier.
systemId - The system ID of the external identifier.
Returns:
An input source.
Throws:
SAXException
IOException
See Also:
EntityResolver.resolveEntity(java.lang.String, java.lang.String)

resolve

public Source resolve(String href,
                      String base)
               throws TransformerException
Resolve an URI reference. Support many URI schemes. No catalog lookup is performed.

Specified by:
resolve in interface URIResolver
Parameters:
href - The URI to resolve.
base - The base URI, if any.
Returns:
An XML source.
Throws:
TransformerException
See Also:
URIResolver.resolve(java.lang.String, java.lang.String)

resolvePath

public static final XFile resolvePath(String path,
                                      Object node,
                                      XFile baseFile)
                               throws FileSystemException
Resolve a path to a file.

Absolute paths are returned as-is. Relative paths are absolutized regarding the xml:base attribute defined in the node and/or its ancestor.

Parameters:
path - The path to the resource, possibly relative.
node - The node that may define itself or one of its ancestor an xml:base in order to resolve relative paths. If the path specified by xml:base is a relative path, it is absolutized regarding the xml:base specified by its nearest ancestor, and so on.
baseFile - The base to use in the last resort, shouldn't be null.
Returns:
An absolute file. null will be returned if the path haven't been absolutized because the base file given was also null.
Throws:
FileSystemException - When an I/O error occurs.
See Also:
Node, SAXNode, XOperable