apache > cocoon

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

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 sendPage or processPipelineTo) and want that pipeline to start from the XML data you have in the flowscript.

The solution lies in using the module or xmodule source in combination with the flow-attr 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.

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

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:


This is a very simple interface with just one method, toSAX.

Now lets look at a concrete example. In the flowscript you could have:

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

Note that the string must really be a Java string, not a Javascript string.

And the corresponding sitemap could contain:

<map:match pattern="mypipe">
  <map:generate src="module:flow-attr:myXml"/>