Search in sources :

Example 1 with BeanEntityEventGenerator

use of org.xwiki.filter.instance.input.BeanEntityEventGenerator 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)

Aggregations

XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 FilterEventParameters (org.xwiki.filter.FilterEventParameters)1 BeanEntityEventGenerator (org.xwiki.filter.instance.input.BeanEntityEventGenerator)1 DocumentInstanceInputProperties (org.xwiki.filter.instance.input.DocumentInstanceInputProperties)1 EntityEventGenerator (org.xwiki.filter.instance.input.EntityEventGenerator)1 BeanOutputFilterStreamFactory (org.xwiki.filter.output.BeanOutputFilterStreamFactory)1 XARFilter (org.xwiki.filter.xar.internal.XARFilter)1 XAROutputProperties (org.xwiki.filter.xar.output.XAROutputProperties)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EntityReference (org.xwiki.model.reference.EntityReference)1 SpaceReference (org.xwiki.model.reference.SpaceReference)1