[groovy-user] Using closure when creating xml with StreamingMarkupBuilder

14 views
Skip to first unread message

jwklomp

unread,
Dec 11, 2011, 2:59:32 PM12/11/11
to us...@groovy.codehaus.org
Hello,

Is it possible to use closures when creating xml? I'm want to create an xml
out of a groovy object that represents a site menu. I'm doing this with
StreamingMarkupBuilder and am tying to get it working with a closure in it,
but so far without success.

The I'm creating the XML like this:

public menuToXml(Menu menu, def countrySpecificConfiguration) {
def builder = new StreamingMarkupBuilder()
builder.encoding = 'UTF-8'
def outputFile = builder.bind {
mkp.xmlDeclaration()
namespaces << ['']
siteMenu {
menu.menuItems.each menuItemToXml
}
}

}

The closure I'm using is:

def menuItemToXml = { menuItem ->
item {
logicalName(menuItem.name)
controller(menuItem.controller)
action(menuItem.action)
enabled(menuItem.enabled.toString())
pageID(menuItem.pageID)
mustBeLoggedIn(menuItem.mustBeLoggedIn.toString())
authorizedUserRoles {
menuItem.authorizedUserRoles.each { user -> userRole(user) }
}
childItems { menuItem.childItems.each { menuItemToXml } }
}
}

It keeps giving the following error:

groovy.lang.MissingMethodException: No signature of method:
com.ingim.flexiblecontent.service.DynamicMenuService.item() is applicable
for argument types:
(com.ingim.flexiblecontent.service.DynamicMenuService$_closure1_closure6)
values:
[com.ingim.flexiblecontent.service.DynamicMenuService$_closure1_closure6@aee1f98]
Possible solutions: use([Ljava.lang.Object;), is(java.lang.Object),
grep(java.lang.Object), with(groovy.lang.Closure), wait(), every()
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)
at
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:78)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
at
com.ingim.flexiblecontent.service.DynamicMenuService$_closure1.doCall(DynamicMenuService.groovy:85)
.....


-----
Kind Regards,

Jan-Willem Klomp
--
View this message in context: http://groovy.329449.n5.nabble.com/Using-closure-when-creating-xml-with-StreamingMarkupBuilder-tp5066442p5066442.html
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Reply all
Reply to author
Forward
0 new messages