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
Hide line numbers
1: {pre} 2: <% 3: import org.codehaus.groovy.control.MultipleCompilationErrorsException 4: 5: if(request.xpage == "plain" && xwiki.hasAccessLevel("programming", doc.fullName)) { 6: 7: def scriptText = request.getParameter("script") ?: "'The received script was null.'" 8: 9: def output = new StringWriter() 10: def binding = new Binding([out: new PrintWriter(output), xwiki:xwiki, context:context, request:request, util:util]) 11: 12: def stacktrace = new StringWriter() 13: def errWriter = new PrintWriter(stacktrace) 14: 15: def result = "" 16: try { 17: result = new GroovyShell(binding).evaluate(scriptText) 18: } catch (MultipleCompilationErrorsException e) { 19: stacktrace.append(e.message - 'startup failed, Script1.groovy: ') 20: } catch (Throwable t) { 21: sanitizeStacktrace(t) 22: def cause = t 23: while (cause = cause?.cause) { 24: sanitizeStacktrace(cause) 25: } 26: t.printStackTrace(errWriter) 27: } 28: 29: response.contentType = "application/json" 30: 31: out.println "{ executionResult: \"" + escape(result) + "\", " + "outputText: \"" + escape(output) + "\", " + "stacktraceText: \"" + escape(stacktrace) + "\"}" 32: 33: } 34: 35: else { 36: println "This is a groovy executor" 37: } 38: 39: def escape(object) { 40: object.toString().replaceAll(/\n/, /\\\n/).replaceAll(/"/, /\\"/) 41: } 42: 43: def sanitizeStacktrace(t) { 44: def filtered = [ 45: 'com.google.', 'org.mortbay.', 46: 'java.', 'javax.', 'sun.', 47: 'groovy.', 'org.codehaus.groovy.', 48: 'com.xpn.xwiki.render', 'org.apache.velocity', 49: 'org.xwiki.velocity', 'com.xpn.xwiki', 50: 'org.apache.struts', 'Script1' 51: ] 52: def trace = t.getStackTrace() 53: def newTrace = [] 54: trace.each { stackTraceElement -> 55: if (filtered.every { !stackTraceElement.className.startsWith(it) }) { 56: newTrace << stackTraceElement 57: } 58: } 59: def clean = newTrace.toArray(newTrace as StackTraceElement[]) 60: t.stackTrace = clean 61: } 62: 63: %> 64: {/pre}
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey