Solprovider Lenya Kongregate Registration for Free Flash Games and Chat with solprovider

Passing XML between XMAPs and Flow

Start Flow

The XMAP calling Flow uses:
<map:flow language="javascript">
<map:script src="code.js"/>
<map:match pattern="**/startflow*">
<map:call function="flowfunction"/>
<map:match pattern="flowxml">
<map:generate src="something.xml"/>
<map:serialize type="xml"/>

Retrieve XML

Flow cannot see any XML from the XMAP, but it can retrieve the results of an XMAP Pipeline.

You need this function:
// loadDocument() reads in an XML file and returns a DOM Document.
function loadDocument(uri) {
var parser = null;
var source = null;
var resolver = null;
try {
parser = cocoon.getComponent(;
resolver = cocoon.getComponent(;
source = resolver.resolveURI(uri);
var is = new;
return parser.parseDocument(is);
} finally {
if (source != null) resolver.release(source);
if (parser != null) cocoon.releaseComponent(parser);
if (resolver != null) cocoon.releaseComponent(resolver);

Retrieve the XML:
function flowfunction() {
var dom = loadDocument("cocoon:/flowxml");

Get the Root element:
var root = dom.getDocumentElement();

Get other elements:
var nodePeople = root.getElementsByTagName("person");
for(var i = 0; i < nodePeople.getLength(); i++){
node = nodePeople.item(i);

Get information:

Return from Flow

Flow passes control back to an XMAP using sendPage().

The pipeline must exist in the calling XMAP.

The pipeline name can use the querystring.
cocoon.sendPage("flowReturn?name=" + name);

This is useful for communication with the XMAP. Do not use this method for information that can be hardcoded:
cocoon.sendPage("flowSuccess?name=" + name);
cocoon.sendPage("flowFailure?name=" + name);

Using Return Value in XMAP

The next Pipeline must be complete, starting with a Generator or Aggregator. I know of no method of passing XML results from Flow back to the XMAP. The only control is which pipeline is called, and using the querystring with the pipeline name to set values.

We used this code to force the login for new registrations:
cocoon.sendPage("flowReturn?name=" + name);
<map:match pattern="login-success-pipeline">
<map:act type="authenticator"/>
<map:redirect-to uri="/{page-envelope:publication-id}/live/index_{page-envelope:document-language}.html?lenya.usecase=session"/>

WORK: Add example of using the returned value for controlling execution in the XMAP.
WORK: Discuss the "values" format if it is useful: cocoon.sendPage("contact-success", {"name":name});

One solution is to repeat the Pipeline called by Flow (using a Resource for the common elements), then continue with an XSLT processing based on the return value to change the XML.

<< i18n Validation PopupsEmail >>

Contact Solprovider
Paul Ercolino