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.
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}}Parameters definition
| Name | Optional | Allowed values | Default value | Description | Since version |
|---|---|---|---|---|---|
| language | yes | the identifier of the JSR 223 engine | Indicate which engine to use to execute the provided script | ||
| output | yes | true/false | true | Indicate the output result has to be inserted back in the document | 1.8.1, 1.9M1 |
| wiki | yes | true/false | true | indicate 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 |
| jars | yes | comma-separated list of JARs that will be added to the script execution class loader | none | see below | 2.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:| Name | Class | Description |
|---|---|---|
| xwiki | com.xpn.xwiki.api.XWiki | Utility APIs |
| xcontext | com.xpn.xwiki.api.Context | Contains contextual informations |
| request | com.xpn.xwiki.web.XWikiRequest | The servlet request. Generaly used to get URL parameters. |
| response | com.xpn.xwiki.web.XWikiResponse | The servlet response |
| doc | com.xpn.xwiki.api.Document | The current document |
| util | com.xpn.xwiki.api.Util | Utility APIs |
| msg | com.xpn.xwiki.web.XWikiMessageTool | l10n tool |
| syntaxFactory | org.xwiki.rendering.syntax.SyntaxFactory | generate proper Syntax object from syntax identifier |
Example
{{script language=groovy}}
def list = ["one", "two"]
list.each { item ->
println "* ${item}"
}
{{/script}}Result
- one
- two