org.apache.wiki.filters
Class DefaultFilterManager

java.lang.Object
  extended by org.apache.wiki.modules.ModuleManager
      extended by org.apache.wiki.filters.DefaultFilterManager
All Implemented Interfaces:
FilterManager

public class DefaultFilterManager
extends ModuleManager
implements FilterManager

Manages the page filters. Page filters are components that can be executed at certain places:

Using page filters allows you to modify the page data on-the-fly, and do things like adding your own custom WikiMarkup.

The initial page filter configuration is kept in a file called "filters.xml". The format is really very simple:

  
 
  

    
      org.apache.wiki.filters.ProfanityFilter
    
  
    
      org.apache.wiki.filters.TestFilter

      
        foobar
        Zippadippadai
      

      
        blatblaa
        5
      

    
  
  
The <filter> -sections define the filters. For more information, please see the PageFilterConfiguration page in the JSPWiki distribution.


Field Summary
 
Fields inherited from class org.apache.wiki.modules.ModuleManager
m_engine, PLUGIN_RESOURCE_LOCATION
 
Fields inherited from interface org.apache.wiki.api.engine.FilterManager
DEFAULT_XMLFILE, PROP_FILTERXML, SYSTEM_FILTER_PRIORITY, USER_FILTER_PRIORITY
 
Constructor Summary
DefaultFilterManager(WikiEngine engine, Properties props)
          Constructs a new FilterManager object.
 
Method Summary
 void addPageFilter(PageFilter f, int priority)
          Adds a page filter to the queue.
 void destroy()
          Notifies PageFilters to clean up their ressources.
 void doPostSaveFiltering(WikiContext context, String pageData)
          Does the page filtering after the page has been saved.
 String doPostTranslateFiltering(WikiContext context, String htmlData)
          Does the filtering after HTML translation.
 String doPreSaveFiltering(WikiContext context, String pageData)
          Does the filtering before a save to the page repository.
 String doPreTranslateFiltering(WikiContext context, String pageData)
          Does the filtering before a translation.
 void fireEvent(int type, WikiContext context)
          Fires a WikiPageEvent of the provided type and WikiContext.
 List<PageFilter> getFilterList()
          Returns the list of filters currently installed.
protected  void initialize(Properties props)
          Initializes the filters from an XML file.
 Collection modules()
          Returns a collection of modules currently managed by this ModuleManager.
 
Methods inherited from class org.apache.wiki.modules.ModuleManager
checkCompatibility
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFilterManager

public DefaultFilterManager(WikiEngine engine,
                            Properties props)
                     throws WikiException
Constructs a new FilterManager object.

Parameters:
engine - The WikiEngine which owns the FilterManager
props - Properties to initialize the FilterManager with
Throws:
WikiException - If something goes wrong.
Method Detail

addPageFilter

public void addPageFilter(PageFilter f,
                          int priority)
                   throws IllegalArgumentException
Adds a page filter to the queue. The priority defines in which order the page filters are run, the highest priority filters go in the queue first.

In case two filters have the same priority, their execution order is the insertion order.

Specified by:
addPageFilter in interface FilterManager
Parameters:
f - PageFilter to add
priority - The priority in which position to add it in.
Throws:
IllegalArgumentException - If the PageFilter is null or invalid.
Since:
2.1.44.

initialize

protected void initialize(Properties props)
                   throws WikiException
Initializes the filters from an XML file.

Parameters:
props - The list of properties. Typically jspwiki.properties
Throws:
WikiException - If something goes wrong.

doPreTranslateFiltering

public String doPreTranslateFiltering(WikiContext context,
                                      String pageData)
                               throws FilterException
Does the filtering before a translation.

Specified by:
doPreTranslateFiltering in interface FilterManager
Parameters:
context - The WikiContext
pageData - WikiMarkup data to be passed through the preTranslate chain.
Returns:
The modified WikiMarkup
Throws:
FilterException - If any of the filters throws a FilterException
See Also:
PageFilter.preTranslate(WikiContext, String)

doPostTranslateFiltering

public String doPostTranslateFiltering(WikiContext context,
                                       String htmlData)
                                throws FilterException
Does the filtering after HTML translation.

Specified by:
doPostTranslateFiltering in interface FilterManager
Parameters:
context - The WikiContext
htmlData - HTML data to be passed through the postTranslate
Returns:
The modified HTML
Throws:
FilterException - If any of the filters throws a FilterException
See Also:
PageFilter.postTranslate(WikiContext, String)

doPreSaveFiltering

public String doPreSaveFiltering(WikiContext context,
                                 String pageData)
                          throws FilterException
Does the filtering before a save to the page repository.

Specified by:
doPreSaveFiltering in interface FilterManager
Parameters:
context - The WikiContext
pageData - WikiMarkup data to be passed through the preSave chain.
Returns:
The modified WikiMarkup
Throws:
FilterException - If any of the filters throws a FilterException
See Also:
PageFilter.preSave(WikiContext, String)

doPostSaveFiltering

public void doPostSaveFiltering(WikiContext context,
                                String pageData)
                         throws FilterException
Does the page filtering after the page has been saved.

Specified by:
doPostSaveFiltering in interface FilterManager
Parameters:
context - The WikiContext
pageData - WikiMarkup data to be passed through the postSave chain.
Throws:
FilterException - If any of the filters throws a FilterException
See Also:
PageFilter.postSave(WikiContext, String)

getFilterList

public List<PageFilter> getFilterList()
Returns the list of filters currently installed. Note that this is not a copy, but the actual list. So be careful with it.

Specified by:
getFilterList in interface FilterManager
Returns:
A List of PageFilter objects

destroy

public void destroy()
Notifies PageFilters to clean up their ressources.

Specified by:
destroy in interface FilterManager

fireEvent

public void fireEvent(int type,
                      WikiContext context)
Fires a WikiPageEvent of the provided type and WikiContext. Invalid WikiPageEvent types are ignored.

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

modules

public Collection modules()
Returns a collection of modules currently managed by this ModuleManager. Each entry is an instance of the WikiModuleInfo class. This method should return something which is safe to iterate over, even if the underlying collection changes.

Specified by:
modules in interface FilterManager
Specified by:
modules in class ModuleManager
Returns:
A Collection of WikiModuleInfo instances.


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