This page describes how to use the XML Commons Resolver with Apache FOP. It shows you how you can use abstract URIs to specify resources such as images and how you can translate these abstract URIs to actual URLs pointing to the real file. This is ideal to do a mapping for resources for which the final location at deployment time is not known. The catalog file is where you specify how the URIs are supposed to be mapped to the concrete URLs.

Note: This requires Apache FOP 0.93 or later!

Get XML Commons Resolver

You can download it at: http://xml.apache.org/mirrors.cgi

The main website is at: http://xml.apache.org/commons/components/resolver/

XML Commons Resolver is [http://thread.gmane.org/gmane.text.xml.fop.user/29585 included in OpenJDK 6], so if you're running OpenJDK 6 or later, it's already installed. In OpenJDK 6 the catalog resolver class name is, com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver

XML Commons Resolver may also be included in Java 6 installations other than the one from Sun - this should be checked.

The Example

You can download the source for the example from the web using the following links:

Setup instructions

     -Dxml.catalog.files="C:/Dev/Java/workspace/FOP Main Sandbox/src/xml/fop-demo-catalog.xml"

(Obviously, you will need to adjust the path. You simply need to make sure that the path is right and the catalog file is found.

Notes

You will recognize that the FO file is specified through a "URN", too, not just the image referenced in the FO file. This is simply to make it easier for you to set up the demo. The FO file itself will be loaded directly from the Web.

Command line option

Simon Pepping [http://thread.gmane.org/gmane.text.xml.fop.user/29585 added a -catalog option] in [http://svn.apache.org/viewvc?view=revision&revision=825875 revision 825875]. With this option you can render XML with the FOP command and use the catalog resolver:

  $ ./fop -catalog -xml icaatom.html -xsl icaatom.xsl icaatom.pdf

The -catalog option specifically only works for the conversion from XML to output. (In such a case FOP sets up the transformation from XML to FO using XSLT, and in that setup the -catalog option adds a catalog resolver.) Even with the -catalog option the catalog resolver is not used for image retrieval. (Maybe it should, but it has not been thought of.)

Since the W3C started [http://www.w3.org/blog/systeam/2008/02/08/w3c_s_excessive_dtd_traffic blocking abusive request patterns] for DTDs, it may be necessary to use local copies of these DTDs instead. A good way to do this is with the catalog resolver. Errors like the following may happen when you try using a DTD from the W3C's servers:

java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

HowTo/XmlCommonsResolver (last edited 2009-12-04 23:37:07 by JackBates)