Mashups in EMML : Writing Mashups in EMML : Transforming Intermediate Results : Adding User-Defined Scripting Code to Mashups : Include Scripts Directly
Include Scripts Directly
You can also simply write Groovy or JavaScript code directly in the body of <script>.
You must enclose your Groovy or JavaScript code in a CDATA section. This ensures that any characters in the Groovy or JavaScript code that are delimiters in XML, such as <, are not misinterpreted. For example:
<script type="text/javascript" inputvariables="$reviewers"
outputvariable="$newPayload">
<![CDATA[
var newPayload = TopReviewers;
if ( reviewers.reviewer.rating > 3 ) {
newPayload.TopReviewers += <name>{i.name}</name>;
}
]]>
</script>
...
<script type="groovy" inputvariables="$input" outputvariable="$output">
<![CDATA[
import groovy.xml.dom.DOMUtil
import groovy.xml.dom.DOMCategory
import groovy.xml.DOMBuilder


def reader = new StringReader(input)
def doc = DOMBuilder.parse(reader)
def root = doc.documentElement

use(DOMCategory) {
def groceries = root.category.findAll{it.'@type' == 'groceries'}[0].item

groceries.each { g ->
g.value = 'Luxury ' + g.text()
}
...
}
output = DOMUtil.serialize(root)
]]>
</script>
Copyright © 2013-2015 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback