use of com.xpn.xwiki.render.groovy.XWikiPageClassLoader in project xwiki-platform by xwiki.
the class XWiki method parseGroovyFromString.
/**
* Privileged API to retrieve an object instantiated from groovy code in a String, using a classloader including all
* JAR files located in the passed page as attachments. Note that Groovy scripts compilation is cached
*
* @param script the Groovy class definition string (public class MyClass { ... })
* @return An object instantiating this class
* @throws XWikiException
*/
public Object parseGroovyFromString(String script, String jarWikiPage, XWikiContext xcontext) throws XWikiException {
XWikiPageClassLoader pcl = new XWikiPageClassLoader(jarWikiPage, xcontext);
Object prevParentClassLoader = xcontext.get("parentclassloader");
try {
xcontext.put("parentclassloader", pcl);
return parseGroovyFromString(script, xcontext);
} finally {
if (prevParentClassLoader == null) {
xcontext.remove("parentclassloader");
} else {
xcontext.put("parentclassloader", prevParentClassLoader);
}
}
}
Aggregations