Search in sources :

Example 1 with FilterEventParameters

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

the class InstanceInputFilterStream method writeSpace.

private void writeSpace(EntityReferenceTreeNode node, Object filter, InstanceFilter proxyFilter) throws FilterException {
    SpaceReference spaceReference = (SpaceReference) node.getReference();
    FilterEventParameters parameters = new FilterEventParameters();
    // Get begin/end space parameters
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.setWikiSpaceParameters(spaceReference.getName(), parameters);
    }
    // Begin space
    proxyFilter.beginWikiSpace(spaceReference.getName(), parameters);
    // Extend begin space
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.beginWikiSpace(spaceReference.getName(), parameters);
    }
    // Write documents
    for (DocumentReference documentReference : this.instanceModel.getDocumentReferences(spaceReference)) {
        if (isDocumentEnabled(documentReference)) {
            writeDocument(documentReference, filter, proxyFilter);
        } else {
            if (this.properties.isVerbose()) {
                this.logger.info(LOG_DOCUMENT_SKIPPED, "Skipped document [{}]", documentReference);
            }
        }
    }
    // Write nested spaces
    for (EntityReferenceTreeNode child : node.getChildren()) {
        writeSpace(child, filter, proxyFilter);
    }
    // Extend end space
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.endWikiSpace(spaceReference.getName(), parameters);
    }
    // End space
    proxyFilter.endWikiSpace(spaceReference.getName(), parameters);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReferenceTreeNode(org.xwiki.model.reference.EntityReferenceTreeNode) InstanceInputEventGenerator(org.xwiki.filter.instance.input.InstanceInputEventGenerator) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 2 with FilterEventParameters

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

the class InstanceInputFilterStream method read.

@Override
protected void read(Object filter, InstanceFilter proxyFilter) throws FilterException {
    FilterEventParameters parameters = new FilterEventParameters();
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.setWikiFarmParameters(parameters);
    }
    proxyFilter.beginWikiFarm(parameters);
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.setFilter(filter);
        generator.beginWikiFarm(parameters);
    }
    for (WikiReference wikiReference : this.instanceModel.getWikiReferences()) {
        if (isWikiEnabled(wikiReference)) {
            writeWiki(wikiReference, filter, proxyFilter);
        }
    }
    for (InstanceInputEventGenerator generator : this.eventGenerators) {
        generator.endWikiFarm(parameters);
    }
    proxyFilter.endWikiFarm(parameters);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) WikiReference(org.xwiki.model.reference.WikiReference) InstanceInputEventGenerator(org.xwiki.filter.instance.input.InstanceInputEventGenerator)

Example 3 with FilterEventParameters

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

the class DocumentLocaleReader method resetDocument.

private void resetDocument() {
    this.currentSpaceReference = null;
    this.currentLegacySpace = null;
    this.currentDocumentReference = null;
    this.currentLegacyDocument = null;
    this.currentDocumentLocale = null;
    this.currentDocumentRevision = null;
    this.currentDocumentParameters = new FilterEventParameters();
    // Defaults
    this.currentDocumentParameters.put(WikiDocumentFilter.PARAMETER_LOCALE, Locale.ROOT);
    this.currentDocumentLocaleParameters = new FilterEventParameters();
    this.currentDocumentRevisionParameters = new FilterEventParameters();
    this.sentBeginWikiDocument = false;
    this.sentBeginWikiDocumentLocale = false;
    this.sentBeginWikiDocumentRevision = false;
    this.localeFromLegacy = true;
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters)

Example 4 with FilterEventParameters

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

the class XWikiDocumentFilterUtils method exportEntity.

/**
 * @param entity the entity to read
 * @param target the target where to write the result
 * @param xarProperties the configuration of the output filter
 * @param documentProperties the configuration of the input filter
 * @throws ComponentLookupException failed to find an event generator for passed entity
 * @throws FilterException when failing to generate export the passed entity
 * @throws IOException when failing to close the stream
 */
