Search in sources :

Example 11 with FilterEventParameters

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

the class XWikiDocumentLocaleEventGenerator method writeRevision.

private void writeRevision(XWikiDocument document, Object filter, XWikiDocumentFilter documentFilter, DocumentInstanceInputProperties properties) throws FilterException {
    // > WikiDocumentRevision
    FilterEventParameters revisionParameters = new FilterEventParameters();
    if (document.getRelativeParentReference() != null) {
        revisionParameters.put(WikiDocumentFilter.PARAMETER_PARENT, document.getRelativeParentReference());
    }
    revisionParameters.put(WikiDocumentFilter.PARAMETER_TITLE, document.getTitle());
    if (!document.getCustomClass().isEmpty()) {
        revisionParameters.put(WikiDocumentFilter.PARAMETER_CUSTOMCLASS, document.getCustomClass());
    }
    if (!document.getDefaultTemplate().isEmpty()) {
        revisionParameters.put(WikiDocumentFilter.PARAMETER_DEFAULTTEMPLATE, document.getDefaultTemplate());
    }
    if (!document.getValidationScript().isEmpty()) {
        revisionParameters.put(WikiDocumentFilter.PARAMETER_VALIDATIONSCRIPT, document.getValidationScript());
    }
    revisionParameters.put(WikiDocumentFilter.PARAMETER_SYNTAX, document.getSyntax());
    revisionParameters.put(WikiDocumentFilter.PARAMETER_HIDDEN, document.isHidden());
    revisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_AUTHOR, document.getAuthor());
    revisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_COMMENT, document.getComment());
    revisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_DATE, document.getDate());
    revisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_MINOR, document.isMinorEdit());
    revisionParameters.put(WikiDocumentFilter.PARAMETER_CONTENT_AUTHOR, document.getContentAuthor());
    revisionParameters.put(WikiDocumentFilter.PARAMETER_CONTENT_DATE, document.getContentUpdateDate());
    revisionParameters.put(WikiDocumentFilter.PARAMETER_CONTENT, document.getContent());
    if (properties.isWithWikiDocumentContentHTML()) {
        try {
            XWikiContext xcontext = this.xcontextProvider.get();
            revisionParameters.put(WikiDocumentFilter.PARAMETER_CONTENT_HTML, document.getRenderedContent(xcontext));
        } catch (XWikiException e) {
            this.logger.error("Failed to render content of document [{}] as HTML", document.getDocumentReference(), e);
        }
    }
    documentFilter.beginWikiDocumentRevision(document.getVersion(), revisionParameters);
    if (properties.isWithWikiAttachments()) {
        List<XWikiAttachment> sortedAttachments = new ArrayList<XWikiAttachment>(document.getAttachmentList());
        Collections.sort(sortedAttachments, new Comparator<XWikiAttachment>() {

            @Override
            public int compare(XWikiAttachment attachement1, XWikiAttachment attachement2) {
                if (attachement1 == null || attachement2 == null) {
                    int result = 0;
                    if (attachement1 != null) {
                        result = -1;
                    } else if (attachement2 != null) {
                        result = 1;
                    }
                    return result;
                }
                return attachement1.getFilename().compareTo(attachement2.getFilename());
            }
        });
        for (XWikiAttachment attachment : sortedAttachments) {
            ((XWikiAttachmentEventGenerator) this.attachmentEventGenerator).write(attachment, filter, documentFilter, properties);
        }
    }
    // Document Class
    if (properties.isWithWikiClass()) {
        BaseClass xclass = document.getXClass();
        if (!xclass.getFieldList().isEmpty()) {
            ((BaseClassEventGenerator) this.classEventGenerator).write(xclass, filter, documentFilter, properties);
        }
    }
    // Objects (THEIR ORDER IS MOLDED IN STONE!)
    if (properties.isWithWikiObjects()) {
        for (List<BaseObject> xobjects : document.getXObjects().values()) {
            for (BaseObject xobject : xobjects) {
                if (xobject != null) {
                    ((BaseObjectEventGenerator) this.objectEventGenerator).write(xobject, filter, documentFilter, properties);
                }
            }
        }
    }
    // < WikiDocumentRevision
    documentFilter.endWikiDocumentRevision(document.getVersion(), revisionParameters);
}
Also used : ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) BaseObject(com.xpn.xwiki.objects.BaseObject) FilterEventParameters(org.xwiki.filter.FilterEventParameters) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiException(com.xpn.xwiki.XWikiException)

Example 12 with FilterEventParameters

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

the class InstanceInputFilterStream method writeDocument.

private void writeDocument(DocumentReference documentReference, Object filter, InstanceFilter proxyFilter) throws FilterException {
    FilterEventParameters parameters = new FilterEventParameters();
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.setWikiDocumentParameters(documentReference.getName(), parameters);
    }
    proxyFilter.beginWikiDocument(documentReference.getName(), parameters);
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.beginWikiDocument(documentReference.getName(), parameters);
    }
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.endWikiDocument(documentReference.getName(), parameters);
    }
    proxyFilter.endWikiDocument(documentReference.getName(), parameters);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) InstanceInputEventGenerator(org.xwiki.filter.instance.input.InstanceInputEventGenerator)

Example 13 with FilterEventParameters

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

the class InstanceInputFilterStream method writeWiki.

private void writeWiki(WikiReference wikiReference, Object filter, InstanceFilter proxyFilter) throws FilterException {
    FilterEventParameters parameters = new FilterEventParameters();
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.setWikiParameters(wikiReference.getName(), parameters);
    }
    proxyFilter.beginWiki(wikiReference.getName(), parameters);
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.beginWiki(wikiReference.getName(), parameters);
    }
    // TODO: improve with a new space related API to get space level by space level instead of all of them at the
    // same time
    EntityReferenceTreeNode spaces = this.instanceModel.getSpaceReferences(wikiReference);
    for (EntityReferenceTreeNode node : spaces.getChildren()) {
        if (isSpaceEnabled((SpaceReference) node.getReference())) {
            writeSpace(node, filter, proxyFilter);
        }
    }
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.endWiki(wikiReference.getName(), parameters);
    }
    proxyFilter.endWiki(wikiReference.getName(), parameters);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) EntityReferenceTreeNode(org.xwiki.model.reference.EntityReferenceTreeNode) InstanceInputEventGenerator(org.xwiki.filter.instance.input.InstanceInputEventGenerator)

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