Search in sources :

Example 1 with PageFilter

use of org.apache.wiki.api.filters.PageFilter in project jspwiki by apache.

the class DefaultFilterManager method doPostSaveFiltering.

/**
 *  Does the page filtering after the page has been saved.
 *
 *  @param context The WikiContext
 *  @param pageData WikiMarkup data to be passed through the postSave chain.
 *  @throws FilterException If any of the filters throws a FilterException
 *
 *  @see PageFilter#postSave(WikiContext, String)
 */
public void doPostSaveFiltering(WikiContext context, String pageData) throws FilterException {
    fireEvent(WikiPageEvent.POST_SAVE_BEGIN, context);
    for (PageFilter f : m_pageFilters) {
        // log.info("POSTSAVE: "+f.toString() );
        f.postSave(context, pageData);
    }
    fireEvent(WikiPageEvent.POST_SAVE_END, context);
}
Also used : PageFilter(org.apache.wiki.api.filters.PageFilter)

Example 2 with PageFilter

use of org.apache.wiki.api.filters.PageFilter in project jspwiki by apache.

the class DefaultFilterManager method initPageFilter.

private void initPageFilter(String className, Properties props) {
    try {
        PageFilterInfo info = m_filterClassMap.get(className);
        if (info != null && !checkCompatibility(info)) {
            String msg = "Filter '" + info.getName() + "' not compatible with this version of JSPWiki";
            log.warn(msg);
            return;
        }
        // FIXME: Currently fixed.
        int priority = 0;
        Class<?> cl = ClassUtil.findClass("org.apache.wiki.filters", className);
        PageFilter filter = (PageFilter) cl.newInstance();
        filter.initialize(m_engine, props);
        addPageFilter(filter, priority);
        log.info("Added page filter " + cl.getName() + " with priority " + priority);
    } catch (ClassNotFoundException e) {
        log.error("Unable to find the filter class: " + className);
    } catch (InstantiationException e) {
        log.error("Cannot create filter class: " + className);
    } catch (IllegalAccessException e) {
        log.error("You are not allowed to access class: " + className);
    } catch (ClassCastException e) {
        log.error("Suggested class is not a PageFilter: " + className);
    } catch (FilterException e) {
        log.error("Filter " + className + " failed to initialize itself.", e);
    }
}
Also used : PageFilter(org.apache.wiki.api.filters.PageFilter) FilterException(org.apache.wiki.api.exceptions.FilterException)

Example 3 with PageFilter

use of org.apache.wiki.api.filters.PageFilter in project jspwiki by apache.

the class DefaultFilterManagerTest method testInitFilters.

@Test
public void testInitFilters() throws Exception {
    FilterManager m = new DefaultFilterManager(engine, props);
    List l = m.getFilterList();
    Assert.assertEquals("Wrong number of filters", 2, l.size());
    Iterator i = l.iterator();
    PageFilter f1 = (PageFilter) i.next();
    Assert.assertTrue("Not a Profanityfilter", f1 instanceof ProfanityFilter);
    PageFilter f2 = (PageFilter) i.next();
    Assert.assertTrue("Not a Testfilter", f2 instanceof TestFilter);
}
Also used : Iterator(java.util.Iterator) List(java.util.List) PageFilter(org.apache.wiki.api.filters.PageFilter) FilterManager(org.apache.wiki.api.engine.FilterManager) Test(org.junit.Test)

Example 4 with PageFilter

use of org.apache.wiki.api.filters.PageFilter in project jspwiki by apache.

the class DefaultFilterManager method doPreTranslateFiltering.

/**
 *  Does the filtering before a translation.
 *
 *  @param context The WikiContext
 *  @param pageData WikiMarkup data to be passed through the preTranslate chain.
 *  @throws FilterException If any of the filters throws a FilterException
 *  @return The modified WikiMarkup
 *
 *  @see PageFilter#preTranslate(WikiContext, String)
 */
public String doPreTranslateFiltering(WikiContext context, String pageData) throws FilterException {
    fireEvent(WikiPageEvent.PRE_TRANSLATE_BEGIN, context);
    for (PageFilter f : m_pageFilters) {
        pageData = f.preTranslate(context, pageData);
    }
    fireEvent(WikiPageEvent.PRE_TRANSLATE_END, context);
    return pageData;
}
Also used : PageFilter(org.apache.wiki.api.filters.PageFilter)

Example 5 with PageFilter

use of org.apache.wiki.api.filters.PageFilter in project jspwiki by apache.

the class DefaultFilterManager method doPreSaveFiltering.

/**
 *  Does the filtering before a save to the page repository.
 *
 *  @param context The WikiContext
 *  @param pageData WikiMarkup data to be passed through the preSave chain.
 *  @throws FilterException If any of the filters throws a FilterException
 *  @return The modified WikiMarkup
 *  @see PageFilter#preSave(WikiContext, String)
 */
public String doPreSaveFiltering(WikiContext context, String pageData) throws FilterException {
    fireEvent(WikiPageEvent.PRE_SAVE_BEGIN, context);
    for (PageFilter f : m_pageFilters) {
        pageData = f.preSave(context, pageData);
    }
    fireEvent(WikiPageEvent.PRE_SAVE_END, context);
    return pageData;
}
Also used : PageFilter(org.apache.wiki.api.filters.PageFilter)

Aggregations

PageFilter (org.apache.wiki.api.filters.PageFilter)7 FilterManager (org.apache.wiki.api.engine.FilterManager)2 Iterator (java.util.Iterator)1 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 WikiSession (org.apache.wiki.WikiSession)1 FilterException (org.apache.wiki.api.exceptions.FilterException)1 UserProfile (org.apache.wiki.auth.user.UserProfile)1 SpamFilter (org.apache.wiki.filters.SpamFilter)1 InputValidator (org.apache.wiki.ui.InputValidator)1 Test (org.junit.Test)1