Search in sources :

Example 6 with FilterEventParameters

use of org.xwiki.filter.FilterEventParameters 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)

Example 7 with FilterEventParameters

use of org.xwiki.filter.FilterEventParameters in project xwiki-platform by xwiki.

the class BaseClassEventGenerator method write.

@Override
public void write(BaseClass xclass, Object filter, BaseClassFilter xclassFilter, DocumentInstanceInputProperties properties) throws FilterException {
    // WikiClass
    FilterEventParameters classParameters = new FilterEventParameters();
    classParameters.put(WikiClassFilter.PARAMETER_NAME, xclass.getName());
    classParameters.put(WikiClassFilter.PARAMETER_CUSTOMCLASS, xclass.getCustomClass());
    classParameters.put(WikiClassFilter.PARAMETER_CUSTOMMAPPING, xclass.getCustomMapping());
    classParameters.put(WikiClassFilter.PARAMETER_DEFAULTSPACE, xclass.getDefaultWeb());
    classParameters.put(WikiClassFilter.PARAMETER_NAMEFIELD, xclass.getNameField());
    classParameters.put(WikiClassFilter.PARAMETER_SHEET_DEFAULTEDIT, xclass.getDefaultEditSheet());
    classParameters.put(WikiClassFilter.PARAMETER_SHEET_DEFAULTVIEW, xclass.getDefaultViewSheet());
    classParameters.put(WikiClassFilter.PARAMETER_VALIDATIONSCRIPT, xclass.getValidationScript());
    xclassFilter.beginWikiClass(classParameters);
    // Properties
    // Iterate over values sorted by field name so that the values are
    // exported to XML in a consistent order.
    Iterator<PropertyClass> it = xclass.getSortedIterator();
    while (it.hasNext()) {
        PropertyClass xclassProperty = it.next();
        ((PropertyClassEventGenerator) this.propertyEventGenerator).write(xclassProperty, filter, xclassFilter, properties);
    }
    // /WikiClass
    xclassFilter.endWikiClass(classParameters);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Example 8 with FilterEventParameters

use of org.xwiki.filter.FilterEventParameters in project xwiki-platform by xwiki.

the class PropertyClassEventGenerator method write.

@Override
public void write(PropertyClass xclassProperty, Object filter, PropertyClassFilter propertyFilter, DocumentInstanceInputProperties properties) throws FilterException {
    // > WikiClassProperty
    FilterEventParameters propertyParameters = FilterEventParameters.EMPTY;
    String classType = xclassProperty.getClassType();
    if (xclassProperty.getClass().getSimpleName().equals(classType + "Class")) {
        // Keep exporting the full Java class name for old/default property types to avoid breaking the XAR format
        // (to allow XClasses created with the current version of XWiki to be imported in an older version).
        classType = xclassProperty.getClass().getName();
    }
    propertyFilter.beginWikiClassProperty(xclassProperty.getName(), classType, propertyParameters);
    // * WikiClassPropertyField
    // Iterate over values sorted by field name so that the values are
    // exported to XML in a consistent order.
    Iterator<BaseProperty<?>> it = xclassProperty.getSortedIterator();
    while (it.hasNext()) {
        BaseProperty<?> bprop = it.next();
        propertyFilter.onWikiClassPropertyField(bprop.getName(), bprop.toText(), FilterEventParameters.EMPTY);
    }
    // < WikiClassProperty
    propertyFilter.endWikiClassProperty(xclassProperty.getName(), classType, propertyParameters);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 9 with FilterEventParameters

use of org.xwiki.filter.FilterEventParameters in project xwiki-platform by xwiki.

the class XWikiAttachmentEventGenerator method write.

@Override
public void write(XWikiAttachment attachment, Object filter, XWikiAttachmentFilter attachmentFilter, DocumentInstanceInputProperties properties) throws FilterException {
    XWikiContext xcontext = this.xcontextProvider.get();
    FilterEventParameters attachmentParameters = new FilterEventParameters();
    if (attachment.getAuthor() != null) {
        attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_AUTHOR, attachment.getAuthor());
    }
    attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_COMMENT, attachment.getComment());
    attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_DATE, attachment.getDate());
    attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION, attachment.getVersion());
    if (StringUtils.isNotEmpty(attachment.getMimeType())) {
        attachmentParameters.put(WikiAttachmentFilter.PARAMETER_MIMETYPE, attachment.getMimeType());
    }
    if (properties.isWithJRCSRevisions()) {
        try {
            // We need to make sure content is loaded
            XWikiAttachmentArchive archive;
            archive = attachment.loadArchive(xcontext);
            if (archive != null) {
                attachmentParameters.put(XWikiWikiAttachmentFilter.PARAMETER_JRCSREVISIONS, archive.getArchiveAsString());
            }
        } catch (XWikiException e) {
            this.logger.error("Attachment [{}] has malformed history", attachment.getReference(), e);
        }
    }
    InputStream content;
    Long size;
    if (properties.isWithWikiAttachmentsContent()) {
        try {
            content = attachment.getContentInputStream(xcontext);
            size = Long.valueOf(attachment.getLongSize());
        } catch (XWikiException e) {
            this.logger.error("Failed to get content of attachment [{}]", attachment.getReference(), e);
            content = new ByteArrayInputStream(new byte[0]);
            size = 0L;
        }
    } else {
        content = null;
        size = null;
    }
    // WikiAttachment
    attachmentFilter.onWikiAttachment(attachment.getFilename(), content, size, attachmentParameters);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) XWikiAttachmentArchive(com.xpn.xwiki.doc.XWikiAttachmentArchive) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 10 with FilterEventParameters

