org.backsource.utils.xml
Class Catalog

java.lang.Object
  extended byorg.apache.xml.resolver.Catalog
      extended byorg.backsource.utils.xml.Catalog

public class Catalog
extends org.apache.xml.resolver.Catalog

A simple extension of the Catalog to make it easier to construct instances progranatically. It is easier to add catalog entries and set a baseUri programatically than the original.

This version of the Catalog allways need a base uri to work against. This should normally be a directory where dtd:s and other files are collected. To make it easier to use in a component environment where other forms of configurations are used than system wide catalog files the addCatalogEntry(org.backsource.utils.xml.CatalogEntry) should be used. The different type of entries jave static create methods in CatalogEntry. Here is one possible way of setting up the Catalog and adding some entries. It is important to note that how the resolved uris are translated to URL:s, ie resources that are also possible to get physically is really up to the resolver that used this Catalog, see Catalogresolver.

      File base = new File("resources/test/dtd/");
      catalog = new Catalog(base.getAbsolutePath());

      // Ad a systemId that will get rewritten to base+dtd2/ttnitf2.dtd
      catalog.addCatalogEntry( CatalogEntry.getRewriteSystemEntry("http://www.tt.se/dtd/ttnitf2.dtd", "dtd2/ttnitf2.dtd") );

      // add a systemId, that really shoul be looked up in classpath by resolver
      catalog.addCatalogEntry( CatalogEntry.getSystemEntry("log4j.dtd", "/org/apache/log4j/xml/log4j.dtd") );

      // Ad a publicId - amsterdam2.dtd must be in base dir
      catalog.addCatalogEntry( CatalogEntry.getPublicEntry("-//Teknik i Meda//DTD Amsterdam//EN", "amsterdam2.dtd") );

      // ad an uri that will be looked up in base + ../xsl/include.xsl
      CatalogEntry en = CatalogEntry.getUriEntry("include.xsl", "../xsl/include.xsl");

      catalog.addCatalogEntry( en );
 

See The OASIS spec to understand how the concept works.

Apart from all the configuration options given byte the original Catalog it is also possible to configure the Catalog with a DOM tree following the OASI spec. Say you have access to the following xml in a DOM Document:

<?xml version="1.0" ?>
<!-- Do NOT forget the trailing slash -->
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
  prefer="public"
  xml:base="dtd2/">
  <public publicId="-//OASIS//DTD DocBook XML V4.1.2//EN"
            uri="docbookx.dtd"/>
  <system systemId="ttnitf2.dtd"
    uri="ttnitf2.dtd"/>

</catalog>

You could configure the Catalog with:

File base = new File("resources/test/dtd/");
      Catalog cat = new Catalog(base.getAbsolutePath());
      Document d = DocumentUtil.getDocument( new FileInputStream("resources/test/catalog.xml") );
      cat.configure(d);

This is obsolete from 1.1. Unfortunately the parsing rutines of the resolver lib seems to be pretty sloppy, so don't be to suprised if the xml was not properly read because some XML error but with no exception.

Unfortunately the Catalog implementation is based on a lot of implicit working and static stuff: it is normally meant to be used for system wide usage. This has the disadvandage that there are a lot of stuff that the resolver tries to set in the background; and it will complain about missing propertfiles. To make it shutup, this should be run before the Catalog is used:

      org.apache.xml.resolver.CatalogManager.ignoreMissingProperties(true);

Version:
$Revision: 1.1.1.1 $
Author:
Peter Antman

Field Summary
 
Fields inherited from class org.apache.xml.resolver.Catalog
base, BASE, CATALOG, catalogCwd, catalogEntries, catalogFiles, catalogManager, catalogs, default_override, DELEGATE_PUBLIC, DELEGATE_SYSTEM, DELEGATE_URI, DOCTYPE, DOCUMENT, DTDDECL, ENTITY, LINKTYPE, localCatalogFiles, localDelegate, NOTATION, OVERRIDE, PUBLIC, readerArr, readerMap, REWRITE_SYSTEM, REWRITE_URI, SGMLDECL, SYSTEM, URI
 
Constructor Summary
Catalog(java.lang.String baseUri)
           
 
Method Summary
 void addCatalogEntry(CatalogEntry entry)
           
 void configure(org.w3c.dom.Document doc)
          Configure from an OASIS xml document.
 java.net.URL getBase()
           
 void setBaseUri(java.lang.String baseUri)
           
 void setDebug(int level)
           
 
Methods inherited from class org.apache.xml.resolver.Catalog
addDelegate, addEntry, addReader, copyReaders, encodedByte, fixSlashes, getCatalogManager, getCurrentBase, getDefaultOverride, loadSystemCatalogs, makeAbsolute, newCatalog, normalizeURI, parseAllCatalogs, parseCatalog, parseCatalog, parseCatalog, parseCatalogFile, parsePendingCatalogs, resolveDoctype, resolveDocument, resolveEntity, resolveLocalPublic, resolveLocalSystem, resolveLocalURI, resolveNotation, resolvePublic, resolveSubordinateCatalogs, resolveSystem, resolveURI, setCatalogManager, setupReaders, unknownEntry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Catalog

public Catalog(java.lang.String baseUri)
        throws XmlException
Method Detail

setDebug

public void setDebug(int level)

setBaseUri

public void setBaseUri(java.lang.String baseUri)
                throws XmlException
Throws:
XmlException

getBase

public java.net.URL getBase()

addCatalogEntry

public void addCatalogEntry(CatalogEntry entry)

configure

public void configure(org.w3c.dom.Document doc)
               throws XmlException
Configure from an OASIS xml document.

Ig chaning the base of the catalog with xml:base, don't forget to ad a traling slash to any dirs mentioned!

Throws:
XmlException


Copyright © 2000-2004 Backsource. All Rights Reserved.