public void exportEntity(Object entity, OutputTarget target, XAROutputProperties xarProperties, DocumentInstanceInputProperties documentProperties) throws ComponentLookupException, FilterException, IOException {
    // Input
    documentProperties.setVerbose(false);
    // Output
    xarProperties.setForceDocument(true);
    if (target != null) {
        xarProperties.setTarget(target);
    }
    xarProperties.setVerbose(false);
    BeanOutputFilterStream<XAROutputProperties> xarFilter = ((BeanOutputFilterStreamFactory<XAROutputProperties>) this.xarOutputFilterStreamFactory).createOutputFilterStream(xarProperties);
    XARFilter filter = (XARFilter) xarFilter.getFilter();
    BeanEntityEventGenerator<Object, DocumentInstanceInputProperties> generator = this.componentManager.getInstance(new DefaultParameterizedType(null, EntityEventGenerator.class, getClass(entity)));
    // Spaces and document events
    FilterEventParameters documentParameters = null;
    DocumentReference documentReference = null;
    if (entity instanceof XWikiDocument) {
        documentReference = ((XWikiDocument) entity).getDocumentReference();
        for (SpaceReference spaceReference : documentReference.getSpaceReferences()) {
            filter.beginWikiSpace(spaceReference.getName(), FilterEventParameters.EMPTY);
        }
        documentParameters = new FilterEventParameters();
        documentParameters.put(WikiDocumentFilter.PARAMETER_LOCALE, ((XWikiDocument) entity).getDefaultLocale());
        filter.beginWikiDocument(documentReference.getName(), documentParameters);
    }
    // Document Locale events
    generator.write(entity, xarFilter, documentProperties);
    // Document and spaces events
    if (documentParameters != null) {
        filter.endWikiDocument(documentReference.getName(), documentParameters);
        documentReference = ((XWikiDocument) entity).getDocumentReference();
        for (EntityReference reference = documentReference.getParent(); reference instanceof SpaceReference; reference = reference.getParent()) {
            filter.beginWikiSpace(reference.getName(), FilterEventParameters.EMPTY);
        }
    }
    xarFilter.close();
}
Also used : BeanOutputFilterStreamFactory(org.xwiki.filter.output.BeanOutputFilterStreamFactory) SpaceReference(org.xwiki.model.reference.SpaceReference) XAROutputProperties(org.xwiki.filter.xar.output.XAROutputProperties) DocumentInstanceInputProperties(org.xwiki.filter.instance.input.DocumentInstanceInputProperties) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) FilterEventParameters(org.xwiki.filter.FilterEventParameters) BeanEntityEventGenerator(org.xwiki.filter.instance.input.BeanEntityEventGenerator) EntityEventGenerator(org.xwiki.filter.instance.input.EntityEventGenerator) EntityReference(org.xwiki.model.reference.EntityReference) BaseObject(com.xpn.xwiki.objects.BaseObject) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) XARFilter(org.xwiki.filter.xar.internal.XARFilter) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 5 with FilterEventParameters

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

the class BaseObjectEventGenerator method write.

@Override
public void write(BaseObject xobject, Object filter, BaseObjectFilter objectFilter, DocumentInstanceInputProperties properties) throws FilterException {
    XWikiContext xcontext = this.xcontextProvider.get();
    // > WikiObject
    FilterEventParameters objectParameters = new FilterEventParameters();
    objectParameters.put(WikiObjectFilter.PARAMETER_NAME, xobject.getName());
    objectParameters.put(WikiObjectFilter.PARAMETER_CLASS_REFERENCE, xobject.getClassName());
    objectParameters.put(WikiObjectFilter.PARAMETER_GUID, xobject.getGuid());
    objectParameters.put(WikiObjectFilter.PARAMETER_NUMBER, xobject.getNumber());
    objectFilter.beginWikiObject(xobject.getReference() != null ? xobject.getReference().getName() : null, objectParameters);
    // Object class
    BaseClass xclass = xobject.getXClass(xcontext);
    ((BaseClassEventGenerator) this.classEventGenerator).write(xclass, filter, objectFilter, properties);
    // Properties
    // Iterate over values/properties sorted by field name so that the values are
    // exported to XML in a consistent order.
    Iterator<BaseProperty<?>> it = xobject.getSortedIterator();
    while (it.hasNext()) {
        BaseProperty<?> xproperty = it.next();
        String pname = xproperty.getName();
        if (pname != null && !pname.trim().equals("")) {
            ((BasePropertyEventGenerator) this.propertyEventGenerator).write(xproperty, filter, (Map<String, Object>) properties);
        }
    }
    // < WikiObject
    objectFilter.endWikiObject(xobject.getReference().getName(), objectParameters);
}
Also used : FilterEventParameters(org.xwiki.filter.FilterEventParameters) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

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