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:flow>
...
<map:match pattern="**/startflow*">
<map:call function="flowfunction"/>
</map:match>
<map:match pattern="flowxml">
<map:generate src="something.xml"/>
<map:serialize type="xml"/>
</map:match>

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(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
resolver = cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
source = resolver.resolveURI(uri);
var is = new Packages.org.xml.sax.InputSource(source.getInputStream());
is.setSystemId(source.getURI());
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:
node.getAttribute("fullname")

Return from Flow


Flow passes control back to an XMAP using sendPage().
cocoon.sendPage("flowReturnPipeline");
}

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:
if(passed){
cocoon.sendPage("flowSuccess?name=" + name);
}else{
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"/>
</map:match>


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