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