Top Description Inners Constructors Methods
com.openhtmltopdf.resource

public Class FSCatalog

extends Object
Class Inheritance
Imports
com.openhtmltopdf.util.LogMessageId, .XRLog, .XRRuntimeException, org.xml.sax.*, org.xml.sax.helpers.DefaultHandler, java.io.BufferedInputStream, .InputStream, java.util.Collections, .HashMap, .Map, java.util.logging.Level

FSCatalog loads an XML catalog file to read mappings of public IDs for XML schemas/dtds, to resolve those mappings to a local store for the schemas. The catalog file allows one to have a single mapping of schema IDs to local files, and is useful when there are many schemas, or when schemas are broken into many smaller files. Currently FSCatalog only supports the very simple mapping of public id to local URI using the public element in the catalog XML.

FSCatalog is not an EntityResolver; it only parses a catalog file. See FSEntityResolver for entity resolution.

To use, instantiate the class, and call parseCatalog(InputSource) to retrieve a java.util.Map keyed by public ids. The class uses an XMLReader instance retrieved via XMLResource#newXMLReader(), so XMLReader configuration (and specification) follows that of the standard XML parsing in Flying Saucer.

This class is not safe for multi-threaded access.

Author
Patrick Wright

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
FSCatalog.CatalogContentHandler

A SAX ContentHandler that reads an XML catalog file and builds a Map of public IDs to local URIs.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
addHandlers(XMLReader xmlReader, ContentHandler ch)

Adds the default EntityResolved and ErrorHandler for the SAX parser.

public Map<String, String>
parseCatalog(String
A String URI to a catalog XML file on the classpath.
catalogURI
)

Parses an XML catalog file and returns a Map of public ids to local URIs read from the catalog.

public Map<String, String>
parseCatalog(InputSource
A SAX InputSource to a catalog XML file on the classpath.
inputSource
)

Parses an XML catalog file and returns a Map of public ids to local URIs read from the catalog.

private void
setFeature(XMLReader xmlReader, String featureUri, boolean value)

Attempts to set requested feature on the parser; logs exception if not supported or not recognized.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

FSCatalogback to summary
public FSCatalog()

Method Detail

addHandlersback to summary
private void addHandlers(XMLReader xmlReader, ContentHandler ch)

Adds the default EntityResolved and ErrorHandler for the SAX parser.

parseCatalogback to summary
public Map<String, String> parseCatalog(String catalogURI)

Parses an XML catalog file and returns a Map of public ids to local URIs read from the catalog. Only the catalog public elements are parsed.

Parameters
catalogURI:String

A String URI to a catalog XML file on the classpath.

parseCatalogback to summary
public Map<String, String> parseCatalog(InputSource inputSource)

Parses an XML catalog file and returns a Map of public ids to local URIs read from the catalog. Only the catalog public elements are parsed.

Parameters
inputSource:InputSource

A SAX InputSource to a catalog XML file on the classpath.

setFeatureback to summary
private void setFeature(XMLReader xmlReader, String featureUri, boolean value)

Attempts to set requested feature on the parser; logs exception if not supported or not recognized.

com.openhtmltopdf.resource back to summary

private Class FSCatalog.CatalogContentHandler

extends DefaultHandler
Class Inheritance

A SAX ContentHandler that reads an XML catalog file and builds a Map of public IDs to local URIs. Currently only handles the element and attributes. To use, just call XMLReader.setContentHandler() with an instance of the class, parse, then call getEntityMap().

Field Summary

Modifier and TypeField and Description
private final Map<String, String>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Map<String, String>
getEntityMap()

Returns a Map of public Ids to local URIs

public void
startElement(String
The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
namespaceURI
,
String
The local name (without prefix), or the empty string if Namespace processing is not being performed.
localName
,
String
The qualified name (with prefix), or the empty string if qualified names are not available.
qName
,
Attributes
The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
atts
)

Overrides org.xml.sax.helpers.DefaultHandler.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Receive notification of the beginning of an element; here used to pick up the mappings for public IDs to local URIs in the catalog.

Inherited from org.xml.sax.helpers.DefaultHandler:
charactersendDocumentendElementendPrefixMappingerrorfatalErrorignorableWhitespacenotationDeclprocessingInstructionresolveEntitysetDocumentLocatorskippedEntitystartDocumentstartPrefixMappingunparsedEntityDeclwarning

Field Detail

entityMapback to summary
private final Map<String, String> entityMap

Constructor Detail

CatalogContentHandlerback to summary
public CatalogContentHandler()

Method Detail

getEntityMapback to summary
public Map<String, String> getEntityMap()

Returns a Map of public Ids to local URIs

startElementback to summary
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)

Overrides org.xml.sax.helpers.DefaultHandler.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Receive notification of the beginning of an element; here used to pick up the mappings for public IDs to local URIs in the catalog.

Parameters
namespaceURI:String

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.

localName:String

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The local name (without prefix), or the empty string if Namespace processing is not being performed.

qName:String

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The qualified name (with prefix), or the empty string if qualified names are not available.

atts:Attributes

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.