Project

Contents

Issue #00005560

Added new event utility WGDocumentEventListener
Feature/Improvement

We already have WGContentEventListener. If you implement this interface and register your class via WGDatabase.addContentEventListener you will be notified if a content has been changed.

This however is restricted to WGContent-s.

If you need to be informed if some other type of document is changed (area, contenttype, language, structentry, ...) you can't use this class.

We now added a new interface WGDocumentEventListener. Implementations of this class must be registered or unregistered via the new methods

WGDatabase.addDocumentEventListener(obj)
WGDatabase.removeDocumentEventListener(obj)

Registration is typically done in a connect script.

The listener must implement a single method:

void handleEvent(WGDocumentEvent event)

It will be called when any WGDocument ist saved, deleted or moved (only for WGStructEntry-s).

The WGDocumentEvent object has the following methods:

int getType()
int getDocType()
WGDocumentKey getDocumentKey()

getType() returns one of the following

WGDocumentEvent.TYPE_SAVED
WGDocumentEvent.TYPE_DELETED    
WGDocumentEvent.TYPE_MOVED

getDocType() can be used to analyse what kind of WGDocument is operated on.

Sample implementation:

private class ChangeListener implements WGDocumentEventListener{

    @Override
    public void handleEvent(WGDocumentEvent event) throws WGAPIException {
        if(event.getType()==WGDocumentEvent.TYPE_DELETED){
            log.info("deleted document with key " + event.getDocumentKey())
            if(event.getDocType()==WGDocument.TYPE_AREA)
                log.info("oha - an area has been deleted :-(")
        }
    }

}