Search in sources :

Example 1 with FilterStreamXMLStreamWriter

use of org.xwiki.filter.xml.internal.output.FilterStreamXMLStreamWriter in project xwiki-platform by xwiki.

the class XAROutputFilterStream method beginWikiDocumentLocale.

@Override
public void beginWikiDocumentLocale(Locale locale, FilterEventParameters parameters) throws FilterException {
    if (this.writer == null) {
        if (this.wikiWriter == null && (this.properties.isForceDocument() || isTargetTextualContent())) {
            checkXMLWriter();
        } else {
            if (this.wikiWriter == null) {
                this.wikiWriter = new XARWikiWriter(this.properties.getPackageName() != null ? this.properties.getPackageName() : "package", this.properties);
            }
            this.writer = new FilterStreamXMLStreamWriter(this.wikiWriter.newEntry(new LocalDocumentReference(this.currentDocumentReference, locale)), this.properties.getEncoding(), this.properties.isFormat(), true);
        }
    }
    this.writer.writeStartDocument(this.properties.getEncoding(), "1.1");
    this.writer.writeStartElement(XarDocumentModel.ELEMENT_DOCUMENT);
    this.writer.writeAttribute(XarDocumentModel.ATTRIBUTE_DOCUMENT_SPECVERSION, XarDocumentModel.VERSION_CURRENT);
    this.writer.writeAttribute(XarDocumentModel.ATTRIBUTE_DOCUMENT_REFERENCE, localSerializer.serialize(this.currentDocumentReference));
    this.writer.writeAttribute(XarDocumentModel.ATTRIBUTE_DOCUMENT_LOCALE, toString(locale));
    // Legacy space and name
    if (this.currentDocumentReference.getParent().getParent() == null) {
        // If single space behave as it used to and put the space name instead of the reference to keep
        // compatibility when importing in older version
        this.writer.writeElement(XarDocumentModel.ELEMENT_SPACE, this.currentDocumentReference.getParent().getName());
    } else {
        // If nested space put the space reference in the field
        this.writer.writeElement(XarDocumentModel.ELEMENT_SPACE, defaultSerializer.serialize(this.currentDocumentReference.getParent()));
    }
    this.writer.writeElement(XarDocumentModel.ELEMENT_NAME, this.currentDocumentReference.getName());
    // Legacy locale
    this.writer.writeElement(XarDocumentModel.ELEMENT_LOCALE, toString(locale));
    this.writer.writeElement(XarDocumentModel.ELEMENT_DEFAULTLOCALE, toString(this.currentDocumentParameters.get(XWikiWikiDocumentFilter.PARAMETER_LOCALE)));
    this.writer.writeElement(XarDocumentModel.ELEMENT_ISTRANSLATION, locale != null && !Locale.ROOT.equals(locale) ? "1" : "0");
    if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_CREATION_AUTHOR)) {
        this.writer.writeElement(XarDocumentModel.ELEMENT_CREATION_AUTHOR, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_CREATION_AUTHOR));
    }
    if (parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_CREATION_DATE)) {
        this.writer.writeElement(XarDocumentModel.ELEMENT_CREATION_DATE, toString((Date) parameters.get(XWikiWikiDocumentFilter.PARAMETER_CREATION_DATE)));
    }
    if (this.properties.isPreserveVersion() && parameters.containsKey(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS)) {
        this.writer.writeElement(XarDocumentModel.ELEMENT_REVISIONS, (String) parameters.get(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS));
    }
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) FilterStreamXMLStreamWriter(org.xwiki.filter.xml.internal.output.FilterStreamXMLStreamWriter) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 FilterStreamXMLStreamWriter (org.xwiki.filter.xml.internal.output.FilterStreamXMLStreamWriter)1 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)1