Interface PageFilter
-
- All Known Subinterfaces:
ReferenceManager
,SearchManager
- All Known Implementing Classes:
BasePageFilter
,BasicPageFilter
,CreoleFilter
,DefaultReferenceManager
,DefaultSearchManager
,PageEventFilter
,PingWeblogsComFilter
,ProfanityFilter
,SpamFilter
public interface PageFilter
Provides a definition for a page filter. A page filter is a class that can be used to transform the WikiPage content being saved or being loaded at any given time.
Note that the Context#getPage() method always returns the context in which text is rendered, i.e. the original request. Thus the content may actually be different content than what what the Context#getPage() implies! This happens often if you are for example including multiple pages on the same page.
PageFilters must be thread-safe! There is only one instance of each PageFilter per each Engine invocation. If you need to store data persistently, use VariableManager, or WikiContext.
Design notes
As of 2.5.30, initialize() gains access to the Engine.
As of 2.11.0.M7, almost all methods from BasicPageFilter end up here as default methods.
In order to preserve backwards compatibility with filters not using the public API, these default methods checks if a given filter is using the old, non public API and, if that's the case attempt to execute the old, non public api corresponding method. If the filter uses the public API, then the default callback is used. None of the default callbacks do anything, so it is a good idea for you to implement only methods that you need.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
destroy(Engine engine)
Called for every filter, e.g. on wiki engine shutdown.void
initialize(Engine engine, java.util.Properties properties)
Is called whenever the a new PageFilter is instantiated and reset.default void
postSave(Context context, java.lang.String content)
This method is called after the page has been successfully saved.default java.lang.String
postTranslate(Context context, java.lang.String htmlContent)
This method is called after a page has been fed through the translation process, so anything you are seeing here is translated content.default java.lang.String
preSave(Context context, java.lang.String content)
This method is called before the page has been saved to the PageProvider.default java.lang.String
preTranslate(Context context, java.lang.String content)
This method is called whenever a page has been loaded from the provider, but not yet been sent through the markup-translation process.
-
-
-
Method Detail
-
initialize
void initialize(Engine engine, java.util.Properties properties) throws FilterException
Is called whenever the a new PageFilter is instantiated and reset.- Parameters:
engine
- The Engine which owns this PageFilterproperties
- The properties ripped from filters.xml.- Throws:
FilterException
- If the filter could not be initialized. If this is thrown, the filter is not added to the internal queues.
-
preTranslate
default java.lang.String preTranslate(Context context, java.lang.String content) throws FilterException
This method is called whenever a page has been loaded from the provider, but not yet been sent through the markup-translation process. Note that you cannot do HTML translation here, because it will be escaped.- Parameters:
context
- The current context.content
- WikiMarkup.- Returns:
- The modified wikimarkup content. Default implementation returns the markup as received.
- Throws:
FilterException
- If something goes wrong. Throwing this causes the entire page processing to be abandoned.
-
postTranslate
default java.lang.String postTranslate(Context context, java.lang.String htmlContent) throws FilterException
This method is called after a page has been fed through the translation process, so anything you are seeing here is translated content. If you want to do any of your own WikiMarkup2HTML translation, do it here.- Parameters:
context
- The WikiContext.htmlContent
- The translated HTML.- Returns:
- The modified HTML. Default implementation returns the translated html as received.
- Throws:
FilterException
- If something goes wrong. Throwing this causes the entire page processing to be abandoned.
-
preSave
default java.lang.String preSave(Context context, java.lang.String content) throws FilterException
This method is called before the page has been saved to the PageProvider.- Parameters:
context
- The WikiContextcontent
- The wikimarkup that the user just wanted to save.- Returns:
- The modified wikimarkup. Default implementation returns the markup as received.
- Throws:
FilterException
- If something goes wrong. Throwing this causes the entire page processing to be abandoned.
-
postSave
default void postSave(Context context, java.lang.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.
- Parameters:
context
- The WikiContextcontent
- The content which was just stored.- Throws:
FilterException
- If something goes wrong. As the page is already saved, This is just logged.
-
-