Arun Rao wrote:
SMX-1.0.1 looks great..
was working on using Groovy transformers for XML
Need to use Groovy since I need to call api's/services
during transforms and XSLT's might not be optimal..
would like to embed something like this inside a Component:
<component id="groovyTransformer" service="foo:groovyTransformer"
class="org.servicemix.components.groovy.GroovyComponent"
destinationService="foo:transformedSender">
<property name="scriptText"><value><![CDATA[
org.dom4j.Node node = org.dom4j.DocumentHelper
.parseText($inMessage.bodyText).selectSingleNode("/timestamp");
:
do_something_w_node();
:
fails w/ ScriptException
Any thoughts/ideas would be appreciated..
BTW you don't need to use $ in front of variables in Groovy.
Incidentally Groovy has support for its own DOM model which is
integrated nicely with GPath. So you can do things like this...
groovy> def doc = new
groovy.util.XmlParser().parseText("<foo><bar>hello</bar></foo>")
groovy> def bar = doc.bar
groovy> println bar
groovy> go
[bar[attributes={}; value=[hello]]]
So you could rewrite your script as
def root = groovy.util.XmlParser().parseText(inMessage.bodyText)
(root will then be the root element, you can navigate inside using
properties etc).
--
James
-------
http://radio.weblogs.com/0112098/