JavaScriptInterpreter.java
. Notice how it binds Java classes to JavaScript objects.user = new Packages.samples.flow.prefs.logic.User(login, password, firstName, lastName, email);
(see the prefs sample)The JPathTransformer seems like the ideal thing to use in many cases. – TonyCollen
or get these all as one printable page
<map:flow language="JavaScript"> <map:script src="script1.js"/> <map:script src="script2.js"/> <map:script src="script3.js"/> <map:script src="script4.js"/> </map:flow> |
load(fileName)
// loads a scriptcreateSession()
// attaches this flow script instance to sessionremoveSession()
// detaches this flow script instance from sessioncallAction(type, source, parameters)
inputModuleGetAttribute(type, attribute)
outputModuleSetAttribute(type, attribute, value)
sendPage(uri, bizData)
// call presentation layer to present bizDatauri
is a string to a URI which to redirect to. Usually this is within Cocoon.bizData
is an object, usually to send multiple key->value pairs to the page. These are sent using JPath, and can be retrieved using the JPath Logicsheet, Transformer, or Generator. (See above)sendPageAndWait(uri, bizData, timeToLive)
// call presentation layer to present bizData and wait for subsequent request
act(type, src, param)
inputValue(type, name)
outputSet(type, name, value)
outputCommit(type)
outputRollback(type)
print(args)
// prints args to standard outerror(message)
debug(message)
warn(message)
info(message)
logkit.xconf
The info regarding how the flow functions were named (using js*
) in Rhino has been retired. Check the Wiki diffs if you still need this info, but you probably won't. – TonyCollen
You create an object of class PipelineUtil and pass the parameters to this object along with the match pattern of the pipeline. Or you pass the parameters to cocoon.sendPage or cocoon.sendPageAndWait.
In the pipeline you access the parameter using <map:parameter name="flowparameter" value="{flow-attribute:urn}"/>
Here is an example:
---flowscript---
function enricheXML(urnforthexml){ var enrichedXML = java.io.ByteArrayOutputStream(); var pipeutil = cocoon.createObject(Packages.org.apache.cocoon.components.flow.util.PipelineUtil); pipeutil.processToStream("enricheXML", {"urn":urnforthexml}, enrichedXML); return enrichedXML.toString(); } |
---sitemap---
<!-- ==Pattern for the XMLenrichement ====================================== --> <map:match pattern="enricheXML"> <map:generate src="{request-param:uploadfile}" /> <map:transform src="xsl/enrichement.xsl" > <map:parameter name="url" value="{request-param:uploadurl}" /> <map:parameter name="urn" value="{flow-attribute:urn}" /> </map:transform> <map:serialize type="xml" /> </map:match> |
---stylesheet---
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml"/> <xsl:param name="urn" /> <xsl:param name="url" /> <xsl:template match="/"> <enriched> <URL><xsl:value-of select="$url"/></URL> <URN><xsl:value-of select="$urn"/></URN> <xsl:copy-of select="/"/> </enriched> </xsl:template> </xsl:stylesheet> |
Thanks to JanHinzmann