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();
}
Aggregations