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]

Reply via email to