That document discussed integrating that functionality with the AltioLive client as a custom control, but you can also utilize the same feature to add support for implementing AltioLive Service Functions with scripting languages. We'll take a quick look at how to implement this in Java 6.0 and earlier JVMs by using the Apache Bean Scripting Framework (BSF).
All that is required is a simple Java service function proxy to handle calling a script and returning the results. There are 2 service functions, one for Java 6 and one for BSF, and the source code is included with the Altio script service function JAR file (http://developers.altio.com/developer/downloads/scriptsvcfunc.jar). Each service function takes the same parameters:
- Engine: Name of the script engine to use. e.g. javascript, js, groovy
- Script: Name of the script to execute
- Function: Name of the function in the script to execute
The advantages to using a scripting language for custom Altio Service Functions instead of Java are:
- Quicker development time (no IDE or compiler required)
- Take advantage of particular langauge features to perform tasks. Some languages are better at string handling, XML parsing etc and are better suited for particular tasks than Java.
Setup:
1 - Either:- Run the AltioLive Presentation Server using a Java 6 JDK and use the Java 6 examples.(You should remove 'eics-client.jar' from Altio\WEB-INF\lib before starting otherwise you will have JSP compilation problems)
- Run AltioLive Presentation Server using an older JDK and use the BSF examples
Java6
- There are lots of engines here: https://scripting.dev.java.net/files/documents/4957/37593/jsr223-engines.zip
- For each engine you'll need supporting libraries.
- e.g. Groovy libraries can be found here: http://dist.groovy.codehaus.org/distributions/groovy-binary-1.5.6.zip
- Altio installs BSF by default, but I had to upgrade to 2.4.0 to get this to work.
- To add JavaScript support use Rhino: http://www.mozilla.org/rhino/download.html (copy the js.jar into WEB-INF\lib)
- Other engine can be found here: http://jakarta.apache.org/bsf/index.html
3 - Install the Altio Script Service Function by copying the JAR file (http://developers.altio.com/developer/downloads/scriptsvcfunc.jar) into (Altio\WEB-INF\lib)
4 - Create an Altio\WEB-INF\classes\scripts folder and copy the example scripts (http://developers.altio.com/developer/downloads/scripts.zip) in there.
Running
1 - You can reuse the Java Scripting service function proxy to execute any function in any script in any supported scripting engine, as in the examples below. The screenshots below are for the Java 6 implementation - if you are using the BSF then replace the classname withcom.altio.services.scripting.BSFScriptServiceFunctionExecute JavaScript Service Function
Example JavaScript:
function returnSomeXml() {
var result = "<javascript msg="'hello">"
return result;
}
Results:
<RESULT AL_ID="RESULT">
<javascript msg="hello again from javascript, the time is Tue Jul 15 2008 12:17:02 GMT+0100 (BST)" AL_ID="RESULT-javascript"/>
</RESULT>
Execute Groovy Service Function
Example Groovy:
def returnSomeXml2() {
String result = "<groovy>"
xml = {result+="<groovyitem id='${it}'/>"}
val = (1..10).collect(xml)
result += "</groovy>"
return result
}
Results:
<RESULT AL_ID="RESULT">
<groovy AL_ID="RESULT-groovy">
<groovyitem id="1" AL_ID="gi1"/>
<groovyitem id="2" AL_ID="gi2"/>
<groovyitem id="3" AL_ID="gi3"/>
<groovyitem id="4" AL_ID="gi4"/>
<groovyitem id="5" AL_ID="gi5"/>
<groovyitem id="6" AL_ID="gi6"/>
<groovyitem id="7" AL_ID="gi7"/>
<groovyitem id="8" AL_ID="gi8"/>
<groovyitem id="9" AL_ID="gi9"/>
<groovyitem id="10" AL_ID="gi10"/>
</groovy>
</RESULT>
These are trivial examples, but they demonstrate how you can implement Altio Service Functions in dynamic scripting languages. Their advantages of ease of development and deployment should make it simple to start using them for more complicated tasks. Further enhancements to the proxy could include passing parameters to the named script's service function, which would make it possible to send values all the way from the AltioLive client through to a server side script function.
No comments:
Post a Comment