App Entry Listener

Last modified by Admin on 2026/11/25 00:24

cogAbstract superclasses to build application entry events.
TypeJAR
CategoryOther
Developed by

Anca Luca

Active Installs0
Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Success

Installable with the Extension Manager

Description

This extension provides APIs that provide abstract superclasses to be used whenever a piece of code needs to use high-level events on pages that are application entries of a specific application: added, deleted, renamed, copied, etc.
Writing this using a raw event listener is a little complex because some events are higher level events while others are lower level events and such a listener would always need to do the same analysis and filtering of the event before handling it. This API will provide abstract superclasses to be used to manage such events easier, without worrying about the filtering or detection.

Note: the types of this application are unstable for now and can change at any time.

Abstract superclasses:

org.xwiki.contrib.appentrylistener.AbstractAppEntryEventOccurredListener

Use when you want to write a listener to react to events on application entries that have already happened: page deleted, page renamed, created (not implemented yet), modified (not implemented yet), copied (not implemented yet).

Functions to implement:

// Constructor: call super constructor with the listener name as param
public <Your listener class here>()
{
  super(LISTENER_NAME);
}

/**
 * @return the class of the application entries for which this listener will listen.
 */
public abstract EntityReference getAppClassReference();

/**
 * Function called when an entry of the application (as filtered by {@link #isAppEntry(XWikiDocument, Event)}) was
 * deleted. All deletes that happen as part of a rename will not be notified on this function, but handled by the
 * {@link #onAppEntryRenamed(XWikiDocument, DocumentReference, DocumentRenamedEvent)} instead.
 * 
 * @param originalDocument the original document, before delete. Use only for read-only purposes.
 * @param event the original document deleted event, in case any context is needed.
 */
public abstract void onAppEntryDeleted(XWikiDocument originalDocument, DocumentDeletedEvent event);

/**
 * Function called when an entry of the application (as filtered by {@link #isAppEntry(XWikiDocument, Event)}) was
 * renamed.
 * 
 * @param renamedDocument the XWikiDocument that was renamed, after rename. This instance is <b>not cloned</b>, so
 *            use it for read-only purposes. Should any changes be needed on it, make a clone.
 * @param oldReference the old reference of the renamed document, before rename.
 * @param event the original document renamed event, in case any context is needed.
 */
public abstract void onAppEntryRenamed(XWikiDocument renamedDocument, DocumentReference oldReference,
    DocumentRenamedEvent event);

Additionally, if you need to control more in detail how a page is qualified as an app entry or not, you can overwrite the evaluation function:

/**
 * Returns true if the passed entry is an entry of the application (to react to), false otherwise. By default, this
 * function checks the objects of the page based on {@link #getAppClassReference()} but can be overridden to add
 * extra conditions (such as excluding the template document, filtering on a space, etc.).
 * 
 * @param document the document to check whether it's an app entry or not.
 * @param event the original event caught by the listener, in case it's needed for getting context information for
 *            filtering the document.
 * @return true if the passed entry is an entry of the application (to react to), false otherwise.
 */
protected boolean isAppEntry(XWikiDocument document, Event event)

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).

You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.

Versions

Dependencies

Dependencies for this extension (org.xwiki.contrib:appentrylistener 1.0-rc-1):

  • org.xwiki.commons:xwiki-commons-observation-api 14.4
  • org.xwiki.platform:xwiki-platform-oldcore 14.4

Get Connected