[英]Getting result of Groovy script into a GSP
I have a script that takes a bunch of XML info and outputs it in the following format:我有一个脚本,它需要一堆 XML 信息并以下列格式输出:
==================
Package: code: VCOM_NIGHTOWL
==================
==================
Quota Code Balance: code: NO_100G
==================
id: _aiZVYKGuEeqHJ4kr1alp8Q
initialAmount: 107374182400
amount: 107374182400
reservedAmount: 0
startDate: 2020-05-29T15:15:00.000+02:00
expirationDate: 2020-06-29T15:15:00.000+02:00
rolloverPeriodAmount: 1
rolloverPeriodUnits: Month
rolloverExpirationDate: 2020-07-29T15:15:00.000+02:00
rolloverTemplateName: NightOwl_Rollover
==================
Quota Code Balance: code: NightOwl_Rollover
==================
id: _aibxoKGuEeqHJ4kr1alp8Q
initialAmount: 107374182400
amount: 107374104877
reservedAmount: 0
startDate: 2020-05-29T15:15:00.000+02:00
expirationDate: 2020-06-29T15:15:00.000+02:00
==================
Package: code: VCOM_BBC_DATA_ABT
==================
==================
Quota Code Balance: code: DATA-100GB
==================
id: _6DakwKGxEeqHJ4kr1alp8Q
initialAmount: 107374182400
amount: 107374182400
reservedAmount: 125829120
startDate: 2020-05-29T15:40:00.000+02:00
expirationDate: 2020-06-29T15:40:00.000+02:00
rolloverPeriodAmount: 1
rolloverPeriodUnits: Month
rolloverExpirationDate: 2020-07-29T15:40:00.000+02:00
rolloverTemplateName: Rollover
==================
Quota Code Balance: code: Rollover
==================
id: _7m7EMIoeEeqfasqHpqlxMw
initialAmount: 11181322002
amount: 9394601779
reservedAmount: 0
startDate: 2020-04-29T15:40:00.000+02:00
expirationDate: 2020-05-29T15:40:00.000+02:00
I want to render the whole lot in a Grails GSP.我想在 Grails GSP 中渲染全部内容。
I have tried to work out how I can run the script directly within the controller but I can't seem to figure it out.我试图弄清楚如何直接在 controller 中运行脚本,但我似乎无法弄清楚。
This is the script code:这是脚本代码:
import groovy.json.*
import groovy.xml.*
import groovy.util.*
import java.time.*
import java.text.*
import groovy.transform.ToString
def cps_post = new XmlSlurper().parse(new File("F:/SFTP Updates/Groovy/balance.xml"))
def cpsPost = cps_post.Body.GetSubscriberResponse.subscriber
def a = cpsPost.balance.code.size()
println a
def b = cpsPost.balance.quota.credit.size()
println b
def c = cpsPost.balance.quota.code.size()
println c
def d = cpsPost.balance.quota.size()
println c
for (int i = 0; i <= a; i++){
cpsPost.balance[i].code.each { codetag ->
println "=================="
println "Package: ${codetag.name()}: ${codetag.text()}"
println "=================="
cpsPost.balance[i].quota.code.each { quotatag ->
println " =================="
println " Quota Code Balance: ${quotatag.name()}: ${quotatag.text()}"
println " =================="
cpsPost.balance[i].quota.credit.each { credit ->
credit.children().each { tag3 ->
println " ${tag3.name()}: ${tag3.text()}"
}}
}}}
].execute().text
I have also tried to run the script using a "process" cmd and then render the output ie:我还尝试使用“进程”cmd 运行脚本,然后渲染 output 即:
def cpsBilling(){
def process = "groovysh.bat F:/SFTP Updates/Groovy/cpsBilling.groovy".execute()
render "Output: " + process.text
}
This only renders the "Output" string and no process.这只呈现“输出”字符串,没有进程。
Any help would be greatly appreciated as it's driving me bananas.任何帮助将不胜感激,因为它让我很兴奋。
Thanks谢谢
In case it's of use to anyone, I used a scriptlet in the GSP.万一它对任何人都有用,我在 GSP 中使用了一个 scriptlet。 It's probably not the ideal solution but it works for what I need.这可能不是理想的解决方案,但它可以满足我的需要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.