You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by da...@cocoon.zones.apache.org on 2006/03/05 19:00:43 UTC

[DAISY] Created: How do I call a pipeline from flowscript and let the generator start from my DOM tree, input streams, ... ?

A new document has been created.

http://cocoon.zones.apache.org/daisy/documentation/861.html

Document ID: 861
Branch: main
Language: default
Name: How do I call a pipeline from flowscript and let the generator start from my DOM tree, input streams, ... ?
Document Type: FAQ
Created: 3/5/06 6:00:23 PM
Creator (owner): Bruno Dumon
State: publish

Parts
=====

Content
-------
Mime type: text/xml
Size: 1852 bytes
Content:
<html>
<body>

<p>Suppose in a flowscript you have XML in some form or another: a DOM tree, a
Java InputStream, a string, or some other type of object (e.g. an XMLBeans, a
JDOM, ...). Now you want to call a pipeline (either via <tt>sendPage</tt> or
<tt>processPipelineTo</tt>) and want that pipeline to start from the XML data
you have in the flowscript.</p>

<p>The solution lies in using the <tt>module</tt> or <tt>xmodule</tt> source in
combination with the <tt>flow-attr</tt> input module. The module and xmodule
sources are sources which get their input from an input module, and the
flow-attr input module is an input module which can retrieve things from the
viewData object you pass to the sendPage or processPipelineTo functions.</p>

<p>Use the module source when you have your XML data in unparsed form: an
InputStream, a Java string or a Java byte array.</p>

<p>Use the xmodule source when you have your data already in some parsed form.
The xmodule source can natively handle DOM Document or Node objects (and can
even use XPath to get a part of them). For other types of objects, you have to
create a wrapper object which implements the following interface:</p>

<pre>org.apache.excalibur.xml.sax.XMLizable
</pre>

<p>This is a very simple interface with just one method, <tt>toSAX</tt>.</p>

<p>Now lets look at a concrete example. In the flowscript you could have:</p>

<pre>var myXml = new java.lang.String("&lt;message&gt;Hello World!&lt;/message&gt;");
var viewData = { "myXml" : myXml };
cocoon.sendPage("mypipe", viewData);
</pre>

<p>Note that the string must really be a Java string, not a Javascript string.
</p>

<p>And the corresponding sitemap could contain:</p>

<pre>&lt;map:match pattern="mypipe"&gt;
  &lt;map:generate src="module:flow-attr:myXml"/&gt;
  &lt;map:serialize/&gt;
&lt;/map:match&gt;
</pre>

</body>
</html>

Fields
======
Tags: flowscript

Collections
===========
The document belongs to the following collections: documentation