use of org.xwiki.filter.FilterEventParameters in project xwiki-platform by xwiki.

the class XWikiDocumentLocaleEventGenerator method write.

@Override
public void write(XWikiDocument document, Object filter, XWikiDocumentFilter documentFilter, DocumentInstanceInputProperties properties) throws FilterException {
    XWikiContext xcontext = this.xcontextProvider.get();
    // > WikiDocumentLocale
    FilterEventParameters localeParameters = new FilterEventParameters();
    if (properties.isWithJRCSRevisions()) {
        try {
            localeParameters.put(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS, document.getDocumentArchive(xcontext).getArchive(xcontext));
        } catch (XWikiException e) {
            this.logger.error("Document [{}] has malformed history", document.getDocumentReference(), e);
        }
    }
    localeParameters.put(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR, document.getCreator());
    localeParameters.put(WikiDocumentFilter.PARAMETER_CREATION_DATE, document.getCreationDate());
    localeParameters.put(WikiDocumentFilter.PARAMETER_LASTREVISION, document.getVersion());
    documentFilter.beginWikiDocumentLocale(document.getLocale(), localeParameters);
    if (properties.isWithRevisions()) {
        try {
            for (Version version : document.getRevisions(xcontext)) {
                XWikiDocument revisionDocument = xcontext.getWiki().getDocument(document, version.toString(), xcontext);
                writeRevision(revisionDocument, filter, documentFilter, properties);
            }
        } catch (XWikiException e) {
            this.logger.error("Failed to get document [{}] history", document.getDocumentReference(), e);
        }
    }
    writeRevision(document, filter, documentFilter, properties);
    // < WikiDocumentLocale
    documentFilter.endWikiDocumentLocale(document.getLocale(), FilterEventParameters.EMPTY);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) FilterEventParameters(org.xwiki.filter.FilterEventParameters) Version(org.suigeneris.jrcs.rcs.Version) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

FilterEventParameters (org.xwiki.filter.FilterEventParameters)13 XWikiContext (com.xpn.xwiki.XWikiContext)4 InstanceInputEventGenerator (org.xwiki.filter.instance.input.InstanceInputEventGenerator)4 XWikiException (com.xpn.xwiki.XWikiException)3 BaseObject (com.xpn.xwiki.objects.BaseObject)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 BaseProperty (com.xpn.xwiki.objects.BaseProperty)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 EntityReferenceTreeNode (org.xwiki.model.reference.EntityReferenceTreeNode)2 SpaceReference (org.xwiki.model.reference.SpaceReference)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 XWikiAttachmentArchive (com.xpn.xwiki.doc.XWikiAttachmentArchive)1 XWikiDocumentFilter (com.xpn.xwiki.internal.filter.XWikiDocumentFilter)1 XWikiDocumentFilterCollection (com.xpn.xwiki.internal.filter.XWikiDocumentFilterCollection)1 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Version (org.suigeneris.jrcs.rcs.Version)1