Return-Path: Delivered-To: apmail-xml-fop-user-archive@xml.apache.org Received: (qmail 72251 invoked by uid 500); 1 May 2003 17:33:50 -0000 Mailing-List: contact fop-user-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: fop-user@xml.apache.org Delivered-To: mailing list fop-user@xml.apache.org Received: (qmail 72238 invoked from network); 1 May 2003 17:33:50 -0000 Received: from hornisse.agrinet.ch (HELO mail02.agrinet.ch) (212.28.134.115) by daedalus.apache.org with SMTP; 1 May 2003 17:33:50 -0000 Received: from [192.168.1.33] (81.6.8.202) by mail02.agrinet.ch (7.0.012) (authenticated as dev.jeremias@greenmail.ch) id 3E943C8A000F3E30 for fop-user@xml.apache.org; Thu, 1 May 2003 19:33:53 +0200 Date: Thu, 01 May 2003 19:33:51 +0200 From: Jeremias Maerki To: fop-user@xml.apache.org Subject: Re: Seeking advice on HSSF In-Reply-To: <4B4BB815EBADD411AD000090274F060C03716EE6@sjhwmis2.metpath.com> References: <4B4BB815EBADD411AD000090274F060C03716ED7@sjhwmis2.metpath.com> <4B4BB815EBADD411AD000090274F060C03716EE6@sjhwmis2.metpath.com> Message-Id: <20030501192353.4F7F.DEV.JEREMIAS@greenmail.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Becky! ver. 2.05.08 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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). > /*-----------------------------------------------------------------------------------------*/ > /*--------- 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: fop-user-unsubscribe@xml.apache.org For additional commands, e-mail: fop-user-help@xml.apache.org