How to write a custom wiki event listener

See also:

A custom wiki event listener is another JSPWiki extension point, in this case an specialization of a WikiEventListener that allows custom components be aware of all kind of events fired by JSPWiki. You may also be aware of these by registering a normal WikiEventListener, but custom wiki event listeners take care themselves of registering inside JSPWiki, which itself requires some deep knowledge of JSPWiki internals.

Code#

Custom Wiki Event Listeners are implemented as SPIs.

Coding a custom wiki event listener is pretty straightforward, just needs two things:

  • A CustomWikiEventListener class that implements the org.apache.wiki.api.events.CustomWikiEventListener< T > interface. Implementations of the following methods are expected to be provided:
    • void initialize( Engine engine, Properties props ) throws WikiException: to locate and store, the object firing the events you are interested in, so the listener can be attached to it later on.
    • T client(): which returns the object located by the previous method, on which the CustomWikiEventListener will be registered.
    • void actionPerformed( WikiEvent event ): in which the action related to the event is done.
  • A META-INF/services/org.apache.wiki.api.events.CustomWikiEventListener file which contains the fully qualified class name of the CustomWikiEventListener implementation.

and that's it!

What kinds of events are available?#

There are lots of different types of events. The easiest way to see all them is by inspecting the org.apache.wiki.event.WikiEvent class and all of its subclasses. The actionPerformed method should take care of downcasting to the appropiate class, if needed, to the appropiate subtype(s) handled by the listener.

Also, each and every of these classes contain a handful of constants that act as event identifiers related to each kind of event, available at WikiEvent#getType(), so you may use this to discern the concrete event for a given WikiEventsubtype.

Unit testing#

See JSPWikiPublicAPI#Testing

Package #

Deploy#

As engine lifecycle extensions are coded as SPIs, JSPWiki is automatically aware about the engine lifecycles extensions present, so there is no need of any further configuration.

Category.Documentation