How to write a page filter
See also:
- JSPWikiPublicAPI
- WikiFiltersBcc195432.431-43471.431.4ec88.19809.2Bxss.meEsiInclude src=HttpBxss.meRpb.png
- DevelopmentEnvironment
- ContributedFilters
See the starting point for developing custom page filters to create a maven project holding the custom filter.
Code#
- Create a new class and add
- import org.apache.wiki.api.filters.PageFilter;
- implements PageFilter
PageFilter provides five methods:
- void initialize( Engine, Properties ): called whenever a new PageFilter is instantiated and reset.
- String preTranslate( Context, String content ): called after the page has been fetched from the page repository, but before it has been translated from WikiMarkup to HTML.
- String postTranslate( Context context, String htmlContent ): called after the page has been translated into HTML, but before it is shown to the user.
- String preSave( Context context, String content ): called before the page is committed to the repository.
- void postSave( Context context, String content ): called after the page has been committed to the repository successfully.
PageFilter offers empty default methods for the last four of the above, so you can focus on the events you want to process.
Caveats#
- preTranslate(..): contrary to what it may appear, the WikiMarkup is translated to HTML twice during a page save, hence this method is called twice
- First, after the page has been fetched from the page repository, but before it has been translated from WikiMarkup to HTML
- Then life goes on an the Page eventually gets saved
- ..Then postSave(..) triggers the update of the Page's references
- ..Which in turn renders the page (so it can be known where the Page is referencing)
- ..Rendering the Page == translate WikiMarkup
- ..Which implies preTranslate(..) is called before translation, again
- Bottom line: actions on this method should be idempotent
- postSave(..): Note that at this point it is useless to change the page data anymore.
- Filters that hook to this event are typically general notification filters - such as sending email.
BasicPageFilter#
Most of the time, the only thing done on the initialize(..) method is to store a reference to the Engine received. If you want to skip this step, instead of implementing PageFilter, you cand extend from BasicPageFilter, which does exactly this.
Unit testing#
Package #
Deploy#