Script Module

Version 6.3 by Thomas Mortagne on 2012/02/22 15:09

cogProvides various APIs related to script macros in XWiki
TypeJAR
Category
Developed by

XWiki Development Team

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Enterprise, XWiki Enterprise Manager

Compatibility

XWiki > 2.3

Description

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)
    {
        ...
    }
}

Of course, make sure to register your component in components.txt and to deploy your component JAR in WEB-INF/lib.

Then to use this in a Velocity script macro for example you'll write:

{{velocity}}
$services.my.doSomething("something here")
{{/velocity}}
Tags:
    

Get Connected