Download

Download the jython.jar from http://www.jython.org and put it into the WEB-INF/lib directory of your webapp. If you want to rebuild your Cocoon you should copy it also to the lib/local directory of your Cocoon sources, otherwise the JAR will be lost after the build.

Sitemap entry.

<map:match pattern="test.py">
  <map:generate src="test.py" type="script">
    <map:parameter name="key" value="Shark Attack"/>
  </map:generate>
  <map:serialize type="xml"/>
</map:match>

Python script.

#get the output String buffer 
output       = bsf.lookupBean( "output" )

#get the Parameters object
parameters   = bsf.lookupBean("parameters")


#get the value of the parameter "key" defined in the sitemap
value = parameters.getParameter("key")

#generate xml
output.append("<msg>" + value +"</msg>")

(tested with 2.1.3)

PythonScriptGenerator (last edited 2009-09-20 23:42:17 by localhost)