Extensions Wiki » Extensions » Access To Bindings In Python

Access To Bindings In Python

Last modified by Vincent Massol on 2013/03/11 09:39
script_errorFixes access to script bindings in python macro for XE < 2.4
TypeSnippet
Developed by

Caleb James DeLisle

LicenseGNU Lesser General Public License 2.1
Compatibility

XWiki Enterprise < 2.4

Table of contents

Description

Since XWiki Enterprise 2.4 the bug is fixed and this is no longer needed.

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: python script
Created by Caleb James DeLisle on 2010/01/03 01:56

Download XWiki