org.apache.wiki.event
Class PageEventFilter

java.lang.Object
  extended by org.apache.wiki.api.filters.BasicPageFilter
      extended by org.apache.wiki.event.PageEventFilter
All Implemented Interfaces:
PageFilter

public class PageEventFilter
extends BasicPageFilter

Fires WikiPageEvents for page events.

Adding a PageEventFilter to the FilterManager will automatically attach an event delegate with the WikiEventManager to provide for firing and listener management. All that remains is then adding the listener to the filter via the WikiEventManager. This is quite simple:

    PageEventFilter filter = new PageEventFilter();
    engine.getFilterManager().addPageFilter(filter,5000);
    // attach listener to filter
    WikiEventManager.addWikiEventListener(filter,listener);
 

This class provides convenience methods for adding and removing WikiEventListeners.

See Also:
WikiEventManager

Field Summary
 
Fields inherited from class org.apache.wiki.api.filters.BasicPageFilter
m_engine
 
Constructor Summary
PageEventFilter()
           
 
Method Summary
 void addWikiEventListener(WikiEventListener listener)
          Registers a WikiEventListener with this instance.
protected  void fireEvent(int type, WikiContext context)
          Fires a WikiPageEvent of the provided type and page name to all registered listeners.
 void initialize(Properties properties)
          Called whenever a new PageFilter is instantiated and reset.
 void postSave(WikiContext wikiContext, String content)
          This method is called after the page has been successfully saved.
 String postTranslate(WikiContext wikiContext, String htmlContent)
          This method is called after a page has been fed through the TranslatorReader, so anything you are seeing here is translated content.
 String preSave(WikiContext wikiContext, String content)
          This method is called before the page has been saved to the PageProvider.
 String preTranslate(WikiContext wikiContext, String content)
          This method is called whenever a page has been loaded from the provider, but not yet been sent through the TranslatorReader.
 void removeWikiEventListener(WikiEventListener listener)
          Un-registers a WikiEventListener with this instance.
 
Methods inherited from class org.apache.wiki.api.filters.BasicPageFilter
destroy, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PageEventFilter

public PageEventFilter()
Method Detail

initialize

public void initialize(Properties properties)
                throws FilterException
Called whenever a new PageFilter is instantiated and reset.

Throws:
FilterException

preTranslate

public String preTranslate(WikiContext wikiContext,
                           String content)
                    throws FilterException
This method is called whenever a page has been loaded from the provider, but not yet been sent through the TranslatorReader. Note that you cannot do HTML translation here, because TranslatorReader is likely to escape it.

Specified by:
preTranslate in interface PageFilter
Overrides:
preTranslate in class BasicPageFilter
Parameters:
wikiContext - The current wikicontext.
content - WikiMarkup.
Returns:
The modified wikimarkup content.
Throws:
FilterException - If something goes wrong. Throwing this causes the entire page processing to be abandoned.

postTranslate

public String postTranslate(WikiContext wikiContext,
                            String htmlContent)
                     throws FilterException
This method is called after a page has been fed through the TranslatorReader, so anything you are seeing here is translated content. If you want to do any of your own WikiMarkup2HTML translation, do it here.

Specified by:
postTranslate in interface PageFilter
Overrides:
postTranslate in class BasicPageFilter
Parameters:
wikiContext - The WikiContext.
htmlContent - The translated HTML
Returns:
The modified HTML
Throws:
FilterException - If something goes wrong. Throwing this causes the entire page processing to be abandoned.

preSave

public String preSave(WikiContext wikiContext,
                      String content)
               throws FilterException
This method is called before the page has been saved to the PageProvider.

Specified by:
preSave in interface PageFilter
Overrides:
preSave in class BasicPageFilter
Parameters:
wikiContext - The WikiContext
content - The wikimarkup that the user just wanted to save.
Returns:
The modified wikimarkup
Throws:
FilterException - If something goes wrong. Throwing this causes the entire page processing to be abandoned.

postSave

public void postSave(WikiContext wikiContext,
                     String content)
              throws FilterException
This method is called after the page has been successfully saved. If the saving fails for any reason, then this method will not be called.

Since the result is discarded from this method, this is only useful for things like counters, etc.

Specified by:
postSave in interface PageFilter
Overrides:
postSave in class BasicPageFilter
Parameters:
wikiContext - The WikiContext
content - The content which was just stored.
Throws:
FilterException - If something goes wrong. As the page is already saved, This is just logged.

addWikiEventListener

public final void addWikiEventListener(WikiEventListener listener)
Registers a WikiEventListener with this instance. This is a convenience method.

Parameters:
listener - the event listener

removeWikiEventListener

public final void removeWikiEventListener(WikiEventListener listener)
Un-registers a WikiEventListener with this instance. This is a convenience method.

Parameters:
listener - the event listener

fireEvent

protected final void fireEvent(int type,
                               WikiContext context)
Fires a WikiPageEvent of the provided type and page name to all registered listeners. Only PAGE_LOCK and PAGE_UNLOCK event types will fire an event; other event types are ignored.

Parameters:
type - the WikiPageEvent type to be fired.
context - the WikiContext of the event.
See Also:
WikiPageEvent


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.