A few comments inline...
On 01.05.2003 18:47:43 Savino, Matt C wrote:
> Ok here it is. I read all of the POIFS and Coccoon stuff an found there
> is some demand to use the HSSF serializer as a stand-alone piece, ala
> FOP. (Thus avoiding all of the Coccoon overhead and 20MB .war file.)
> This actually used to exist separately that but the POI guys donated it
> to be folded into Coccoon. Supposedly there is a project on the Jakarta
> sandbox called Morphos to run the HSSF serializer separately, but I
> couldn't find it.
Morphos got deleted. I'm still trying to push Nicola Ken Barozzi into a
revival. But he's too deep into work at the moment. The new thing would
be developed in the Krysalis Community Project, probably as "Piper".
Morphos/Piper would also be a nice API for doing XSL:FO transformation.
> No problem, since it seems simple enough anyway (so far).
<snip/>
> /*-----------------------------------------------------------------------------------------*/
> /*--------- This code is common to FOP and HSSF
> -------------------------------------------*/
> /*-----------------------------------------------------------------------------------------*/
> javax.xml.parsers.DocumentBuilderFactory dFactory
> = javax.xml.parsers.DocumentBuilderFactory.newInstance();
> dFactory.setNamespaceAware(true);
> javax.xml.parsers.DocumentBuilder dBuilder =
> dFactory.newDocumentBuilder();
>
> org.w3c.dom.Document xmlDoc = dBuilder.parse(xmlFile);
> javax.xml.transform.dom.DOMSource xmlDomSource = new
> javax.xml.transform.dom.DOMSource(xmlDoc);
>
> org.w3c.dom.Document xslDoc = dBuilder.parse(xsltFile);
> javax.xml.transform.dom.DOMSource xslDomSource = new
> javax.xml.transform.dom.DOMSource(xslDoc);
Why do you parse the whole thing into a DOM? That's very inefficient
when you subsequently give it to JAXP anyway. A StreamSource would be a
lot better!
Have a look at the Example*.java in the latest FOP distribution under
examples/embedding.
>
> javax.xml.transform.TransformerFactory tFactory
> = javax.xml.transform.TransformerFactory.newInstance();
> javax.xml.transform.Templates templates =
> tFactory.newTemplates(xslDomSource);
> javax.xml.transform.Transformer transformer =
> templates.newTransformer();
>
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> /*-----------------------------------------------------------------------------------------*/
> /*--------- End Common Code
> ---------------------------------------------------------------*/
> /*-----------------------------------------------------------------------------------------*/
>
>
>
> /*-----------------------------------------------------------------------------------------*/
> /*--------- FOP-only code
> -----------------------------------------------------------------*/
> /*-----------------------------------------------------------------------------------------*/
>
> org.w3c.dom.Document foDoc = (org.w3c.dom.Document)domResult.getNode();
Again, don't do that. Use SAX as with the HSSF serializer:
Result result = new SAXResult(driver.getContentHandler());
transformer.transform(xml, result);
See how similar the code is to the one for HSSF?
> org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver();
> driver.setErrorDump(true);
> driver.setRenderer(driver.RENDER_PDF);
> driver.setupDefaultMappings() ;
> driver.setOutputStream(out);
> driver.render(foDoc);
>
> response.setContentType("application/pdf");
> /*-----------------------------------------------------------------------------------------*/
> /*--------- End FOP-only Code
> -------------------------------------------------------------*/
> /*-----------------------------------------------------------------------------------------*/
>
>
>
> /*-----------------------------------------------------------------------------------------*/
> /*--------- HSSF-only Code
> ---------------------------------------------------------------*/
> /*-----------------------------------------------------------------------------------------*/
>
> // Set up the HSSF Serializer to serialize the Result to an output
> stream.
> org.apache.cocoon.serialization.HSSFSerializer ser
> = new org.apache.cocoon.serialization.HSSFSerializer();
> ser.initialize(); // don't forget this line or you get a null pointer
> exception
> ser.setOutputStream(out);
>
> // The Serializer functions as a SAX ContentHandler.
> javax.xml.transform.Result result
> = new
> javax.xml.transform.sax.SAXResult((org.xml.sax.ContentHandler)ser);
> transformer.transform(xml, result);
>
> response.setContentType("application/vnd.ms-excel");
> /*-----------------------------------------------------------------------------------------*/
> /*--------- End HSSF-only Code
> ------------------------------------------------------------*/
> /*-----------------------------------------------------------------------------------------*/
>
>
>
> /*-----------------------------------------------------------------------------------------*/
> /*--------- Begin common code again
> -------------------------------------------------------*/
> /*-----------------------------------------------------------------------------------------*/
>
> byte[] content = out.toByteArray();
> response.setContentLength(content.length);
> response.getOutputStream().write(content);
> response.getOutputStream().flush();
> /*-----------------------------------------------------------------------------------------*/
> /*--------- End
> ---------------------------------------------------------------------------*/
> /*-----------------------------------------------------------------------------------------*/
>
Jeremias Maerki
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]