com.ecyrd.jspwiki.filters
Class FilterManager

java.lang.Object
  extended by com.ecyrd.jspwiki.modules.ModuleManager
      extended by com.ecyrd.jspwiki.filters.FilterManager

public final class FilterManager
extends ModuleManager

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:

  
 
  

    
      com.ecyrd.jspwiki.filters.ProfanityFilter
    
  
    
      com.ecyrd.jspwiki.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
static String DEFAULT_XMLFILE
          Default location for the filter XML property file.
static String PROP_FILTERXML
          Property name for setting the filter XML property file.
static int SYSTEM_FILTER_PRIORITY
          JSPWiki system filters are all below this value.
static int USER_FILTER_PRIORITY
          The standard user level filtering.
 
Fields inherited from class com.ecyrd.jspwiki.modules.ModuleManager
m_engine, PLUGIN_RESOURCE_LOCATION
 
Constructor Summary
FilterManager(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 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 com.ecyrd.jspwiki.modules.ModuleManager
checkCompatibility
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_FILTERXML

public static final String PROP_FILTERXML
Property name for setting the filter XML property file. Value is "jspwiki.filterConfig".

See Also:
Constant Field Values

DEFAULT_XMLFILE

public static final String DEFAULT_XMLFILE
Default location for the filter XML property file. Value is "/WEB-INF/filters.xml".

See Also:
Constant Field Values

SYSTEM_FILTER_PRIORITY

public static final int SYSTEM_FILTER_PRIORITY
JSPWiki system filters are all below this value.

See Also:
Constant Field Values

USER_FILTER_PRIORITY

public static final int USER_FILTER_PRIORITY
The standard user level filtering.

See Also:
Constant Field Values
Constructor Detail

FilterManager

public FilterManager(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.

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.

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.

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.

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.

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 getFilterList()
Returns the list of filters currently installed. Note that this is not a copy, but the actual list. So be careful with it.

Returns:
A List of PageFilter objects

destroy

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


fireEvent

public final 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 class ModuleManager
Returns:
A Collection of WikiModuleInfo instances.