Search in sources :

Example 1 with FilterException

use of org.apache.wiki.api.exceptions.FilterException in project jspwiki by apache.

the class ApprovalWorkflowTest method testSaveWikiPageWithException.

@Test
public void testSaveWikiPageWithException() throws WikiException {
    // Add a PageFilter that rejects all save attempts
    FilterManager fm = m_engine.getFilterManager();
    fm.addPageFilter(new AbortFilter(), 0);
    // Create a sample test page and try to save it
    String pageName = "SaveWikiPageWorkflow-Test" + System.currentTimeMillis();
    String text = "This is a test!";
    try {
        m_engine.saveTextAsJanne(pageName, text);
    } catch (WikiException e) {
        Assert.assertTrue(e instanceof FilterException);
        Assert.assertEquals("Page save aborted.", e.getMessage());
        return;
    }
    Assert.fail("Page save should have thrown a FilterException, but didn't.");
}
Also used : WikiException(org.apache.wiki.api.exceptions.WikiException) FilterException(org.apache.wiki.api.exceptions.FilterException) FilterManager(org.apache.wiki.api.engine.FilterManager) Test(org.junit.Test)

Example 2 with FilterException

use of org.apache.wiki.api.exceptions.FilterException in project jspwiki by apache.

the class CreoleFilter method preSave.

/**
 *  {@inheritDoc}
 */
public String preSave(WikiContext wikiContext, String content) throws FilterException {
    try {
        String username = wikiContext.getCurrentUser().getName();
        Properties prop = wikiContext.getEngine().getWikiProperties();
        return new CreoleToJSPWikiTranslator().translateSignature(prop, content, username);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return e.getMessage();
    }
}
Also used : CreoleToJSPWikiTranslator(org.apache.wiki.parser.CreoleToJSPWikiTranslator) Properties(java.util.Properties) FilterException(org.apache.wiki.api.exceptions.FilterException)

Example 3 with FilterException

use of org.apache.wiki.api.exceptions.FilterException 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 4 with FilterException

use of org.apache.wiki.api.exceptions.FilterException in project jspwiki by apache.

the class WikiEngine method textToHTML.

/**
 *  Converts raw page data to HTML.
 *
 *  @param pagedata Raw page data to convert to HTML
 *  @param context  The WikiContext in which the page is to be rendered
 *  @return Rendered page text
 */
public String textToHTML(WikiContext context, String pagedata) {
    String result = "";
    boolean runFilters = "true".equals(m_variableManager.getValue(context, PROP_RUNFILTERS, "true"));
    StopWatch sw = new StopWatch();
    sw.start();
    try {
        if (runFilters)
            pagedata = m_filterManager.doPreTranslateFiltering(context, pagedata);
        result = m_renderingManager.getHTML(context, pagedata);
        if (runFilters)
            result = m_filterManager.doPostTranslateFiltering(context, result);
    } catch (FilterException e) {
    // FIXME: Don't yet know what to do
    }
    sw.stop();
    if (log.isDebugEnabled())
        log.debug("Page " + context.getRealPage().getName() + " rendered, took " + sw);
    return result;
}
Also used : FilterException(org.apache.wiki.api.exceptions.FilterException) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 5 with FilterException

use of org.apache.wiki.api.exceptions.FilterException in project jspwiki by apache.

the class WikiEngine method textToHTML.

/**
 *  Helper method for doing the HTML translation.
 *
 *  @param context The WikiContext in which to do the conversion
 *  @param pagedata The data to render
 *  @param localLinkHook Is called whenever a wiki link is found
 *  @param extLinkHook   Is called whenever an external link is found
 *  @param parseAccessRules Parse the access rules if we encounter them
 *  @param justParse Just parses the pagedata, does not actually render.  In this case,
 *                   this methods an empty string.
 *  @return HTML-rendered page text.
 */
private String textToHTML(WikiContext context, String pagedata, StringTransmutator localLinkHook, StringTransmutator extLinkHook, StringTransmutator attLinkHook, boolean parseAccessRules, boolean justParse) {
    String result = "";
    if (pagedata == null) {
        log.error("NULL pagedata to textToHTML()");
        return null;
    }
    boolean runFilters = "true".equals(m_variableManager.getValue(context, PROP_RUNFILTERS, "true"));
    try {
        StopWatch sw = new StopWatch();
        sw.start();
        if (runFilters && m_filterManager != null)
            pagedata = m_filterManager.doPreTranslateFiltering(context, pagedata);
        MarkupParser mp = m_renderingManager.getParser(context, pagedata);
        mp.addLocalLinkHook(localLinkHook);
        mp.addExternalLinkHook(extLinkHook);
        mp.addAttachmentLinkHook(attLinkHook);
        if (!parseAccessRules)
            mp.disableAccessRules();
        WikiDocument doc = mp.parse();
        // 
        if (!justParse) {
            result = m_renderingManager.getHTML(context, doc);
            if (runFilters && m_filterManager != null)
                result = m_filterManager.doPostTranslateFiltering(context, result);
        }
        sw.stop();
        if (log.isDebugEnabled())
            log.debug("Page " + context.getRealPage().getName() + " rendered, took " + sw);
    } catch (IOException e) {
        log.error("Failed to scan page data: ", e);
    } catch (FilterException e) {
        log.error("page filter threw exception: ", e);
    // FIXME: Don't yet know what to do
    }
    return result;
}
Also used : FilterException(org.apache.wiki.api.exceptions.FilterException) IOException(java.io.IOException) WikiDocument(org.apache.wiki.parser.WikiDocument) StopWatch(org.apache.commons.lang.time.StopWatch) MarkupParser(org.apache.wiki.parser.MarkupParser)

Aggregations

FilterException (org.apache.wiki.api.exceptions.FilterException)5 StopWatch (org.apache.commons.lang.time.StopWatch)2 IOException (java.io.IOException)1 Properties (java.util.Properties)1 FilterManager (org.apache.wiki.api.engine.FilterManager)1 WikiException (org.apache.wiki.api.exceptions.WikiException)1 PageFilter (org.apache.wiki.api.filters.PageFilter)1 CreoleToJSPWikiTranslator (org.apache.wiki.parser.CreoleToJSPWikiTranslator)1 MarkupParser (org.apache.wiki.parser.MarkupParser)1 WikiDocument (org.apache.wiki.parser.WikiDocument)1 Test (org.junit.Test)1