use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class XAROutputFilterStream method onWikiAttachment.
@Override
public void onWikiAttachment(String name, InputStream content, Long size, FilterEventParameters parameters) throws FilterException {
checkXMLWriter();
try {
this.writer.writeStartElement(XARAttachmentModel.ELEMENT_ATTACHMENT);
this.writer.writeElement(XARAttachmentModel.ELEMENT_NAME, name);
if (this.properties.isPreserveVersion() && parameters.containsKey(XWikiWikiAttachmentFilter.PARAMETER_JRCSREVISIONS)) {
this.writer.writeElement(XARAttachmentModel.ELEMENT_REVISIONS, (String) parameters.get(XWikiWikiAttachmentFilter.PARAMETER_JRCSREVISIONS));
}
if (parameters.containsKey(XWikiWikiAttachmentFilter.PARAMETER_MIMETYPE)) {
this.writer.writeElement(XARAttachmentModel.ELEMENT_MIMETYPE, (String) parameters.get(XWikiWikiAttachmentFilter.PARAMETER_MIMETYPE));
}
if (parameters.containsKey(XWikiWikiAttachmentFilter.PARAMETER_REVISION_AUTHOR)) {
this.writer.writeElement(XARAttachmentModel.ELEMENT_REVISION_AUTHOR, (String) parameters.get(XWikiWikiAttachmentFilter.PARAMETER_REVISION_AUTHOR));
}
if (parameters.containsKey(XWikiWikiAttachmentFilter.PARAMETER_REVISION_DATE)) {
this.writer.writeElement(XARAttachmentModel.ELEMENT_REVISION_DATE, toString((Date) parameters.get(XWikiWikiAttachmentFilter.PARAMETER_REVISION_DATE)));
}
if (parameters.containsKey(XWikiWikiAttachmentFilter.PARAMETER_REVISION)) {
this.writer.writeElement(XARAttachmentModel.ELEMENT_REVISION, (String) parameters.get(XWikiWikiAttachmentFilter.PARAMETER_REVISION));
}
if (parameters.containsKey(XWikiWikiAttachmentFilter.PARAMETER_REVISION_COMMENT)) {
this.writer.writeElement(XARAttachmentModel.ELEMENT_REVISION_COMMENT, (String) parameters.get(XWikiWikiAttachmentFilter.PARAMETER_REVISION_COMMENT));
}
if (content != null) {
long contentSize = 0;
this.writer.writeStartElement(XARAttachmentModel.ELEMENT_CONTENT);
byte[] buffer = new byte[ATTACHMENT_BUFFER_CHUNK_SIZE];
int readSize;
do {
try {
readSize = content.read(buffer, 0, ATTACHMENT_BUFFER_CHUNK_SIZE);
} catch (IOException e) {
throw new FilterException("Failed to read content stream", e);
}
if (readSize > 0) {
String chunk;
if (readSize == ATTACHMENT_BUFFER_CHUNK_SIZE) {
chunk = Base64.encodeBase64String(buffer);
} else {
chunk = Base64.encodeBase64String(ArrayUtils.subarray(buffer, 0, readSize));
}
this.writer.writeCharacters(chunk);
contentSize += readSize;
}
} while (readSize == ATTACHMENT_BUFFER_CHUNK_SIZE);
this.writer.writeEndElement();
this.writer.writeElement(XARAttachmentModel.ELEMENT_CONTENT_SIZE, toString(contentSize));
}
this.writer.writeEndElement();
} catch (Exception e) {
throw new FilterException(String.format("Failed to write attachment [%s] from document [%s] with version [%s]", name, this.currentDocumentReference, this.currentDocumentVersion), e);
}
}
use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class XARWikiWriter method newEntry.
public OutputStream newEntry(LocalDocumentReference reference) throws FilterException {
StringBuilder path = new StringBuilder();
// Add space path
addSpacePath(path, reference.getParent());
// Add document name
path.append(escapeXARPath(reference.getName()));
// Add language
if (reference.getLocale() != null && !reference.getLocale().equals(Locale.ROOT)) {
path.append('.');
path.append(reference.getLocale());
}
// Add extension
path.append(".xml");
String entryName = path.toString();
ZipArchiveEntry zipentry = new ZipArchiveEntry(entryName);
try {
this.zipStream.putArchiveEntry(zipentry);
} catch (IOException e) {
throw new FilterException("Failed to add a new zip entry for [" + path + "]", e);
}
this.xarPackage.addEntry(reference, entryName);
return this.zipStream;
}
use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class AbstractWikiObjectPropertyReader method readObjectProperty.
public WikiObjectProperty readObjectProperty(XMLStreamReader xmlReader, XARInputProperties properties, WikiClass wikiClass) throws XMLStreamException, FilterException {
xmlReader.nextTag();
WikiObjectProperty property = new WikiObjectProperty();
property.name = xmlReader.getLocalName();
String type;
if (wikiClass != null) {
WikiClassProperty classProperty = wikiClass.properties.get(property.name);
type = classProperty != null ? classProperty.type : null;
} else {
type = properties.getObjectPropertyType();
}
try {
property.value = this.propertySerializerManager.getPropertySerializer(type).read(xmlReader);
} catch (ComponentLookupException e) {
throw new FilterException("Failed to get a property parser", e);
}
property.parameters.put(WikiObjectPropertyFilter.PARAMETER_TYPE, type);
xmlReader.nextTag();
return property;
}
use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class WikiReader method read.
public void read(Object filter, XARInputFilter proxyFilter) throws IOException, FilterException {
InputStream stream;
InputSource source = this.properties.getSource();
if (source instanceof InputStreamInputSource) {
stream = ((InputStreamInputSource) source).getInputStream();
} else {
throw new FilterException("Unsupported source type [" + source.getClass() + "]");
}
read(stream, filter, proxyFilter);
// Close remaining opened spaces
if (this.documentReader.getSentSpaceReference() != null) {
for (EntityReference space = this.documentReader.getSentSpaceReference(); space != null; space = space.getParent()) {
proxyFilter.endWikiSpace(space.getName(), FilterEventParameters.EMPTY);
}
}
// Send extension event
if (this.xarPackage.getPackageExtensionId() != null) {
proxyFilter.beginExtension(this.xarPackage.getPackageExtensionId(), this.xarPackage.getPackageVersion(), FilterEventParameters.EMPTY);
proxyFilter.endExtension(this.xarPackage.getPackageExtensionId(), this.xarPackage.getPackageVersion(), FilterEventParameters.EMPTY);
}
}
use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class DocumentInstanceInputEventGenerator method setWikiDocumentParameters.
@Override
public void setWikiDocumentParameters(String name, FilterEventParameters documentParameters) throws FilterException {
DocumentReference reference = new DocumentReference(name, new SpaceReference(this.currentReference));
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument defaultDocument;
try {
defaultDocument = xcontext.getWiki().getDocument(reference, xcontext);
} catch (XWikiException e) {
throw new FilterException("Failed to get document [" + reference + "]", e);
}
documentParameters.put(WikiDocumentFilter.PARAMETER_LOCALE, defaultDocument.getDefaultLocale());
}
Aggregations