Access to Bindings (context, doc, xwiki etc.) in Python Snippet

Access to Bindings (context, doc, xwiki etc.) in Python Snippet

This snippet is a workaround for http://bugs.jython.org/issue1426 Which is discussed in the mailing list here: http://xwiki.markmail.org/message/nuctq6fmjhbgogig

The problem is that the objects which are normally available in scripting:

  • doc - The current document
  • xcontext - The current Context
  • xwiki - The XWiki object
  • request - The current Request
  • response - The current Response
Are not available in Python.

{{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}}
Tags:
Created by Caleb James DeLisle on 2010/01/03 01:56
Last modified by Caleb James DeLisle on 2010/01/03 02:12

This wiki is licensed under a Creative Commons license
2.2.1.27354