Index: src/main/java/com/xpn/xwiki/api/XWiki.java =================================================================== --- src/main/java/com/xpn/xwiki/api/XWiki.java (revision 4385) +++ src/main/java/com/xpn/xwiki/api/XWiki.java (working copy) @@ -2403,6 +2403,22 @@ * @return An object instanciating this class * @throws XWikiException */ + public Object parseGroovyFromPage(String fullname, String jarWikiPage) throws XWikiException + { + XWikiDocument doc = xwiki.getDocument(fullname, getXWikiContext()); + if (xwiki.getRightService().hasProgrammingRights(doc, getXWikiContext())) + return xwiki.parseGroovyFromString(doc.getContent(), jarWikiPage, getXWikiContext()); + return "groovy_missingrights"; + } + + /** + * Priviledged API to retrieve an object instanciated from groovy code in a String Groovy + * scripts compilation is cached + * + * @param fullname // script containing a Groovy class definition (public class MyClass { ... }) + * @return An object instanciating this class + * @throws XWikiException + */ public Object parseGroovyFromPage(String fullname) throws XWikiException { XWikiDocument doc = xwiki.getDocument(fullname, getXWikiContext()); Index: src/main/java/com/xpn/xwiki/render/groovy/XWikiGroovyRenderer.java =================================================================== --- src/main/java/com/xpn/xwiki/render/groovy/XWikiGroovyRenderer.java (revision 4385) +++ src/main/java/com/xpn/xwiki/render/groovy/XWikiGroovyRenderer.java (working copy) @@ -316,6 +316,7 @@ public Object parseGroovyFromString(String script, XWikiContext context) throws XWikiException { prepareCache(context); + ClassLoader parentClassLoader = (ClassLoader) context.get("parentclassloader"); try { CachedGroovyClass cgc; Class gc; @@ -325,7 +326,7 @@ } catch (XWikiCacheNeedsRefreshException e) { classCache.cancelUpdate(script); - GroovyClassLoader gcl = new GroovyClassLoader(); + GroovyClassLoader gcl = (parentClassLoader==null) ? new GroovyClassLoader() : new GroovyClassLoader(parentClassLoader); gc = gcl.parseClass(script); cgc = new CachedGroovyClass(gc); classCache.putInCache(script, cgc); Index: src/main/java/com/xpn/xwiki/render/groovy/XWikiPageClassLoader.java =================================================================== --- src/main/java/com/xpn/xwiki/render/groovy/XWikiPageClassLoader.java (revision 0) +++ src/main/java/com/xpn/xwiki/render/groovy/XWikiPageClassLoader.java (revision 0) @@ -0,0 +1,76 @@ +package com.xpn.xwiki.render.groovy; + +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.doc.XWikiDocument; +import com.xpn.xwiki.doc.XWikiAttachment; + +import java.net.URLClassLoader; +import java.net.URL; +import java.net.URLStreamHandlerFactory; +import java.util.List; +import java.util.ArrayList; + +/** + * Copyright 2006,XpertNet SARL,and individual contributors as indicated + * by the contributors.txt. + *
+ * This is free software;you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation;either version2.1of + * the License,or(at your option)any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY;without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software;if not,write to the Free + * Software Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA + * 02110-1301 USA,or see the FSF site:http://www.fsf.org. + * + * @author ldubost + */ + +public class XWikiPageClassLoader extends URLClassLoader { + + public XWikiPageClassLoader(URL[] urls, ClassLoader parent) { + super(urls, parent); + } + + public XWikiPageClassLoader(URL[] urls) { + super(urls); + } + + public XWikiPageClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) { + super(urls, parent, factory); + } + + public XWikiPageClassLoader(String jarWikiPage, XWikiContext context) throws XWikiException { + this(jarWikiPage, Thread.currentThread().getContextClassLoader(), context); + } + + public XWikiPageClassLoader(String jarWikiPage, ClassLoader parent, XWikiContext context) throws XWikiException { + super(new URL[0], parent); + XWikiDocument doc = context.getWiki().getDocument(jarWikiPage, context); + List urlList = new ArrayList(); + if (!doc.isNew()) { + List attachList = doc.getAttachmentList(); + for (int i=0;i