Script Macro

This is a XWiki macro, bundled with all the XWiki products by default.
Macro developed by the XWiki Development Team.
This macro cannot currently be downloaded separately.

Script Macro

Executes a script implementing the JSR-223 API.

Usage

{{script language="scriptengine"}}
print "some" + " " + "script" + " " + "content"
{{/script}}

By default the "xwiki" and "xcontext" variables are defined and respectively represent a XWiki and Context API objects.

Parameters definition

NameOptionalAllowed valuesDefault valueDescriptionSince version
languageyesthe identifier of the JSR 223 engine Indicate which engine to use to execute the provided script 
outputyestrue/falsetrueIndicate the output result has to be inserted back in the document1.8.1, 1.9M1
wikiyestrue/falsetrueindicate if the result of the script execution has to be parsed by the current wiki parser. If not it's put in a verbatim block.2.0 M1
jarsyescomma-separated list of JARs that will be added to the script execution class loadernonesee below2.0RC1

Specifying extra JARs

If you have programming rights, it's possible to add JARs that will be available to the script's execution by using the jars parameters. The format is a comma-separated list of entries of the following types:

  • a URL of the type http://server/path/to/some.jar
  • a reference to a JAR attachment on the current page: attach:some.jar
  • a reference to a JAR attachment located on another page: attach:wiki:space.page@some.jar
  • a reference to all jars located on a give page: attach:wiki:space.page

Bindings

Some bindings/variable are automatically provided:

NameClassDescription
xwikicom.xpn.xwiki.api.XWikiUtility APIs
xcontextcom.xpn.xwiki.api.ContextContains contextual informations
requestcom.xpn.xwiki.web.XWikiRequestThe servlet request. Generaly used to get URL parameters.
responsecom.xpn.xwiki.web.XWikiResponseThe servlet response
doccom.xpn.xwiki.api.DocumentThe current document
utilcom.xpn.xwiki.api.UtilUtility APIs
msgcom.xpn.xwiki.web.XWikiMessageTooll10n tool
syntaxFactoryorg.xwiki.rendering.syntax.SyntaxFactorygenerate proper Syntax object from syntax identifier

Example

{{script language=groovy}}
def list = ["one", "two"]
list.each { item ->
  println "* ${item}"
}
{{/script}}

Result

  • one
  • two
Tags:
Created by Thomas Mortagne on 2008/12/02 14:37
Last modified by Vincent Massol on 2009/10/02 00:32

This wiki is licensed under a Creative Commons license
2.2.1.27354