blob: d516c9afc3b0ecbb106a6be0b919400afc1d4812 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" "../../dtd/document-v10.dtd">
<document>
<header>
<title>Advanced Control Flow</title>
<authors>
<person name="Ovidiu Predescu" email="ovidiu@apache.org"/>
<person name="Christopher Oliver" email="coliver@apache.org"/>
</authors>
</header>
<body>
<s1 title="Sitemap">
<p>The Cocoon <link href="../concepts/sitemap.html">Sitemap</link> provides two elements to specify interactions with your Flowscripts: <link href="#flow">flow</link>, and <link href="#call">call</link>.</p>
<anchor id="flow"/> <s2 title="flow">
<p>The <code>flow</code> element defines a Flowscript interpreter for a sitemap. The <code>language</code> attribute specifies the target programming language. Currently the only supported language is <code>"javascript"</code>. Its embedded <code>script</code> elements allow you to specify the files that make up the flow for this sitemap. Each <code>script</code> element specifies the URI of a script that will be compiled and executed when this Sitemap is created. The <code>src</code> attribute specifies the URI of the script.</p>
<source><![CDATA[
<map:flow language="Language">
<map:script src="URI"/>
</map:flow>
]]></source>
<p>Example:</p>
<source><![CDATA[
<map:flow language="javascript">
<map:script src="myApplication.js"/>
</map:flow>
]]></source>
</s2>
<p/>
<anchor id="call"/><s2 title="call">
<p>The <code>call</code> element allows you to call a top-level function in your Flowscript or to invoke an existing continuation.</p>
<s3 title="function"><anchor id="callFunction"/>
<p>If the <code>function</code> attribute is present, then the Sitemap will invoke a top-level function defined in your Flowscript. The <code>function</code> attribute specifies the name of the function. Zero or more nested <code>parameter</code> elements may be provided to pass arguments to the function.</p>
<source><![CDATA[
<map:call function="FunctionName">
<map:parameter name="Name" value="Value"/>*
</map:call>
]]></source>
<p>Example:</p>
<source><![CDATA[
<map:flow language="javascript">
<map:script src="myApplication.js"/>
</map:flow>
<map:pipelines>
<map:pipeline>
<map:match pattern="index.html">
<map:call function="showIndexPage"/>
</map:match>
</map:pipeline>
</map:pipelines>
]]></source>
<p>Then in <code>myApplication.js</code> you would define a JavaScript function called <code>showIndexPage()</code> such as:</p>
<source><![CDATA[
function showIndexPage() {
var param = cocoon.request.get("paramName");
sendPage("private/index.html", {param: param});
}
]]></source>
<p/>
</s3>
<s3 title="continuation"><anchor id="callContinuation"/>
<p>If the <code>continuation</code> attribute is present, then the Sitemap will invoke an existing continuation of your Flowscript. The <code>continuation</code> attribute specifies the unique id of the continuation.</p>
<source><![CDATA[
<map:call continuation="Id"/>
]]></source>
<p>Example:</p>
<source><![CDATA[
<map:match pattern="*.form">
<map:call continuation="{1}"/>
</map:match>
]]></source>
</s3>
</s2>
</s1>
</body>
</document>