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