OK, the ByteArrayOutputStream solves the NullPointer Exception. The only
problem left is there is none of my xml data in the pdf. I only get the
static header of the xsl document :o/

Do we have to change the sequence somehow?




> --- Ursprüngliche Nachricht ---
> Von: Jeremias Maerki <[EMAIL PROTECTED]>
> An: fop-users@xmlgraphics.apache.org
> Betreff: Re: How to pass input of xml tranfs. to xslt transf. ?
> Datum: Thu, 08 Dec 2005 16:04:32 +0100
> 
> I'm not sure why you get an error that "handler is null". The setup
> looks ok now. The only thing that's missing is the ByteArrayOutputStream
> that FOP writes the PDF output to. In order to make PDF displaying work
> you need to know the size of the PDF so there's no way around buffering
> the PDF into a byte array. See some changes inline below.
> 
> On 08.12.2005 15:50:48 Peter.Neu wrote:
> > First of all. Thanks for taking so much time for my problem :o)
> > 
> > I tried to include your code. It's attached below:
> > 
> > 1. the transformer factory with the implementation I use does not
> support
> > this call: this.transformerFactory.newTransformerHandler(xsltSrc); - so
> I
> > modified it a bit.
> > 
> > 2. When I run the code I get the error that the handler is null :o/
> > 
> > 3. I'm still not sure how to output the stuff to the browser.
> > 
> > cheers,
> > Pete
> > 
> > Code:
> > 
> > SAXTransformerFactory tf = (SAXTransformerFactory)
> > SAXTransformerFactory.newInstance();
> > // my static xsl file in here
> > Source xsltSrc = new StreamSource((new
> > File(session.getServletContext().getRealPath("/xml/nbw.xsl"))));
> > TransformerHandler handler = tf.newTransformerHandler(xsltSrc);
> > 
> > //Prepare FOP here
> > Driver driver = new Driver();
> > driver.setLogger(this.log2);
> > driver.setRenderer(Driver.RENDER_PDF);
> > 
> //Setup a buffer to obtain the content length
> //Use the ByteArrayOutputStream from Jakarta Commons IO. It's more
> //memory-efficient
> ByteArrayOutputStream out2 = new ByteArrayOutputStream();
> driver.setOutputStream(out2);
> > 
> > SAXResult result = new SAXResult(driver.getContentHandler());
> > handler.setResult(result);
> > 
> > 
> > XmlTransformer xmlt = new XmlTransformer();
> > xmlt.doXMLTransform(handler);
> > /* this  is nothing but
> > *   handler.startDocument();
> >     handerl.startElement("BLA");
> >     handerl.endElement("BLA");
> >     hd.endDocument();
> > */
> > 
> > //Prepare response
> > response.setContentType("application/pdf");
> > //  response.setContentLength(out2.size());
> > 
> > //Send content to Browser
> 
> response.getOutputStream().write(out2.toByteArray());
> 
> > response.getOutputStream().flush();
> > 
> > 
> > ---------------------------------------------------------------------
> > 
> > > --- Ursprüngliche Nachricht ---
> > > Von: Jeremias Maerki <[EMAIL PROTECTED]>
> > > An: fop-users@xmlgraphics.apache.org
> > > Betreff: Re: How to pass input of xml tranfs. to xslt transf. ?
> > > Datum: Thu, 08 Dec 2005 14:53:19 +0100
> > > 
> > > It's unclear what this XmlTransformer does exactly. You only
> instantiate
> > > a new instance but you do nothing with it.
> > > 
> > > Anyway, I'll try to rework your code so you can pipe this stuff
> > > together:
> > > 
> > > 1. You don't need the FileOutputStream anymore.
> > > 2. No need to configure the serializer if you just pipe the stuff
> > > through.
> > > 3. Since you do only an identity transform you don't need the first
> > > TransformerHandler. Instead set up the XSLT transformation as a
> > > TransformerHandler.
> > > 
> > > SAXTransformerFactory tf =
> > > (SAXTransformerFactory)SAXTransformerFactory.newInstance();
> > > 
> > > // my static xsl file in here
> > > Source xsltSrc = new StreamSource((new File(("nbw.xsl"))));
> > > TransformerHandler handler =
> > > this.transformerFactory.newTransformerHandler(xsltSrc);
> > > 
> > > //Prepare FOP here
> > > 
> > > SAXResult result = new SAXResult(driver.getContentHandler());
> > > handler.setResult(streamResult);
> > > 
> > > XmlTransformer xmlt = new XmlTransformer(handler);
> > > //Start the XML generation, however you do this (see question above)
> > > xmlt.doSomething();
> > > 
> > > This should send the SAX events generated by your XmlTransformer (not
> an
> > > ideal name IMO) through the TransformerHandler (for the XSLT
> transform)
> > > and its output further on to FOP.
> > > 
> > > On 08.12.2005 14:31:23 Peter.Neu wrote:
> > > >     protected void JAXPTransform(HttpSession session,
> > > HttpServletResponse response, HttpServletRequest req) throws Exception
> {
> > > > 
> > > > 
> > > >         // Here I provide a file output stream for the result of the
> sax
> > > transformation -> what I need is some kind of stream
> > > >               
> > > >         File xmlfile = new
> > > File(session.getServletContext().getRealPath("/xml/"), "nbw.xml");
> > > >         OutputStream out = new java.io.FileOutputStream(xmlfile);
> > > >         
> > > >         // set the stream result for the transformation
> > > >         StreamResult streamResult = new StreamResult((out));
> > > >         SAXTransformerFactory tf = (SAXTransformerFactory)
> > > SAXTransformerFactory.newInstance();
> > > >         TransformerHandler hd = tf.newTransformerHandler();
> > > >         Transformer serializer = hd.getTransformer();
> > > >         
> > > >         serializer.setOutputProperty(OutputKeys.ENCODING,
> "ISO-8859-1");
> > > >         serializer.setOutputProperty(OutputKeys.INDENT, "yes");
> > > >         
> > > >         hd.setResult(streamResult);
> > > > 
> > > >         // the whole creation of the xml is done in the
> XmlTransformer
> > > which writes to the output file but should write it to some kind of
> stream
> > > >         XmlTransformer xmlt = new XmlTransformer(hd);
> > > >                 
> > > >         //from here on just the basic servlet example from here : 
> > > >         //
> http://xmlgraphics.apache.org/fop/0.20.5/servlets.html#xslt
> > > >         Driver driver = new Driver();
> > > >         driver.setLogger(this.log2);
> > > >         driver.setRenderer(Driver.RENDER_PDF);
> > > > 
> > > >         //Setup a buffer to obtain the content length
> > > >         ByteArrayOutputStream out2 = new ByteArrayOutputStream();
> > > >         driver.setOutputStream(out2);
> > > > 
> > > >         //Setup Transformer
> > > >         BufferedReader r = req.getReader();
> > > > 
> > > > 
> > > >         this.transformerFactory = TransformerFactory.newInstance();
> > > >         
> > > >         // my static xsl file in here
> > > >         Source xsltSrc = new StreamSource((new File(("nbw.xsl"))));
> > > >         Transformer transformer =
> > > this.transformerFactory.newTransformer(xsltSrc);
> > > > 
> > > >         //Make sure the XSL transformation's result is piped through
> to
> > > FOP
> > > >         Result res = new SAXResult(driver.getContentHandler());
> > > > 
> > > >         //Setup input
> > > >         // This is the point where im stuck -> I don't know how to
> > > insert a stream in here
> > > >        Source src = new StreamSource(new File("foo.xml"));
> > > > 
> > > >         //Start the transformation and rendering process
> > > >         transformer.transform(src, res);
> > > > 
> > > >         //Prepare response
> > > >         response.setContentType("application/pdf");
> > > >         response.setContentLength(out2.size());
> > > > 
> > > >         //Send content to Browser
> > > >         response.getOutputStream().write(out2.toByteArray());
> > > >         response.getOutputStream().flush();
> > > > 
> > > > 
> > > >     }
> > > 
> > > 
> > > 
> > > Jeremias Maerki
> > > 
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > 
> > 
> > -- 
> > Telefonieren Sie schon oder sparen Sie noch?
> > NEU: GMX Phone_Flat http://www.gmx.net/de/go/telefonie
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> Jeremias Maerki
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to