Search in sources :

Example 1 with XWikiDocumentFilter

use of com.xpn.xwiki.internal.filter.XWikiDocumentFilter in project xwiki-platform by xwiki.

the class XWikiDocumentOutputFilterStream method createFilter.

@Override
protected Object createFilter() {
    List<XWikiDocumentFilter> filters = new ArrayList<>(this.children.size() + 1);
    for (EntityOutputFilterStream<?> child : this.children) {
        filters.add((XWikiDocumentFilter) child.getFilter());
    }
    filters.add(this);
    this.filter = new XWikiDocumentFilterCollection(filters) {

        @Override
        public void beginWikiClass(FilterEventParameters parameters) throws FilterException {
            if (!objectFilter.isEnabled()) {
                classFilter.enable();
            }
            super.beginWikiClass(parameters);
        }

        @Override
        public void endWikiClass(FilterEventParameters parameters) throws FilterException {
            super.endWikiClass(parameters);
            classFilter.disable();
        }

        @Override
        public void beginWikiObject(String name, FilterEventParameters parameters) throws FilterException {
            objectFilter.enable();
            super.beginWikiObject(name, parameters);
        }

        @Override
        public void endWikiObject(String name, FilterEventParameters parameters) throws FilterException {
            super.endWikiObject(name, parameters);
            objectFilter.disable();
        }

        @Override
        public void onWikiAttachment(String name, InputStream content, Long size, FilterEventParameters parameters) throws FilterException {
            attachmentFilter.enable();
            super.onWikiAttachment(name, content, size, parameters);
            attachmentFilter.disable();
        }
    };
    if (this.contentListener != null) {
        // Inject listener for the document content events
        return this.filterManager.createCompositeFilter(this.contentListener, this.filter);
    } else {
        return this.filter;
    }
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) XWikiDocumentFilterCollection(com.xpn.xwiki.internal.filter.XWikiDocumentFilterCollection) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FilterException(org.xwiki.filter.FilterException) XWikiDocumentFilter(com.xpn.xwiki.internal.filter.XWikiDocumentFilter)

Aggregations

XWikiDocumentFilter (com.xpn.xwiki.internal.filter.XWikiDocumentFilter)1 XWikiDocumentFilterCollection (com.xpn.xwiki.internal.filter.XWikiDocumentFilterCollection)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 FilterEventParameters (org.xwiki.filter.FilterEventParameters)1 FilterException (org.xwiki.filter.FilterException)1