Home > Java > Using Apache FOP with Cooktop

Using Apache FOP with Cooktop

February 12th, 2008

java logoIn one of my projects we use XSTL transformation and Apache FOP to generate PDF files from XML documents. I am using Cooktop as my favorite free XML/XSLT development and test environment for a long time now. A colleague made me aware that it is possible to make Cooktop use custom XSLT engines for transformation.

I just had to download the most current version of Apache FOP (fop-0.94-bin-jdk1.4.zip), unpack it and copy the directories build and lib into the the folder xslt/fop inside the Cooktop installation directory.

Then I edited the preconfigured engine under Options -> System XML -> Manage XSLT Engines in Cooktop. The attributes exec, installed and the environment variable CLASSPATH had to be changed. Here is my final working configuration:

<XSLT
    name="Apache FOP"
    type="external"
  exec=""%CONFIG%\xslt\fop\fop.bat"
	"!xml!" "!xsl!"
	"!res!"
	"!res-no-ext!.pdf""
    path="%CONFIG%\xslt\fop"
    supported_func="system-property"
    http-support="no"
    installed="yes"
    code-url="http://xml.apache.org/fop/">
      <ENVIRONMENT>
         <ITEM
          name="CLASSPATH"
          value="%CONFIG%\xslt\fop\build\fop.jar;
	%CONFIG%\xslt\fop\lib\xercesImpl-2.7.1.jar;
	%CONFIG%\xslt\fop\lib\avalon-framework-4.2.0.jar;
	%CONFIG%\xslt\fop\lib\batik-all-1.6.jar;
	%CONFIG%\xslt\fop\lib\commons-io-1.3.1.jar;
	%CONFIG%\xslt\fop\lib\commons-logging-1.0.4.jar;
	%CONFIG%\xslt\fop\lib\serializer-2.7.0.jar;
	%CONFIG%\xslt\fop\lib\xalan-2.7.0.jar;
	%CONFIG%\xslt\fop\lib\xml-apis-1.3.02.jar;
	%CONFIG%\xslt\fop\lib\xmlgraphics-commons-1.2.jar" />
      </ENVIRONMENT>
   </XSLT>

The last thing I had to do was to edit the fop.bat file containing the command line that calls the FOP processor. My fop.bat lookes like the following after editing it:

@echo off
start /MIN /WAIT java -cp "%CLASSPATH%"
      org.apache.fop.cli.Main -xml %1 -xsl %2 -pdf %4

echo ^<FRAMESET COLS="*"^> >> %3
echo ^<FRAME src= %4 /^>>> %3
echo ^</FRAMESET^> >> %3

Now it is possible to change the XSLT Engine to Apache FOP and to run the XSL transformation. The resulting PDF is stored in a temporary folder and displayed by a frame inside the result tab of Cooktop.

This tutorial helped a lot getting things going. On some machines of my colleagues we had problems with the CLASSPATH environment variable. The solution was to create the path inside the batch file like described in the tutorial.

Java



  1. No comments yet.
  1. No trackbacks yet.