General Actions:
Log-in
Wiki:
CreativeIT
▼
:
Document Index
»
Space:
XWiki
▼
:
Document Index
»
Page:
GroovyConsoleExecutor
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Welcome to the CreativeIT Wiki!
»
XWiki Space
»
GroovyConsoleExecutor
Wiki source code of
GroovyConsoleExecutor
Last modified by
Holger Dick
on 2009/07/13 15:39
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Show line numbers
{pre} <% import org.codehaus.groovy.control.MultipleCompilationErrorsException if(request.xpage == "plain" && xwiki.hasAccessLevel("programming", doc.fullName)) { def scriptText = request.getParameter("script") ?: "'The received script was null.'" def output = new StringWriter() def binding = new Binding([out: new PrintWriter(output), xwiki:xwiki, context:context, request:request, util:util]) def stacktrace = new StringWriter() def errWriter = new PrintWriter(stacktrace) def result = "" try { result = new GroovyShell(binding).evaluate(scriptText) } catch (MultipleCompilationErrorsException e) { stacktrace.append(e.message - 'startup failed, Script1.groovy: ') } catch (Throwable t) { sanitizeStacktrace(t) def cause = t while (cause = cause?.cause) { sanitizeStacktrace(cause) } t.printStackTrace(errWriter) } response.contentType = "application/json" out.println "{ executionResult: \"" + escape(result) + "\", " + "outputText: \"" + escape(output) + "\", " + "stacktraceText: \"" + escape(stacktrace) + "\"}" } else { println "This is a groovy executor" } def escape(object) { object.toString().replaceAll(/\n/, /\\\n/).replaceAll(/"/, /\\"/) } def sanitizeStacktrace(t) { def filtered = [ 'com.google.', 'org.mortbay.', 'java.', 'javax.', 'sun.', 'groovy.', 'org.codehaus.groovy.', 'com.xpn.xwiki.render', 'org.apache.velocity', 'org.xwiki.velocity', 'com.xpn.xwiki', 'org.apache.struts', 'Script1' ] def trace = t.getStackTrace() def newTrace = [] trace.each { stackTraceElement -> if (filtered.every { !stackTraceElement.className.startsWith(it) }) { newTrace << stackTraceElement } } def clean = newTrace.toArray(newTrace as StackTraceElement[]) t.stackTrace = clean } %> {/pre}
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey