Fawzib Rojas wrote:
I asked a few days ago about creating a PDF on a background thread (Subject:Create PDF on background) but didn't got an answer I could use. Our users requests the PDF and it cannot be batched. Sometimes it takes a few minutes to be created. What I want to do is something like this:

<map:match pattern="background-pdf-document">
 <map:generate type="custom_generator" src=""/>
 <map:transform src="my_transform.xsl"/>
 <map:serialize type="background">
   <!-- pipeline for pdf (or anything) to be run in the background -->
   <!-- because it takes a while to be created -->
<map:parameter name="actual_pipeline" value="cocoon:/pdf_pipeline" type="fo2pdf"/> <!-- pipeline to display progress of pipeline 1 refreshing it until pipeline 1 is done? --> <map:parameter name="progress_pipeline" value="cocoon:/progress_pipeline" type="html"/>
 </map:serialize>
</map:match>

Is something like this possible? Maybe a custom serializer? Is there another way to do this?


Seems to me you could accomplish this fairly easily with Flowscript. Something like:

function pdfDocumentFlow() {
        // Start the PDF running in the background, it will be
        // written to the OutputStream:
        var outputStream = new MySpecialOutputStream();
        cocoon.processPipelineTo(
                "pdf-generation-pipeline",
                {param1:value1, param2:value2},
                outputStream
        );

        // Display the waiting page until complete:
        while(!outputStream.isClosed()) {
                sendPageAndWait("waiting-screen");
        }

        // PDF is finished, now display it:
        cocoon.sendPage(
                "pdf-display-pipeline",
                {byteArray : outputStream.toByteArray()}
        );
}

Where "pdf-generation-pipeline" is the normal pipeline producing your PDF document, "waiting-screen" is obviously the screen saying the operation is still in process (and probably refreshes occasionally to call the continuation), and "pdf-display-pipeline" is a pipeline that simply reads from the byte array you pass it from the flow, e.g.

<map:match pattern="pdf-display-pipeline">
        <map:read src="{module:flow-attr:byteArray}"
                  mime-type="application/x-pdf" />
</map:match>

The other big missing piece is finding or creating an OutputStream implementation ("MySpecialOutputStream" in the above code) that knows when it's been closed, so you can test for when the PDF has been completely generated. You can create a Java class that extends ByteArrayOutputStream or FileOutputStream, for instance. Or you can probably do this directly in Javascript as well, see http://www.mozilla.org/rhino/scriptjava.html for how to extend java classes in JS.

This is all off the top of my head of course. Hope it at least gives you a starting point.
--Jason




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