Problem transforming DITA to PDF (incompatable types)

Here should go questions about transforming XML with XSLT and FOP.
rcfiv
Posts: 6

Problem transforming DITA to PDF (incompatable types)

Fri Dec 05, 2014 10:33 pm

I have an XSLT that is working fine outside of oXygen author (v 15.2). I suspect my problem has to do with my jar files conflicting with oXygen's jar files. Here's the error I am getting:

Code: Select all

java.lang.ClassCastException: net.sourceforge.jeuclid.fop.JEuclidXMLHandler incompatible with org.apache.fop.render.XMLHandler
   at org.apache.fop.render.XMLHandlerRegistry.discoverXMLHandlers(XMLHandlerRegistry.java:153)
   at org.apache.fop.render.XMLHandlerRegistry.<init>(XMLHandlerRegistry.java:49)
   at org.apache.fop.apps.FopFactory.<init>(FopFactory.java:180)
   at org.apache.fop.apps.FopFactory.newInstance(FopFactory.java:190)
   at com.ibm.tools.fs.io.XmlFile.transformToPDF(XmlFile.java:719)
   at com.ibm.itso.gasm.gpt.oXygen.plugin.transforms.TransformDeliverableThread.run(TransformDeliverableThread.java:231)


The code I use for transformation is:

Code: Select all

        // Determine if there are options set for rendering pdf
        System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
        FopFactory fopFactory = FopFactory.newInstance();
        if ( options != null ) {
            // Determine if file or url
            if ( !isOptsAURL ) fopFactory.setUserConfig((File)options);
            else {
                // Set in factory
                URL optUrl = (URL) options;
                fopFactory.setUserConfig(optUrl.getProtocol() + "://" + optUrl.getHost() + optUrl.getPath());
            }
        }
       
        // Create driver and set output file
        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, fopFactory.newFOUserAgent(), new java.io.FileOutputStream(destination));

        // transform file
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transform = tFactory.newTemplates(new StreamSource(xslt)).newTransformer();
        for ( NameValuePair pair : params ) {
            transform.setParameter(pair.getName(), pair.getValue());
        }
        transform.setParameter("versionParam", "2.0");
        transform.setOutputProperty(OutputKeys.ENCODING, encoding);
        transform.transform(new StreamSource(this),new SAXResult(fop.getDefaultHandler()));
        System.clearProperty("javax.xml.transform.TransformerFactory");
        fopFactory = null;
        fop = null;
        tFactory = null;
        transform = null;


I'm including fop 1.1 jar in my plugin. Here's a list of my included jar files:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plugin SYSTEM "../plugin.dtd">
<plugin name="GASM Plug-in for oXygen" description="GASM Plug-in for oXygen" version="1.0.0" vendor="GASM" class="com.ibm.itso.gasm.gpt.oXygen.plugin.GasmPlugin" classLoaderType="preferReferencedResources" id="GASM Plug-in for oXygen">
<runtime>
<library name="lib/gasmplugin.jar"/>
<library name="lib/fop.jar"/>
<library name="lib/ibmpkcs.jar"/>
<library name="lib/jaxen-core.jar"/>
<library name="lib/jaxen-jdom.jar"/>
<library name="lib/jdom.jar"/>
<library name="lib/saxpath.jar"/>
<library name="lib/serializer-2.7.0.jar"/>
<library name="lib/tools.jar"/>
<library name="lib/xalan-2.7.0.jar"/>
<library name="lib/xercesImpl-2.7.1.jar"/>
<library name="lib/gson-2.2.2-javadoc.jar"/>
<library name="lib/gson-2.2.2-sources.jar"/>
<library name="lib/gson-2.2.2.jar"/>
</runtime>
<extension type="WorkspaceAccess" class="com.ibm.itso.gasm.gpt.oXygen.plugin.GasmWSPluginExtention" />
</plugin>
Radu
Posts: 5757

Re: Problem transforming DITA to PDF (incompatable types)

Mon Dec 08, 2014 10:52 am

Hi,

Oxygen comes with lots of libraries (among which Xerces, Xalan, FOP 1.1) so ideally you would remove these libraries from your plugin (use them only in the compilation stage):

Code: Select all

<library name="lib/fop.jar"/>
....
<library name="lib/serializer-2.7.0.jar"/>
...
<library name="lib/xalan-2.7.0.jar"/>
....
<library name="lib/xercesImpl-2.7.1.jar"/>


or as I see you have set up in the plugin.xml to prefer the local referenced resources classLoaderType="preferReferencedResources" you could continue adding JARs in it, for example also add in it a reference to your own copies of the jeuclid-core.jar and jeuclid-fop.jar libraries which right now are loaded on the parent class loader.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
rcfiv
Posts: 6

Re: Problem transforming DITA to PDF (incompatable types)

Mon Dec 08, 2014 3:28 pm

Actually, I tried removing the reference to FOP from my plugin and it worked. However, now it's not releasing the PDF file. So I can't open the PDF until I shutdown oXygen Author. Do you know a way around this?
Radu
Posts: 5757

Re: Problem transforming DITA to PDF (incompatable types)

Mon Dec 08, 2014 3:31 pm

Hi,

In the sample code you posted you are creating a new file output stream.
You should keep that created file output stream in a variable and make sure to close the stream at the end, after the generation is finished.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
rcfiv
Posts: 6

Re: Problem transforming DITA to PDF (incompatable types)

Mon Dec 08, 2014 3:34 pm

Radu wrote:Hi,

In the sample code you posted you are creating a new file output stream.
You should keep that created file output stream in a variable and make sure to close the stream at the end, after the generation is finished.

Regards,
Radu


Good idea, I'll give that a try.
rcfiv
Posts: 6

Re: Problem transforming DITA to PDF (incompatable types)

Mon Dec 08, 2014 4:00 pm

Radu wrote:Hi,

In the sample code you posted you are creating a new file output stream.
You should keep that created file output stream in a variable and make sure to close the stream at the end, after the generation is finished.

Regards,
Radu



That worked! Thanks!

Return to “XSLT and FOP”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests