This accessor provides script execution services based on Jython.
The operator specifies a script resource. This resource may either be a plain/text script document or an
XML document with the script specified as the text of the root element.
When using XML it is strongly advisable to enclose your script inside a CDATA section, for example:
<script><![CDATA[ ...your script .. ]]></script>
Please be aware of the known limitations which currently apply to the
extensibility of Python scripts.
Script Context
Each script execution is provided with a NetKernel context object which allows
the script to be a fully featured NetKernel accessor. The context is an instance of the
INKFConvenienceHelper class. The context has three purposes,
to allow introspection of the request which initiated the script, to allow sub-requests
to be initiated, and to specify a response. For more details see the
NKF Reference Guide.
A script must always return a response. Since it cannot be assumed that a scripting language will return
an object that is useable by the underlying script accessor, a script must create and issue its response via the context.
response=context.createResponseFrom(...)
context.issueResponse(response)
The context is part of the NetKernel Foundation API (NKF) - as with any accessor, ultimately a scripts response must be a NetKernel Representation but for
convenience the context will create a response from either an Aspect or a Representation.
Parameters
Parameters can be passed to a script by specifying abritrarily named arguments. These are accessible in the scripting context
using the this:param URI address space convention used in the DPML runtime.
For example if we had
active:python+operator@myscript.py+myargument@data.xml
The myargument parameter can be obtained inside the script using the context and the argument URI "this:param:myargument".
context.source("this:param:myargument")
Example
Here's an example of a javascript script for performing an XSLT, logging the result and returning the result as the response.
import sys
sys.add_package("org.ten60.netkernel.layer1.representation")
# Create and issue XSLT request
sr=context.createSubRequest();
sr.setURI("active:xslt");
sr.addArgument("operand","data1.xml");
sr.addArgument("operator","style1.xsl");
rep=context.issueSubRequest(sr);
# Log result
sr=context.createSubRequest();
sr.setURI("active:log");
sr.addArgument("operand",rep);
context.issueSubRequest(sr);
# Create response
resp=context.createResponseFrom(rep);
resp.setMimeType("text/plain");
resp.setExpired();
# Issue response
context.setResponse(resp);