use of org.xwiki.filter.FilterEventParameters in project xwiki-platform by xwiki.
the class XWikiDocumentOutputFilterStream method createFilter.
@Override
protected Object createFilter() {
List<XWikiDocumentFilter> filters = new ArrayList<>(this.children.size() + 1);
for (EntityOutputFilterStream<?> child : this.children) {
filters.add((XWikiDocumentFilter) child.getFilter());
}
filters.add(this);
this.filter = new XWikiDocumentFilterCollection(filters) {
@Override
public void beginWikiClass(FilterEventParameters parameters) throws FilterException {
if (!objectFilter.isEnabled()) {
classFilter.enable();
}
super.beginWikiClass(parameters);
}
@Override
public void endWikiClass(FilterEventParameters parameters) throws FilterException {
super.endWikiClass(parameters);
classFilter.disable();
}
@Override
public void beginWikiObject(String name, FilterEventParameters parameters) throws FilterException {
objectFilter.enable();
super.beginWikiObject(name, parameters);
}
@Override
public void endWikiObject(String name, FilterEventParameters parameters) throws FilterException {
super.endWikiObject(name, parameters);
objectFilter.disable();
}
@Override
public void onWikiAttachment(String name, InputStream content, Long size, FilterEventParameters parameters) throws FilterException {
attachmentFilter.enable();
super.onWikiAttachment(name, content, size, parameters);
attachmentFilter.disable();
}
};
if (this.contentListener != null) {
// Inject listener for the document content events
return this.filterManager.createCompositeFilter(this.contentListener, this.filter);
} else {
return this.filter;
}
}
use of org.xwiki.filter.FilterEventParameters in project xwiki-platform by xwiki.
the class BaseClassEventGenerator method write.
@Override
public void write(BaseClass xclass, Object filter, BaseClassFilter xclassFilter, DocumentInstanceInputProperties properties) throws FilterException {
// WikiClass
FilterEventParameters classParameters = new FilterEventParameters();
classParameters.put(WikiClassFilter.PARAMETER_NAME, xclass.getName());
classParameters.put(WikiClassFilter.PARAMETER_CUSTOMCLASS, xclass.getCustomClass());
classParameters.put(WikiClassFilter.PARAMETER_CUSTOMMAPPING, xclass.getCustomMapping());
classParameters.put(WikiClassFilter.PARAMETER_DEFAULTSPACE, xclass.getDefaultWeb());
classParameters.put(WikiClassFilter.PARAMETER_NAMEFIELD, xclass.getNameField());
classParameters.put(WikiClassFilter.PARAMETER_SHEET_DEFAULTEDIT, xclass.getDefaultEditSheet());
classParameters.put(WikiClassFilter.PARAMETER_SHEET_DEFAULTVIEW, xclass.getDefaultViewSheet());
classParameters.put(WikiClassFilter.PARAMETER_VALIDATIONSCRIPT, xclass.getValidationScript());
xclassFilter.beginWikiClass(classParameters);
// Properties
// Iterate over values sorted by field name so that the values are
// exported to XML in a consistent order.
Iterator<PropertyClass> it = xclass.getSortedIterator();
while (it.hasNext()) {
PropertyClass xclassProperty = it.next();
((PropertyClassEventGenerator) this.propertyEventGenerator).write(xclassProperty, filter, xclassFilter, properties);
}
// /WikiClass
xclassFilter.endWikiClass(classParameters);
}
use of org.xwiki.filter.FilterEventParameters in project xwiki-platform by xwiki.
the class PropertyClassEventGenerator method write.
@Override
public void write(PropertyClass xclassProperty, Object filter, PropertyClassFilter propertyFilter, DocumentInstanceInputProperties properties) throws FilterException {
// > WikiClassProperty
FilterEventParameters propertyParameters = FilterEventParameters.EMPTY;
String classType = xclassProperty.getClassType();
if (xclassProperty.getClass().getSimpleName().equals(classType + "Class")) {
// Keep exporting the full Java class name for old/default property types to avoid breaking the XAR format
// (to allow XClasses created with the current version of XWiki to be imported in an older version).
classType = xclassProperty.getClass().getName();
}
propertyFilter.beginWikiClassProperty(xclassProperty.getName(), classType, propertyParameters);
// * WikiClassPropertyField
// Iterate over values sorted by field name so that the values are
// exported to XML in a consistent order.
Iterator<BaseProperty<?>> it = xclassProperty.getSortedIterator();
while (it.hasNext()) {
BaseProperty<?> bprop = it.next();
propertyFilter.onWikiClassPropertyField(bprop.getName(), bprop.toText(), FilterEventParameters.EMPTY);
}
// < WikiClassProperty
propertyFilter.endWikiClassProperty(xclassProperty.getName(), classType, propertyParameters);
}
use of org.xwiki.filter.FilterEventParameters in project xwiki-platform by xwiki.
the class XWikiAttachmentEventGenerator method write.
@Override
public void write(XWikiAttachment attachment, Object filter, XWikiAttachmentFilter attachmentFilter, DocumentInstanceInputProperties properties) throws FilterException {
XWikiContext xcontext = this.xcontextProvider.get();
FilterEventParameters attachmentParameters = new FilterEventParameters();
if (attachment.getAuthor() != null) {
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_AUTHOR, attachment.getAuthor());
}
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_COMMENT, attachment.getComment());
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_DATE, attachment.getDate());
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION, attachment.getVersion());
if (StringUtils.isNotEmpty(attachment.getMimeType())) {
attachmentParameters.put(WikiAttachmentFilter.PARAMETER_MIMETYPE, attachment.getMimeType());
}
if (properties.isWithJRCSRevisions()) {
try {
// We need to make sure content is loaded
XWikiAttachmentArchive archive;
archive = attachment.loadArchive(xcontext);
if (archive != null) {
attachmentParameters.put(XWikiWikiAttachmentFilter.PARAMETER_JRCSREVISIONS, archive.getArchiveAsString());
}
} catch (XWikiException e) {
this.logger.error("Attachment [{}] has malformed history", attachment.getReference(), e);
}
}
InputStream content;
Long size;
if (properties.isWithWikiAttachmentsContent()) {
try {
content = attachment.getContentInputStream(xcontext);
size = Long.valueOf(attachment.getLongSize());
} catch (XWikiException e) {
this.logger.error("Failed to get content of attachment [{}]", attachment.getReference(), e);
content = new ByteArrayInputStream(new byte[0]);
size = 0L;
}
} else {
content = null;
size = null;
}
// WikiAttachment
attachmentFilter.onWikiAttachment(attachment.getFilename(), content, size, attachmentParameters);
}
use of org.xwiki.filter.FilterEventParameters in project xwiki-platform by xwiki.
the class XWikiDocumentLocaleEventGenerator method write.
@Override
public void write(XWikiDocument document, Object filter, XWikiDocumentFilter documentFilter, DocumentInstanceInputProperties properties) throws FilterException {
XWikiContext xcontext = this.xcontextProvider.get();
// > WikiDocumentLocale
FilterEventParameters localeParameters = new FilterEventParameters();
if (properties.isWithJRCSRevisions()) {
try {
localeParameters.put(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS, document.getDocumentArchive(xcontext).getArchive(xcontext));
} catch (XWikiException e) {
this.logger.error("Document [{}] has malformed history", document.getDocumentReference(), e);
}
}
localeParameters.put(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR, document.getCreator());
localeParameters.put(WikiDocumentFilter.PARAMETER_CREATION_DATE, document.getCreationDate());
localeParameters.put(WikiDocumentFilter.PARAMETER_LASTREVISION, document.getVersion());
documentFilter.beginWikiDocumentLocale(document.getLocale(), localeParameters);
if (properties.isWithRevisions()) {
try {
for (Version version : document.getRevisions(xcontext)) {
XWikiDocument revisionDocument = xcontext.getWiki().getDocument(document, version.toString(), xcontext);
writeRevision(revisionDocument, filter, documentFilter, properties);
}
} catch (XWikiException e) {
this.logger.error("Failed to get document [{}] history", document.getDocumentReference(), e);
}
}
writeRevision(document, filter, documentFilter, properties);
// < WikiDocumentLocale
documentFilter.endWikiDocumentLocale(document.getLocale(), FilterEventParameters.EMPTY);
}
Aggregations