Hm,

perhaps the better choice is

public void setOutputStream(OutputStream out)
                    throws IOException
{

      this.output = new MyOutputStream(out, "c:/temp/myout.pdf");
        super.setOutputStream(this.output);
}


This passes the modified output stream to the FOPSerializer.

Regards
Holger

Jan Kohnert <[EMAIL PROTECTED]> schrieb am 16.09.2005 13:17:58:

> Holger,

>  
> no its not working. I m still getting an empty file + no outputfile
> to the client. :(

> I checked the FOPSerializers sources and founf out that it might be
> a bit more difficult:

>     /**
>      * Create the FOP driver
>      * Set the <code>OutputStream</code> where the XML should be serialized.
>      */
>     public void setOutputStream(OutputStream out) {
>        
>         // Give the source resolver to Batik which is used by FOP
>         //SourceProtocolHandler.setup(this.resolver);

>  
>         // load the fop driver
>         this.driver = new Driver();
>         this.driver.setLogger(this.logger);
>         if (this.rendererName == null) {
>             this.renderer = factory.createRenderer(mimetype);
>         } else {
>             try {
>                 this.renderer = (Renderer)ClassUtils.
> newInstance(this.rendererName);
>             } catch (Exception e) {
>                 if (getLogger().isWarnEnabled()) {
>                     getLogger().warn("Cannot load class " + this.
> rendererName, e);
>                 }
>                 throw new CascadingRuntimeException("Cannot load
> class " + this.rendererName, e);
>             }
>         }
>         this.driver.setRenderer(this.renderer);
>         this.driver.setOutputStream(out);
>         setContentHandler(this.driver.getContentHandler());
>     }

> but by using this code instead I still did'nt get any output.
>  
> Regards,
> Jan
>  
>
> Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Gesendet: Freitag, 16. September 2005 12:41
> An: [email protected]
> Betreff: Antwort: AW: AW: AW: Antwort: Saving the Outputstream

>
> Jan,
>
> first I think you must override the serializer's setOutputStream()
> method to initialize your stream rather than simply replacing output
> with your stream. I think this method will be called automatically
> from within Cocoon, and if you do it like you did, maybe the
> "output" element will be replaced by the original (single output)
> stream. This would explain why an empty file is created.
>
> public void setOutputStream(OutputStream out)
>                     throws IOException
> {
>         this.output = new MyOutputStream(out, "c:/temp/myout.pdf");
>
> }
>
> and remove the code from startDocument(). Please let me know if it works!
>
> Regards
> Holger
>
> Jan Kohnert <[EMAIL PROTECTED]> schrieb am 16.09.2005 11:18:36:
>
> > Holger,
> >  
> > so far I wrote the following code. Works pretty fine except that I
> > get an empty file on the servers harddrive :(
> > Do you have any Idea what I m doing wrong?
> > Thanks !
> >  
> > Regards,
> > Jan
> >  
> > code:
> > package swl.test.cocoon.serialization;
> >  
> > import java.io.FileOutputStream;
> > import java.io.IOException;
> > import java.io.OutputStream;
> >  
> > import org.apache.cocoon.serialization.FOPSerializer;
> > import org.xml.sax.SAXException;
> >  
> > public class Swlfo2pdf extends FOPSerializer {
> >  
> >  MyOutputStream output;
> >  
> >
> //--------------------------------------------------------------------------------------------------------
> >  public void startDocument() throws SAXException {
> >   output = new MyOutputStream(output, "c:/temp/myout.pdf");
> >   super.startDocument();
> >  }
> >
> //--------------------------------------------------------------------------------------------------------
> >  public void endDocument() throws SAXException {
> >   super.endDocument();
> >  }
> >  
> >
> //*********************************************************************************************************
> >  public static class MyOutputStream extends OutputStream {
> >  
> >   private OutputStream origOut;
> >   private OutputStream tmpfileOut;  
> >  
> >   public MyOutputStream(OutputStream out, String tmp) {
> >    origOut = out;
> >    try {
> >     tmpfileOut = new FileOutputStream(tmp);
> >    } catch (IOException ex) {
> >    }
> >   }
> >
> //--------------------------------------------------------------------------------------------------------
> >   public void write(int b) throws IOException {
> >    try {
> >     if (tmpfileOut != null)
> >      tmpfileOut.write(b);
> >    }
> >    catch (IOException ex) {
> >    }
> >    origOut.write(b);
> >   }
> >
> //--------------------------------------------------------------------------------------------------------
> >   public void write(byte[] b) throws IOException{
> >    try{
> >     if (tmpfileOut != null)
> >      tmpfileOut.write(b);    
> >    }
> >    catch (IOException ex){    
> >    }
> >    origOut.write(b);
> >   }
> >
> //--------------------------------------------------------------------------------------------------------
> >   public void write(byte[] b, int off, int len) throws IOException{
> >    try{
> >     if (tmpfileOut != null)
> >      tmpfileOut.write(b, off, len);    
> >    }
> >    catch (IOException ex){    
> >    }
> >    origOut.write(b, off, len);  
> >   }
> >
> //--------------------------------------------------------------------------------------------------------
> >   public void close() throws IOException {
> >    try {
> >     tmpfileOut.close();
> >    } catch (IOException ex) {
> >    }
> >    //origOut.close();
> >   }
> >
> //--------------------------------------------------------------------------------------------------------
> >  }
> > }
> >
> > Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > Gesendet: Donnerstag, 15. September 2005 13:38
> > An: [email protected]
> > Betreff: AW: AW: AW: Antwort: Saving the Outputstream
>
> >
> > Jan,
> >
> > I am sorry I couldn't find the snippet.
> >
> > > So, how do I tell myoutoutstream that it has an OutputStream with
> > > the same content as the original OutoutStream but is pointing to a
> > > completely different filelocation.
> >
> > You simply make your OutputStream write into 2 streams and replace
> > the original stream with your "double stream", that's why you need
> > to override setOutputStream(). The Serializer should use your custom
> > OutputStreamClass instead of the original.
> >
> > From the outside it looks like one stream, the inside writes into 2
> > different streams. I remember I wrote a class which overwrites all
> > of the write() methods of OutputStream
> >
> > Check this: http://java.sun.com/j2se/1.4.
> 2/docs/api/java/io/OutputStream.html
> >
> > One example:
> >
> > class OutOutStream extends FileOutputStream {
> >         OUtputStream os;
> >
> >         // Create the "double" outputstream: Constructor is taking
> > the original stream
> >
> >         public OutOutStream(OutputStream streamone, File outputfile) {
> >                 super(outputfile); // don't know exactly how...
> >                 this.os = streamone;
> >         }
> >
> >         // Override all other write() methods like this:
> >         public void write(byte[] b) {
> >                 os.write(b); // original stream
> >                 this.write(b); // secondary stream
> >         }
> >
> > }
> >
> > ---
> >
> > class yourserializer extends ...Serializer {
> >         ...
> >         setOutputStream() {
> >                 // create and use the "double stream"
> >                 output = new OutOutStream(super.output, new
> > File("myoutput.dfile"));
> >         }
> >
> > }
> >
> > Let me know if this works, I haven't tried this.
> >
> > Regards
> > Holger
> >
> > Jan Kohnert <[EMAIL PROTECTED]> schrieb am 15.09.2005 11:05:32:
> >
> > > Holger,
> > >  
> > > thanks for the hint!
> > > One point that is unclear for me is, how to tell a OutoutStream
> > > where it is supposed to point on except by using the contructor.
> > > So, how do I tell myoutoutstream that it has an OutputStream with
> > > the same content as the original OutoutStream but is pointing to a
> > > completely different filelocation.
> > >  
> > > "I remember I have a kind of CopyStream class somewhere. I'll
> have a look."
> > >  
> > > Would be cool if you finde it!
> > >  
> > > Regards,
> > > Jan
> > >
> > > Von: [EMAIL PROTECTED] [mailto:holger.
> [EMAIL PROTECTED]
> > > Gesendet: Mittwoch, 14. September 2005 13:52
> > > An: [email protected]
> > > Betreff: AW: AW: Antwort: Saving the Outputstream
> >
> > >
> > > Jan,
> > >
> > > at a first glimpse, your class is not doing anything but creating an
> > > empty file. There's no link between your OutputStream and the data.
> > >
> > > The serializer provides its own output stream (super.output
> > according to this
> > > http://wiki.apache.org/cocoon/WritingSerializers )
> > >
> > > Perhaps you need to replace trhe output stream by a class which
> > > writes the output to both streams: The web browser and - in addition
> > > to that - to a file stream.
> > >
> > > I think an approach would be:
> > > 1. try to create an OutputStream class which does the output two 2
> > > streams (e.g. CopyOutputStream)
> > > 2. overwrite the setOutputStream() method in the Swlfo2pdf class
> > > 3. Initialize your OutputStream class using the original output
> > > stream super.output as seconde output stream target
> > >
> > > Anyone here who already did something like that? I remember I have a
> > > kind of CopyStream class somewhere. I'll have a look.
> > >
> > > Regards
> > > Holger
> > >
> > > Jan Kohnert <[EMAIL PROTECTED]> schrieb am 14.09.2005 13:25:55:
> > >
> > > > Yes offcause I cant do this :)
> > > >  
> > > > But some things have changed. Insted of using a Reader I extandet
> > > > the fo2pdf Serializer.
> > > >
> > > > package swl.test.cocoon.serialization;
> > > >
> > > > import java.io.FileNotFoundException;
> > > > import java.io.FileOutputStream;
> > > >
> > > > import org.apache.cocoon.serialization.FOPSerializer;
> > > > import org.xml.sax.SAXException;
> > > >
> > > > public class Swlfo2pdf extends FOPSerializer {
> > > >    
> > > >
> > > >    public void endDocument(){
> > > >       try {
> > > >          super.endDocument();
> > > >          FileOutputStream myout = new FileOutputStream("c:
> > > /temp/myout.pdf");
> > > >       } catch (SAXException e) {
> > > >          // TODO Auto-generated catch block
> > > >          e.printStackTrace();
> > > >       } catch (FileNotFoundException e) {
> > > >          // TODO Auto-generated catch block
> > > >          e.printStackTrace();
> > > >       }
> > > >    }
> > > > }
> > > >  
> > > > The serializer Swlfo2pdf runs great. I m getting the requestet
> > > > dokument with it, plus an empty file c:/temp/myout.pdf. But offcause
> > > > this is'nt all I need. Instead of an empty document I want to get a
> > > > identical copy of the FOPSerializer's output on a servers directory
> > > > of my choise). But so far I've no Idea how this is suposed to work :(
> > > >  
> > > > my xmap:
> > > > <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
> > > >     <!-- =========================== components
> > > > =================================== -->
> > > >     <map:components>
> > > >         <map:transformers default="xslt">
> > > >             <map:transformer name="xslt-saxon" pool-grow="2" pool-
> > > > max="32" pool-min="8" src=""> > > > TraxTransformer">
> > > >                 <use-request-parameters>false</use-request-parameters>
> > > >                 <use-browser-capabilities-db>false</use-browser-
> > > > capabilities-db>
> > > >                 <xslt-processor-role>saxon</xslt-processor-role>
> > > >             </map:transformer>
> > > >         </map:transformers>
> > > >         <map:serializers default="html">
> > > >             <map:serializer name="fo2pdf" src=""> > > > > serialization.FOPSerializer" mime-type="application/pdf"/>
> > > >             <map:serializer name="Swlfo2pdf" src=""> > > > > serialization.Swlfo2pdf" mime-type="application/pdf"/>
> > > >         </map:serializers>
> > > >     </map:components>
> > > >     <!-- =========================== Views
> > > > =================================== -->
> > > >     <map:views>
> > > >         <map:view name="content" from-label="content">
> > > >             <map:serialize type="xml"/>
> > > >         </map:view>
> > > >         <map:view name="links" from-position="last">
> > > >             <map:serialize type="links"/>
> > > >         </map:view>
> > > >     </map:views>
> > > >     <map:pipelines>
> > > >         <!-- =========================== Pipelines
> > > > ================================= -->
> > > >         <map:pipeline>
> > > >             <!-- PDF Pipeline -->
> > > >             <map:match pattern="*/*/*.pdf">
> > > >                 <map:generate src=""> > > > > /worknt/hausn/xbefund/xml/{1}/{3}.xml"/>
> > > >                 <map:transform type="xslt-saxon" src=""> > > > > /worknt/hausn/xbefund/stylesheets/{1}/{2}.xsl"/>
> > > >                 <map:serialize type="Swlfo2pdf"/>
> > > >             </map:match>
> > > >         </map:pipeline>
> > > >     </map:pipelines>
> > > > </map:sitemap>
> > > >  
> > > >  
> > > > Thanks, Jan
> > > >  
> > > >
> > > > Von: [EMAIL PROTECTED] [mailto:holger.
> > [EMAIL PROTECTED]
> > > > Gesendet: Mittwoch, 14. September 2005 11:00
> > > > An: [email protected]
> > > > Cc: '[email protected]'; users-return-82225-holger.
> > > > [EMAIL PROTECTED]
> > > > Betreff: Antwort: Saving the Outputstream
> > >
> > > >
> > > > Hi,
> > > >
> > > > Could you provide (copy/paste) the reader source and sitemap.xmap
> > > > extract which you are using?
> > > >
> > > > Seems as if the attachment is broken. I suggest not to attach files
> > > > to the mailing list.
> > > >
> > > > Regards
> > > > Holger
> > > >
> > > > [EMAIL PROTECTED]
> > > > schrieb am 13.09.2005 16:04:36:
> > > >
> > > > > Hello List,
> > > > >
> > > > > I m creating PDF Files using cocoons fo2pdf serializer.
> Everything works
> > > > > fine. Now I want to save the created pdf file on a servers
> directory. I
> > > > > wrote a Reader to get access to the outputstream in order to
> > save it. The
> > > > > directory name is dependent on the transferred xml files name.
> > > To to this I
> > > > > wrote my own Reader. Sadly closely nothing happens when I try
> > to save the
> > > > > outputstream.
> > > > >
> > > > > In Addition my Reader sources and my xconf.
> > > > >
> > > > > Can anyone please help me? Thanks!
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > [Anhang "src.rar" gelöscht von Holger Willenborg/Muenster/Armacell]
> > > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to