Enhydra 5.1 API

org.enhydra.xml.io
Class XMLEntityResolver

java.lang.Object
  |
  +--org.enhydra.xml.io.XMLEntityResolver
All Implemented Interfaces:
EntityResolver

public class XMLEntityResolver
extends java.lang.Object
implements EntityResolver

A flexable entity resolver for use with parsing XML files. This implements:

A list of class loaders maybe associated with this object. If so an attempt will be made to resolve file: URLs from the class path.

See Also:
XCatalog

Field Summary
static java.lang.String CLASSPATH_PROTOCOL
          Protocol to use in specifying a URL pointing to the CLASSPATH.
static java.lang.String CLASSPATH_PROTOCOL_PREFIX
          Protocol prefix.
static java.lang.String DEFAULT_ENTITY_CATALOG
          URL for Enhydra default entity catalog.
static java.lang.String LUTRIS_ENTITY_CATALOG
          URL for Lutrus Enhydra default entity catalog.
 
Constructor Summary
XMLEntityResolver()
           
 
Method Summary
 void addClassLoader(java.lang.ClassLoader classLoader)
          Add a classloader to the end of the order list of classloaders to search for entities.
 void addPublicMapping(java.lang.String publicId, java.lang.String systemId)
          Adds a public to system identifier mapping.
 void addSystemMapping(java.lang.String systemId1, java.lang.String systemId2)
          Adds a system identifier alias.
 java.util.Enumeration getClassLoaders()
          Get an enumeration of the class loaders.
 java.io.PrintWriter getDebugWriter()
          Get the debug writer.
 java.lang.String getPublicMapping(java.lang.String publicId)
          Returns a public identifier mapping.
 java.util.Enumeration getPublicMappingKeys()
          Returns an enumeration of public identifier mapping keys.
 java.lang.String getSystemMapping(java.lang.String systemId)
          Returns a system identifier alias.
 java.util.Enumeration getSystemMappingKeys()
          Returns an enumeration of system identifier mapping keys.
 void loadCatalog(InputSource source)
          Loads a catalog specified by the given input source and appends the contents to the catalog object.
 void removePublicMapping(java.lang.System publicId)
          Removes a public identifier mapping.
 void removeSystemMapping(java.lang.String systemId)
          Removes a system identifier alias.
 InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Allow the application to resolve external entities.
 void setDebugWriter(java.io.PrintWriter writer)
          Set a writer used to output debug messages.
 void setDefaultResolving()
          Load the default entity catalog and enable loading entities the classloader for the classloader that loaded this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSPATH_PROTOCOL

public static final java.lang.String CLASSPATH_PROTOCOL
Protocol to use in specifying a URL pointing to the CLASSPATH.

See Also:
Constant Field Values

CLASSPATH_PROTOCOL_PREFIX

public static final java.lang.String CLASSPATH_PROTOCOL_PREFIX
Protocol prefix.

See Also:
Constant Field Values

DEFAULT_ENTITY_CATALOG

public static final java.lang.String DEFAULT_ENTITY_CATALOG
URL for Enhydra default entity catalog.

See Also:
#loadDefaultCatalog, Constant Field Values

LUTRIS_ENTITY_CATALOG

public static final java.lang.String LUTRIS_ENTITY_CATALOG
URL for Lutrus Enhydra default entity catalog. Only loaded if available.

See Also:
#loadDefaultCatalog, Constant Field Values
Constructor Detail

XMLEntityResolver

public XMLEntityResolver()
Method Detail

setDebugWriter

public void setDebugWriter(java.io.PrintWriter writer)
Set a writer used to output debug messages.


getDebugWriter

public java.io.PrintWriter getDebugWriter()
Get the debug writer.


loadCatalog

public void loadCatalog(InputSource source)
                 throws SAXException,
                        java.io.IOException
Loads a catalog specified by the given input source and appends the contents to the catalog object.

Parameters:
source - The catalog source.
Throws:
SAXException - Throws exception on SAX error.
java.io.IOException - Throws exception on i/o error.

setDefaultResolving

public void setDefaultResolving()
                         throws SAXException,
                                java.io.IOException
Load the default entity catalog and enable loading entities the classloader for the classloader that loaded this class.

SAXException
java.io.IOException

addPublicMapping

public void addPublicMapping(java.lang.String publicId,
                             java.lang.String systemId)
Adds a public to system identifier mapping.

Parameters:
publicId - The public identifier, or "key".
systemId - The system identifier, or "value".

removePublicMapping

public void removePublicMapping(java.lang.System publicId)
Removes a public identifier mapping.

Parameters:
publicId - The public identifier to remove.

getPublicMappingKeys

public java.util.Enumeration getPublicMappingKeys()
Returns an enumeration of public identifier mapping keys.


getPublicMapping

public java.lang.String getPublicMapping(java.lang.String publicId)
Returns a public identifier mapping.

Parameters:
publicId - The public identifier, or "key".
Returns:
Returns the system identifier value or null if there is no mapping defined.

addSystemMapping

public void addSystemMapping(java.lang.String systemId1,
                             java.lang.String systemId2)
Adds a system identifier alias.


removeSystemMapping

public void removeSystemMapping(java.lang.String systemId)
Removes a system identifier alias.

Parameters:
systemId - The system identifier to remove.

getSystemMappingKeys

public java.util.Enumeration getSystemMappingKeys()
Returns an enumeration of system identifier mapping keys.


getSystemMapping

public java.lang.String getSystemMapping(java.lang.String systemId)
Returns a system identifier alias.

Parameters:
systemId - The system identifier "key".
Returns:
Returns the system identifier alias value or null if there is no alias defined.

addClassLoader

public void addClassLoader(java.lang.ClassLoader classLoader)
Add a classloader to the end of the order list of classloaders to search for entities.


getClassLoaders

public java.util.Enumeration getClassLoaders()
Get an enumeration of the class loaders.


resolveEntity

public InputSource resolveEntity(java.lang.String publicId,
                                 java.lang.String systemId)
                          throws SAXException,
                                 java.io.IOException
Description copied from interface: EntityResolver
Allow the application to resolve external entities.

The Parser will call this method before opening any external entity except the top-level document entity (including the external DTD subset, external entities referenced within the DTD, and external entities referenced within the document element): the application may request that the parser resolve the entity itself, that it use an alternative URI, or that it use an entirely different input source.

Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box).

If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to the application.

Specified by:
resolveEntity in interface 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:
java.io.IOException - A Java-specific IO exception, possibly the result of creating a new InputStream or Reader for the InputSource.
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
EntityResolver

Enhydra 5.1 API