Script Module
Version 8.2 by Thomas Mortagne on 2014/07/28 14:58
Scripting APIs, on top of JSR-223 |
Type | JAR |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Enterprise, XWiki Enterprise Manager |
Compatibility | XWiki > 2.3 |
Table of contents
Description
XWiki's scripting features are built on top of JSR-223.
The Script Module offers the following:
- Defines ScriptEvaluatedEvent and ScriptEvaluatingEvent events (see Observation Module) for being called before a script macro executes or just after it's been executed. The ScriptEvaluatedEvent event even allow to cancel the execution of the script macro.
- Provides a ScriptService component role allowing to expose APIs to script macros (see below)
Script Services
To expose an API to a script macro you simply need to implement the org.xwiki.script.service.ScriptService component role (see Component Module to know more about components).
For example:
@Component
@Named("my")
@Singleton
public class MyScriptService implements ScriptService
{
// Declare all java methods you wish to expose here. For example:
public void doSomething(String whatever)
{
...
}
}
@Named("my")
@Singleton
public class MyScriptService implements ScriptService
{
// Declare all java methods you wish to expose here. For example:
public void doSomething(String whatever)
{
...
}
}
Then to use this in a Velocity script macro for example you'll write:
{{velocity}}
$services.my.doSomething("something here")
{{/velocity}}
$services.my.doSomething("something here")
{{/velocity}}