org.schmant.support.xml
Class XmlCatalogResolver

java.lang.Object
  extended by org.schmant.support.AbstractArgumentChecker
      extended by org.schmant.support.xml.XmlCatalogResolver
All Implemented Interfaces:
URIResolver, XmlCatalog<XmlCatalogResolver>, EntityResolver

public class XmlCatalogResolver
extends AbstractArgumentChecker
implements URIResolver, EntityResolver, XmlCatalog<XmlCatalogResolver>

This is an EntityResolver and a URIResolver that uses internal mappings between systemId, publicId or URI and objects that can be interpreted as ReadableFile:s by InterpretAsReadableFileStrategy.

This can for instance be used to handle relative paths in external entities. That can be difficult in Java, otherwise.

The catalog resolver is case sensitive.

The resolve methods log their results to level debug, unless setVerbose(boolean) is set to true, in which case all results are logged to level info.

Instances of this class are thread safe.

Since:
0.5
Author:
Karl Gustafsson
Task_package:
org.schmant.task.base

Constructor Summary
XmlCatalogResolver()
           
 
Method Summary
 XmlCatalogResolver addPublicId(String pid, Object o)
          Add one entity with the supplied public ID to the catalog.
 XmlCatalogResolver addPublicIds(Map<String,?> m)
          Add a map with public ID:s and their corresponding entities.
 XmlCatalogResolver addSystemId(String sid, Object o)
          Add one entity with the supplied system ID to the catalog.
 XmlCatalogResolver addSystemIds(Map<String,?> m)
          Add a map with system ID:s and their corresponding entities.
 XmlCatalogResolver addUri(String uri, Object o)
          Add one entity with the supplied URI to the catalog.
 XmlCatalogResolver addUris(Map<String,?> m)
          Add a map with URI:s and their corresponding entities.
 Map<String,Object> getPublicIdMap()
          Get (a copy of) all the public id mappings in the catalog resolver.
 Map<String,Object> getSystemIdMap()
          Get (a copy of) all the system id mappings in the catalog resolver.
 Map<String,Object> getUriMap()
          Get (a copy of) all the URI mappings in the catalog resolver.
 Source resolve(String href, String base)
          This methods resolves entities in the URI map.
 InputSource resolveEntity(String publicId, String systemId)
           
 XmlCatalogResolver setPreferPublic(boolean preferPublic)
          When resolving entities, should publicId names be used before systemId names? The default is to use systemId names before publicId (false).
 XmlCatalogResolver setUseFilesInsteadOfStreamsForUris(boolean b)
          Should java.io.File-based javax.xml.transform.Source objects be created instead of java.io.InputStream-based when resolving URI:s? Doing so probably makes the Source object reusable and vaguely aware of the entity's location, which seems to be required by some XML applications.
 XmlCatalogResolver setVerbose(boolean b)
          Should the catalog resolver be verbose? If it is, it logs an info message to the current thread's Report every time it tries to resolve an entity.
 String toString()
           
 
Methods inherited from class org.schmant.support.AbstractArgumentChecker
check, check, check, check
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XmlCatalogResolver

public XmlCatalogResolver()
Method Detail

setPreferPublic

public XmlCatalogResolver setPreferPublic(boolean preferPublic)
When resolving entities, should publicId names be used before systemId names? The default is to use systemId names before publicId (false).

Parameters:
preferPublic - Should publicId names be preferred?
Returns:
this

setVerbose

public XmlCatalogResolver setVerbose(boolean b)
Should the catalog resolver be verbose? If it is, it logs an info message to the current thread's Report every time it tries to resolve an entity.

Parameters:
b - Should the resolver be verbose?
Returns:
this

setUseFilesInsteadOfStreamsForUris

public XmlCatalogResolver setUseFilesInsteadOfStreamsForUris(boolean b)
Should java.io.File-based javax.xml.transform.Source objects be created instead of java.io.InputStream-based when resolving URI:s? Doing so probably makes the Source object reusable and vaguely aware of the entity's location, which seems to be required by some XML applications. (Docbook XSL stylesheets, for instance.) On the other hand, setting this to true requires that all resolved entities are java.io.File-backed.

The default is to use stream-based Source objects. (false)

Parameters:
b - Should Source objects be File-based?
Returns:
this

resolve

public Source resolve(String href,
                      String base)
This methods resolves entities in the URI map.

Specified by:
resolve in interface URIResolver

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
Specified by:
resolveEntity in interface EntityResolver

addSystemId

public XmlCatalogResolver addSystemId(String sid,
                                      Object o)
Description copied from interface: XmlCatalog
Add one entity with the supplied system ID to the catalog.

Specified by:
addSystemId in interface XmlCatalog<XmlCatalogResolver>
Parameters:
sid - The system ID.
o - An entity that can be interpreted by InterpretAsReadableFileStrategy.
Returns:
this.

addSystemIds

public XmlCatalogResolver addSystemIds(Map<String,?> m)
Description copied from interface: XmlCatalog
Add a map with system ID:s and their corresponding entities.

Specified by:
addSystemIds in interface XmlCatalog<XmlCatalogResolver>
Parameters:
m - A mapping between system ID:s and entities.
Returns:
this

getSystemIdMap

public Map<String,Object> getSystemIdMap()
Get (a copy of) all the system id mappings in the catalog resolver.

Returns:
All system id mappings.

addPublicId

public XmlCatalogResolver addPublicId(String pid,
                                      Object o)
Description copied from interface: XmlCatalog
Add one entity with the supplied public ID to the catalog.

Specified by:
addPublicId in interface XmlCatalog<XmlCatalogResolver>
Parameters:
pid - The public ID.
o - An entity that can be interpreted by InterpretAsReadableFileStrategy.
Returns:
this.

addPublicIds

public XmlCatalogResolver addPublicIds(Map<String,?> m)
Description copied from interface: XmlCatalog
Add a map with public ID:s and their corresponding entities.

Specified by:
addPublicIds in interface XmlCatalog<XmlCatalogResolver>
Parameters:
m - A mapping between public ID:s and entities.
Returns:
this

getPublicIdMap

public Map<String,Object> getPublicIdMap()
Get (a copy of) all the public id mappings in the catalog resolver.

Returns:
All public id mappings.

addUri

public XmlCatalogResolver addUri(String uri,
                                 Object o)
Description copied from interface: XmlCatalog
Add one entity with the supplied URI to the catalog.

Specified by:
addUri in interface XmlCatalog<XmlCatalogResolver>
Parameters:
uri - The URI.
o - An entity that can be interpreted by InterpretAsReadableFileStrategy.
Returns:
this.

addUris

public XmlCatalogResolver addUris(Map<String,?> m)
Description copied from interface: XmlCatalog
Add a map with URI:s and their corresponding entities.

Specified by:
addUris in interface XmlCatalog<XmlCatalogResolver>
Parameters:
m - A mapping between URI:s and entities.
Returns:
this

getUriMap

public Map<String,Object> getUriMap()
Get (a copy of) all the URI mappings in the catalog resolver.

Returns:
All URI mappings.

toString

public String toString()
Overrides:
toString in class Object