You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Sébastien Geindre <se...@meteo.fr> on 2007/01/18 11:54:44 UTC

Aplly transformation to a xml post data

hello all,

I handle a upload request send by cocoon forms with flowscript :
   var uploadWidget = form.lookupWidget("upload");
   var stream = uploadWidget.getValue().getInputStream();
 
I'd like to transform the upload stream (which is XML) via a pipeline :
  cocoon.processPipelineTo(
       'uri',
       stream,
       ??);

what kind of generator i must use ?

   <map:match pattern="uri">
     <map:generator type ="/*????????*/"/>
    <map:transform src="tranform.xsl"/>
     <map:serialize type="xml"/>
   </map:match>

thanks,
Sébastien.

Re: Aplly transformation to a xml post data

Posted by "Steven D. Majewski" <sd...@virginia.edu>.
On Jan 18, 2007, at 6:46 AM, Sébastien Geindre wrote:

> Steven D. Majewski wrote:
>>
>> On Jan 18, 2007, at 5:54 AM, Sébastien Geindre wrote:
>>
>>> hello all,
>>>
>>> I handle a upload request send by cocoon forms with flowscript :
>>>    var uploadWidget = form.lookupWidget("upload");
>>>    var stream = uploadWidget.getValue().getInputStream();
>>>
>>> I'd like to transform the upload stream (which is XML) via a  
>>> pipeline :
>>>   cocoon.processPipelineTo(
>>>        'uri',
>>>        stream,
>>>        ??);
>>>
>>> what kind of generator i must use ?
>>>
>>>    <map:match pattern="uri">
>>>      <map:generator type ="????????"/>
>>>     <map:transform src="tranform.xsl"/>
>>>      <map:serialize type="xml"/>
>>>    </map:match>
>>>
>>
>>
>> I'm not using the uploadWidget -- I just have this in my form:
>>
>>     <input type="file" name="pubxml" />
>>
>>
>> My form action is calling a flowscript, which then calls one
>> of these pipelines, using the upload://partname  internal protocol:
>
> Could you send us an example of your flowscript ?
> The one which call the pipeline xml-upload-xml for instance.
>
> Thanx a lot !


Well -- that's the part I'm working on right now, but I have a  
working stub.
( See other thread about realpath: I want to move the file to a work  
area,
   display styled results and as whether to move to published area,  
after
   checking for file-exists, login and session attributes, and some  
other things.)

For the stub, so far, the pipeline is:

     <map:pipeline>
       <map:match pattern="xml-upload-process">
         <map:call function="upload" >
           <!-- <map:parameter name="temp_dir" value="/tmp" /> -->
           <map:parameter name="temp_dir" value="{contextpath:./ 
work}" />
         </map:call>
       </map:match>
     </map:pipeline>

( I just changed temp/work destination from /tmp to  {contextpath:./ 
work} which will
    resolve to  ./work directory under my mounted sitemap directory. )



And the flowscript stub (after removing some site specific parameter  
processing) is:



importClass( Packages.org.apache.commons.transaction.util.FileHelper );

function upload() {
     var docsrc = cocoon.request.getParameter( "pubxml");

     // make a copy of uploaded file to tmp ...
     if ( FileHelper.fileExists( docsrc ) ) {
         var doc = java.io.File( docsrc );
         FileHelper.copy( doc, java.io.File 
( cocoon.parameters.temp_dir, doc.getName() ));

     }

     cocoon.sendPage( 'xml-upload-doc' , {} );

}


Parameter pubxml ( which is the name of the file input in the form,
and is also used as the partname in upload:/pubxml ) gets the pathname
of the file uploaded to cocoon's temporary upload directory.

The files get removed from that directory at the completion of the  
pipeline,
so it is copied to another location. The pipeline in 'xml-upload-doc' is
using upload:/pubxml as the source -- it still works in the sub- 
pipeline,
but at one point I inserted an interim sendPageAndWait call, but the
uploaded file disappears before the continuation is resumed so that
breaks the xml-upload-doc pipeline. Any processing after resumption of
a continuation would have to use the copied file as the source.


The display of the uploaded xml would work without the flowscript --
you would just need to call xml-upload-doc pipeline from the form  
action,
but in that case, the file would disappear after it was displayed.
But perhaps a SourceWriter could be inserted in the middle of the  
pipeline
to write the uploaded file somewhere.


-- Steve Majewski / UVA Alderman Library




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Aplly transformation to a xml post data

Posted by Sébastien Geindre <se...@meteo.fr>.
Steven D. Majewski wrote:
>
> On Jan 18, 2007, at 5:54 AM, Sébastien Geindre wrote:
>
>> hello all,
>>
>> I handle a upload request send by cocoon forms with flowscript :
>>    var uploadWidget = form.lookupWidget("upload");
>>    var stream = uploadWidget.getValue().getInputStream();
>>
>> I'd like to transform the upload stream (which is XML) via a pipeline :
>>   cocoon.processPipelineTo(
>>        'uri',
>>        stream,
>>        ??);
>>
>> what kind of generator i must use ?
>>
>>    <map:match pattern="uri">
>>      <map:generator type ="????????"/>
>>     <map:transform src="tranform.xsl"/>
>>      <map:serialize type="xml"/>
>>    </map:match>
>>
>
>
> I'm not using the uploadWidget -- I just have this in my form:
>
>     <input type="file" name="pubxml" />
>
>
> My form action is calling a flowscript, which then calls one
> of these pipelines, using the upload://partname  internal protocol:

Could you send us an example of your flowscript ?
The one which call the pipeline xml-upload-xml for instance.

Thanx a lot !
>
>
>
>     <!-- display upload as xml -->
>     <map:pipeline>
>       <map:match pattern="xml-upload-xml">
>         <map:generate src="upload://pubxml" />
>         <map:serialize type="xml" />
>       </map:match>
>     </map:pipeline>
>
>     <!--  display upload styled as html  -->
>     <map:pipeline>
>       <map:match pattern="xml-upload-doc">
>       <map:generate src="upload://pubxml" />
>       <map:transform src="xsl/document.xsl" />
>       <map:serialize type="html" />
>       </map:match>
>     </map:pipeline>
>
>
> -- Steve Majewski
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Aplly transformation to a xml post data

Posted by "Steven D. Majewski" <sd...@virginia.edu>.
On Jan 18, 2007, at 5:54 AM, Sébastien Geindre wrote:

> hello all,
>
> I handle a upload request send by cocoon forms with flowscript :
>    var uploadWidget = form.lookupWidget("upload");
>    var stream = uploadWidget.getValue().getInputStream();
>
> I'd like to transform the upload stream (which is XML) via a  
> pipeline :
>   cocoon.processPipelineTo(
>        'uri',
>        stream,
>        ??);
>
> what kind of generator i must use ?
>
>    <map:match pattern="uri">
>      <map:generator type ="????????"/>
>     <map:transform src="tranform.xsl"/>
>      <map:serialize type="xml"/>
>    </map:match>
>


I'm not using the uploadWidget -- I just have this in my form:

	<input type="file" name="pubxml" />


My form action is calling a flowscript, which then calls one
of these pipelines, using the upload://partname  internal protocol:



     <!-- display upload as xml -->
     <map:pipeline>
       <map:match pattern="xml-upload-xml">
         <map:generate src="upload://pubxml" />
         <map:serialize type="xml" />
       </map:match>
     </map:pipeline>

     <!--  display upload styled as html  -->
     <map:pipeline>
       <map:match pattern="xml-upload-doc">
       <map:generate src="upload://pubxml" />
       <map:transform src="xsl/document.xsl" />
       <map:serialize type="html" />
       </map:match>
     </map:pipeline>


-- Steve Majewski



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Aplly transformation to a xml post data

Posted by Sébastien Geindre <se...@meteo.fr>.
Thanx,
i've found this page http://cocoon.apache.org/2.1/861.daisy.html which 
describe what you 'v mentioned.


Jason Johnston wrote:
> Sébastien Geindre wrote:
>> hello all,
>>
>> I handle a upload request send by cocoon forms with flowscript :
>>    var uploadWidget = form.lookupWidget("upload");
>>    var stream = uploadWidget.getValue().getInputStream();
>>  
>> I'd like to transform the upload stream (which is XML) via a pipeline :
>>   cocoon.processPipelineTo(
>>        'uri',
>>        stream,
>>        ??);
>>
>> what kind of generator i must use ?
>>
>>    <map:match pattern="uri">
>>      <map:generator type ="/*????????*/"/>
>>     <map:transform src="tranform.xsl"/>
>>      <map:serialize type="xml"/>
>>    </map:match>
>
>
> You can use the normal resource generator, and a 'module:' source URI 
> to fetch the content from a flow attribute:
>
> cocoon.processPipelineTo(
>         'uri',
>         stream,
>         {stream:stream});
>
> <map:generator src="module:flow-attr:stream" />
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Aplly transformation to a xml post data

Posted by Jason Johnston <co...@lojjic.net>.
Sébastien Geindre wrote:
> hello all,
> 
> I handle a upload request send by cocoon forms with flowscript :
>    var uploadWidget = form.lookupWidget("upload");
>    var stream = uploadWidget.getValue().getInputStream();
>  
> I'd like to transform the upload stream (which is XML) via a pipeline :
>   cocoon.processPipelineTo(
>        'uri',
>        stream,
>        ??);
> 
> what kind of generator i must use ?
> 
>    <map:match pattern="uri">
>      <map:generator type ="/*????????*/"/>
>     <map:transform src="tranform.xsl"/>
>      <map:serialize type="xml"/>
>    </map:match>


You can use the normal resource generator, and a 'module:' source URI to 
fetch the content from a flow attribute:

cocoon.processPipelineTo(
         'uri',
         stream,
         {stream:stream});

<map:generator src="module:flow-attr:stream" />

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org