xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cedric Staub <cedric.st...@wyona.com>
Subject Combining FOP with multiple transformations
Date Tue, 06 Jul 2010 13:59:38 GMT
Hello everyone

I ran into some problems with FOP today, and the documentation wasn't
able to help me solve them. I am trying to apply multiple transformers
to an XML file before handing it over to FOP in order to generate a
PDF, but I keep running into exceptions. I am using version 0.95.

My code looks like this:
-------
 xmlReader.setContentHandler(i18nTrans);
 i18nTrans.setResult(new SAXResult(xsltTrans));
 xsltTrans.setResult(new SAXResult(fop.getDefaultHandler()));
 xmlReader.parse(new InputSource(docSource));
-------

Where i18nTrans, xsltTrans are of the type TransformerHandler (SAX),
xmlReader is of the type XMLReader (SAX) and fop is of the type Fop.

Here's how I created the fop object:
-------
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 FopFactory fopFactory = FopFactory.newInstance();
 fopFactory.setURIResolver(srcResolver);
 Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, baos);
-------

Now, my problem is the following line from above:
-------
 xsltTrans.setResult(new SAXResult(fop.getDefaultHandler()));
-------

Everytime I call setResult with Fop's default handler as an argument on
any of my TransformerHandlers, I get either a NullPointerException or
a ClassCastException, depending on which transformer I call setResult
on.

I seems this is happening because Fop's default handler returns null
when the function getLexicalHandler is called. This seems to be the
reason for the NullPointerException. 

Now, the SAX API documentation states that: "If the lexical handler is
not set, an attempt should be made by the transformer to cast the
ContentHandler to a LexicalHandler". But casting the return value of
getHandler() to a LexicalHandler fails (FOTreeBuilder cannot be cast to
LexicalHandler).

Is this behaviour correct? If so, how can I apply both transformers
(i18nTrans and xsltTrans) to the XML file before handing it over to Fop?
The documentation says to use the transform(src, res) function from the
Transformer class, but since I have more then one transformer this
approach doesn't seem sufficient (unless I misunderstood it).

I would appreciate it if someone could help me out here, as I'm kind of
lost on how to do this ;-). Thank you in advance.

Greetings,
Cedric

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Mime
View raw message