org.pf.six
Class FileEntityResolver

java.lang.Object
  extended by org.pf.six.FileEntityResolver
All Implemented Interfaces:
org.xml.sax.EntityResolver

public class FileEntityResolver
extends java.lang.Object

Some XML parser packages (e.g. crimson 1.1.3) provide a entity resolver that uses URL connections to retrieve the resources. Unfortunately that doesn't always work. Especially if the URL connection for files in the local file system are opened with "ftp://" protocol.

Therefore this simple entity resolver implementation is capable of returning proper InputResource instances for file ids on the local system.

Version:
1.2
Author:
Manfred Duchrow

Constructor Summary
FileEntityResolver()
          Initialize the new instance with default values.
FileEntityResolver(boolean validating)
          Initialize the new instance with the setting if the parser is validating the XML input.
 
Method Summary
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          If the given systemId specifies a file in the local file system an InputSource with an opended FileInputStream on this file will be returned.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileEntityResolver

public FileEntityResolver()
Initialize the new instance with default values.


FileEntityResolver

public FileEntityResolver(boolean validating)
Initialize the new instance with the setting if the parser is validating the XML input. If true, this resolver must return an InputSource for a URI pointing to a DTD file. If false this resolver must return null for a URI pointing to a DTD file.

Parameters:
validating - Determines whether the resolver must return a resource for a DTD or not
Method Detail

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
                                      throws org.xml.sax.SAXException,
                                             java.io.IOException
If the given systemId specifies a file in the local file system an InputSource with an opended FileInputStream on this file will be returned. If the systemId contains a different protocol (e.g. http:// or ftp:// ) then null is returned.

Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Parameters:
publicId - The public identifier of the external entity being referenced, or null if none was supplied.
systemId - The system identifier of the external entity being referenced.
Returns:
An InputSource object describing the new input source, or null to request that the parser open a regular URI connection to the system identifier.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
java.io.IOException - A Java-specific IO exception, possibly the result of creating a new InputStream or Reader for the InputSource.
See Also:
InputSource