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.
Please note that this currently doesn't work, yet! And it will only work with the new FOP!
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/
The Example
You can download the source for the example from the web using the following links:
The example Java file:
http://people.apache.org/~jeremias/fop-xml-resolver-demo/ExampleFO2PDFWithResolver.java The example catalog:
http://people.apache.org/~jeremias/fop-xml-resolver-demo/fop-demo-catalog.xml The example FO file:
http://people.apache.org/~jeremias/fop-xml-resolver-demo/xml-resolver-demo.fo (no need to download that!)
Setup instructions
Set up the Java file in a Java project.
Add resolver.jar to the classpath.
Set the following system property for the launch configuration (or the command-line):
-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.
Run the ExampleFO2PDFWithResolver class.
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.
TODO
At the moment, this example doesn't work, since the resolution mechanism requires StreamSource instance to be returned by the resolver, readily set up with an InputStream. The XML Commons Resolver doesn't do that. It actually returns a SAXSource on which the SystemID is set. The ImageFactory there has to be able to convert the SystemID into a URL and get the InputStream through that URL. Care needs to be taken that the InputStream is properly closed after usage.