Package org.apache.wiki.filters
Class DefaultFilterManager
- java.lang.Object
-
- org.apache.wiki.modules.BaseModuleManager
-
- org.apache.wiki.filters.DefaultFilterManager
-
- All Implemented Interfaces:
FilterManager,ModuleManager
public class DefaultFilterManager extends BaseModuleManager implements FilterManager
Manages the page filters. Page filters are components that can be executed at certain places:- Before the page is translated into HTML.
- After the page has been translated into HTML.
- Before the page is saved.
- After the page has been saved.
The initial page filter configuration is kept in a file called "filters.xml". The format is really very simple:
<pagefilters> <filter> <class>org.apache.wiki.filters.ProfanityFilter</class> <filter> <filter> <class>org.apache.wiki.filters.TestFilter</class> <param> <name>foobar</name> <value>Zippadippadai</value> </param> <param> <name>blatblaa</name> <value>5</value> </param> </filter> </pagefilters>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.BaseModuleManager
m_engine
-
Fields inherited from interface org.apache.wiki.filters.FilterManager
DEFAULT_XMLFILE, PROP_FILTERXML, SYSTEM_FILTER_PRIORITY, USER_FILTER_PRIORITY
-
Fields inherited from interface org.apache.wiki.modules.ModuleManager
PLUGIN_RESOURCE_LOCATION
-
-
Constructor Summary
Constructors Constructor Description DefaultFilterManager(Engine engine, java.util.Properties props)Constructs a new FilterManager object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPageFilter(PageFilter f, int priority)Adds a page filter to the queue.voiddestroy()Notifies PageFilters to clean up their ressources.voiddoPostSaveFiltering(Context context, java.lang.String pageData)Does the page filtering after the page has been saved.java.lang.StringdoPostTranslateFiltering(Context context, java.lang.String htmlData)Does the filtering after HTML translation.java.lang.StringdoPreSaveFiltering(Context context, java.lang.String pageData)Does the filtering before a save to the page repository.java.lang.StringdoPreTranslateFiltering(Context context, java.lang.String pageData)Does the filtering before a translation.voidfireEvent(int type, Context context)Fires a WikiPageEvent of the provided type and WikiContext.java.util.List<PageFilter>getFilterList()Returns the list of filters currently installed.org.apache.wiki.filters.DefaultFilterManager.PageFilterInfogetModuleInfo(java.lang.String moduleName)Returns theWikiModuleInfoinformation about the provided moduleName.protected voidinitialize(java.util.Properties props)Initializes the filters from an XML file.java.util.Collection<WikiModuleInfo>modules()Returns a collection of modules currently managed by this ModuleManager.-
Methods inherited from class org.apache.wiki.modules.BaseModuleManager
checkCompatibility, modules
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.wiki.modules.ModuleManager
checkCompatibility
-
-
-
-
Constructor Detail
-
DefaultFilterManager
public DefaultFilterManager(Engine engine, java.util.Properties props) throws WikiException
Constructs a new FilterManager object.- Parameters:
engine- The Engine which owns the FilterManagerprops- Properties to initialize the FilterManager with- Throws:
WikiException- If something goes wrong.
-
-
Method Detail
-
addPageFilter
public void addPageFilter(PageFilter f, int priority) throws java.lang.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:
addPageFilterin interfaceFilterManager- Parameters:
f- PageFilter to addpriority- The priority in which position to add it in.- Throws:
java.lang.IllegalArgumentException- If the PageFilter is null or invalid.- Since:
- 2.1.44.
-
initialize
protected void initialize(java.util.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 java.lang.String doPreTranslateFiltering(Context context, java.lang.String pageData) throws FilterException
Does the filtering before a translation.- Specified by:
doPreTranslateFilteringin interfaceFilterManager- Parameters:
context- The WikiContextpageData- 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(Context, String)
-
doPostTranslateFiltering
public java.lang.String doPostTranslateFiltering(Context context, java.lang.String htmlData) throws FilterException
Does the filtering after HTML translation.- Specified by:
doPostTranslateFilteringin interfaceFilterManager- Parameters:
context- The WikiContexthtmlData- 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(Context, String)
-
doPreSaveFiltering
public java.lang.String doPreSaveFiltering(Context context, java.lang.String pageData) throws FilterException
Does the filtering before a save to the page repository.- Specified by:
doPreSaveFilteringin interfaceFilterManager- Parameters:
context- The WikiContextpageData- 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(Context, String)
-
doPostSaveFiltering
public void doPostSaveFiltering(Context context, java.lang.String pageData) throws FilterException
Does the page filtering after the page has been saved.- Specified by:
doPostSaveFilteringin interfaceFilterManager- Parameters:
context- The WikiContextpageData- WikiMarkup data to be passed through the postSave chain.- Throws:
FilterException- If any of the filters throws a FilterException- See Also:
PageFilter.postSave(Context, String)
-
getFilterList
public java.util.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:
getFilterListin interfaceFilterManager- Returns:
- A List of PageFilter objects
-
destroy
public void destroy()
Notifies PageFilters to clean up their ressources.- Specified by:
destroyin interfaceFilterManager
-
fireEvent
public void fireEvent(int type, Context 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 java.util.Collection<WikiModuleInfo> 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:
modulesin interfaceModuleManager- Returns:
- A Collection of WikiModuleInfo instances.
-
getModuleInfo
public org.apache.wiki.filters.DefaultFilterManager.PageFilterInfo getModuleInfo(java.lang.String moduleName)
Returns theWikiModuleInfoinformation about the provided moduleName.- Specified by:
getModuleInfoin interfaceModuleManager- Returns:
- The wikiModuleInfo
-
-