4 Replies Latest reply: Feb 13, 2008 1:11 AM by 26141 RSS

    How to: XDK10 and FOP 20.5 - this works

    109580
      Hi All

      Let me share with you all how to get XDK 10 and FOP 20.5 working. Below are all the versions of files that you require:

      XDK 10
      ------
      I use all the .jar files from the /lib directory

      FOP 20.5
      --------
      fop.jar
      avalon-framework-cvs-20020806.jar
      batik.jar
      xalan-2.4.1.jar
      xercesImpl-2.2.1.jar

      The next thing is that I rewrote the xsqlserializer.jar file and here is the code:

      //***************************************************
      package oracle.xml.xsql.serializers;

      import org.w3c.dom.Document;
      import org.apache.fop.messaging.MessageHandler;
      import oracle.xml.xsql.XSQLPageRequest;
      import oracle.xml.xsql.XSQLDocumentSerializer;
      import org.apache.fop.apps.Driver;
      import org.apache.avalon.framework.logger.Logger;
      import org.apache.avalon.framework.logger.ConsoleLogger;

      /**
      * Tested with the FOP 0.20.3RC release from 19-Jan-2002
      */
      public class XSQLFOPSerializer implements XSQLDocumentSerializer {
      private static final String PDFMIME = "application/pdf";
      public void serialize(Document doc, XSQLPageRequest env) throws Throwable {
      try {

      // First make sure we can load the driver
      Driver FOPDriver = new Driver();

      // Tell FOP not to spit out any messages by default.
      // You can modify this code to create your own FOP Serializer
      // that logs the output to one of many different logger targets
      // using the Apache LogKit API
      Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
      MessageHandler.setScreenLogger(logger);
      FOPDriver.setLogger(logger);

      // Some of FOP's messages appear to still use MessageHandler.
      MessageHandler.setOutputMethod(MessageHandler.NONE);

      // Then set the content type before getting the reader/
      env.setContentType(PDFMIME);

      FOPDriver.setOutputStream(env.getOutputStream());
      FOPDriver.setRenderer(FOPDriver.RENDER_PDF);
      FOPDriver.render(doc);
      }
      catch (Exception e) {
      // Cannot write PDF output for the error anyway.
      // So maybe this stack trace will be useful info
      e.printStackTrace(System.err);
      }
      }
      }
      //*******************************************************

      The above defnitely works for me and should work for you too. Think of it as an early christmas present.

      Best wishes

      Richard