Hi, I wrote the workaround for getting context/document/wiki access in python. i will be posting as a snippet and reference in scripting howto. {{python}} # This python snippet loads the script engine bindings which are unavailable in jython # because of http://bugs.jython.org/issue1426 # The only bindings which are loaded are: xcontext, doc, xwiki, request and response import com.xpn.xwiki.web.Utils as Utils import org.xwiki.context.Execution as Execution import com.xpn.xwiki.api.Context as Context import com.xpn.xwiki.api.XWiki as XWiki import com.xpn.xwiki.api.Document as Document xcontext = Context(Utils.getComponent(Execution).getContext().getProperty("xwikicontext")) doc = Document(xcontext.getDoc(), xcontext.getContext()) xwiki = XWiki(xcontext.getXWiki(), xcontext.getContext()) request = xcontext.getRequest() response = xcontext.getResponse() #insert your python code here {{/python}} Good Luck, Caleb James DeLisle Thomas Mortagne wrote:
On Thu, Dec 10, 2009 at 20:51, Josh Eastburn <[email protected]> wrote:
Thomas,
{{python}} try: from com.xpn.xwiki.web import Utils from org.xwiki.context import Execution except ImportError: print 'import error'
try: context = Utils.getComponent(Execution.class).getContext().getProperty("xwikicontext") except: print 'method call failed' {{/python}}
outputs: method call failed
I might just have to wait for a Jython fix.
The problem is the "Execution.class" it seems, i don't know how to get the java class object in Jython but i guess there is a way.
Thanks,
Josh
On Thu, Dec 10, 2009 at 2:26 AM, Thomas Mortagne <[email protected]>wrote:
On Thu, Dec 10, 2009 at 11:11, Thomas Mortagne <[email protected]> wrote:
As a workaround you can get the current XWiki ExecutionContext component, here is how to do it in java (until I find how to write it in Python):
XWikiContext context = (XWikiContext)
com.xpn.xwiki.web.Utils.getComponent(Execution.class).getContext().getProperty("xwikicontext");
XWikiContext context = (XWikiContext)
com.xpn.xwiki.web.Utils.getComponent(org.xwiki.context.Execution.class).getContext().getProperty("xwikicontext");
to be more precise
On Thu, Dec 10, 2009 at 10:51, Thomas Mortagne <[email protected]> wrote:
On Thu, Dec 10, 2009 at 10:15, Thomas Mortagne <[email protected]> wrote:
On Wed, Dec 9, 2009 at 22:08, Josh Eastburn < [email protected] <jkeastburn%[email protected]>> wrote: > Thomas, > > So far, no luck. > > I tried a simple script like: > > {{python}} > try: > print xcontext.action > except Exception: > print 'exception' > {{/python}} > > this outputs: > > exception > > Side note: > > {{python}} > try: > print xcontext.action > except Exception as exc: > print exc > {{/python}} > > Results in a failure to execute the macro. Indeed it seems there is a bug in Jython JSR 223 implementation. I'm looking at it and will report the issue to jython if i can validate that it comes from jython. I has already been reported, see http://bugs.jython.org/issue1426, hope it will be fixed soon...
> -Josh > > On Wed, Dec 9, 2009 at 4:17 AM, Thomas Mortagne < [email protected]> > wrote: >> Hi, >> >> On Wed, Dec 9, 2009 at 02:50, Josh Eastburn < [email protected] <jkeastburn%[email protected]>< jkeastburn%[email protected] <jkeastburn%[email protected]>>> > wrote: >>> The documentation seems to indicate that bindings normally available in >>> Velocity like $context should be available in other scripting languages, > but >>> accessing 'context' in Python (e.g. if context.action == 'inline':) > always >>> gives me problems. Any help? >> "context" is deprecated and contains JSR223 ScriptContext (it's a >> reserved keyword). You need to use "xcontext". >> >>> Thanks, >>> >>> Josh >>> _______________________________________________ >>> users mailing list >>> [email protected] >>> http://lists.xwiki.org/mailman/listinfo/users >>> >> >> >> -- >> Thomas Mortagne >> _______________________________________________ >> users mailing list >> [email protected] >> http://lists.xwiki.org/mailman/listinfo/users > _______________________________________________ > users mailing list > [email protected] > http://lists.xwiki.org/mailman/listinfo/users >
-- Thomas Mortagne
-- Thomas Mortagne
-- Thomas Mortagne
-- Thomas Mortagne _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users