Search in sources :

Example 1 with SnippetPageFilter

use of net.sourceforge.processdash.ui.snippet.SnippetPageFilter in project processdash by dtuma.

the class CmsContentDispatcher method applySnippetFilters.

private void applySnippetFilters(PageContentTO page, String mode) {
    Map<SnippetInstanceTO, SnippetPageFilter> filters = null;
    for (Iterator i = page.getSnippets().iterator(); i.hasNext(); ) {
        SnippetInstanceTO snip = (SnippetInstanceTO) i.next();
        SnippetDefinition def = snip.getDefinition();
        SnippetPageFilter filter = null;
        try {
            if (def != null)
                filter = def.getFilter(mode, null);
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Unable to create page filter for snippet '" + snip.getSnippetID() + "'", e);
        }
        if (filter != null) {
            if (filters == null)
                filters = new LinkedHashMap();
            filters.put(snip, filter);
        }
    }
    if (filters != null) {
        // if any filters were found, run them all against the page.
        for (Map.Entry<SnippetInstanceTO, SnippetPageFilter> e : filters.entrySet()) {
            SnippetInstanceTO snip = e.getKey();
            SnippetPageFilter f = e.getValue();
            try {
                f.filter(page, snip, mode);
            } catch (Exception ex) {
                logger.log(Level.SEVERE, "Snippet page filter '" + snip.getSnippetID() + "' encountered an exception while running.", ex);
            }
        }
        // the filters may have added new snippet instances to the page.
        // resolve those snippets if necessary.
        lookupSnippets(page);
    }
}
Also used : Iterator(java.util.Iterator) SnippetPageFilter(net.sourceforge.processdash.ui.snippet.SnippetPageFilter) SnippetDefinition(net.sourceforge.processdash.ui.snippet.SnippetDefinition) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IOException(java.io.IOException) TinyCGIException(net.sourceforge.processdash.net.http.TinyCGIException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TinyCGIException (net.sourceforge.processdash.net.http.TinyCGIException)1 SnippetDefinition (net.sourceforge.processdash.ui.snippet.SnippetDefinition)1 SnippetPageFilter (net.sourceforge.processdash.ui.snippet.SnippetPageFilter)1