use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class XAROutputFilterStream method onWikiObjectProperty.
@Override
public void onWikiObjectProperty(String name, Object value, FilterEventParameters parameters) throws FilterException {
checkXMLWriter();
try {
this.writer.writeStartElement(XARObjectPropertyModel.ELEMENT_PROPERTY);
this.writer.writeStartElement(name);
String type = (String) parameters.get(WikiObjectPropertyFilter.PARAMETER_TYPE);
if (type == null && this.currentObjectProperties != null) {
type = this.currentObjectProperties.get(name);
}
try {
this.propertySerializerManager.getPropertySerializer(type).write(this.writer.getWriter(), value);
} catch (Exception e) {
throw new FilterException("Failed to write property value", e);
}
this.writer.writeEndElement();
this.writer.writeEndElement();
} catch (Exception e) {
throw new FilterException(String.format("Failed to write xobject property [%s:%s] from document [%s] with version [%s]", name, value, this.currentDocumentReference, this.currentDocumentVersion), e);
}
}
use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class XAROutputFilterStream method beginWikiObject.
@Override
public void beginWikiObject(String name, FilterEventParameters parameters) throws FilterException {
checkXMLWriter();
try {
this.writer.writeStartElement(XARObjectModel.ELEMENT_OBJECT);
this.currentObjectClass = (String) parameters.get(WikiObjectFilter.PARAMETER_CLASS_REFERENCE);
if (parameters.containsKey(WikiObjectFilter.PARAMETER_NAME)) {
this.writer.writeElement(XARObjectModel.ELEMENT_NAME, (String) parameters.get(WikiObjectFilter.PARAMETER_NAME));
} else {
this.writer.writeElement(XARObjectModel.ELEMENT_NAME, this.localSerializer.serialize(this.currentDocumentReference));
}
this.writer.writeElement(XARObjectModel.ELEMENT_NUMBER, toString((Integer) parameters.get(WikiObjectFilter.PARAMETER_NUMBER)));
this.writer.writeElement(XARObjectModel.ELEMENT_CLASSNAME, this.currentObjectClass);
if (parameters.containsKey(WikiObjectFilter.PARAMETER_GUID)) {
this.writer.writeElement(XARObjectModel.ELEMENT_GUID, (String) parameters.get(WikiObjectFilter.PARAMETER_GUID));
}
this.currentObjectProperties = new HashMap<String, String>();
} catch (Exception e) {
throw new FilterException(String.format("Failed to write begin xobject [%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 XAROutputFilterStream method endWikiObject.
@Override
public void endWikiObject(String name, FilterEventParameters parameters) throws FilterException {
try {
this.writer.writeEndElement();
this.currentObjectClass = null;
this.currentObjectProperties = null;
} catch (Exception e) {
throw new FilterException(String.format("Failed to write end xobject [%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 AttachmentReader method read.
@Override
public WikiAttachment read(XMLStreamReader xmlReader, XARInputProperties properties) throws XMLStreamException, FilterException {
WikiAttachment wikiAttachment = new WikiAttachment();
for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
String elementName = xmlReader.getLocalName();
EventParameter parameter = XARAttachmentModel.ATTACHMENT_PARAMETERS.get(elementName);
if (parameter != null) {
Object wsValue = convert(parameter.type, xmlReader.getElementText());
if (wsValue != null) {
wikiAttachment.parameters.put(parameter.name, wsValue);
}
} else {
if (XARAttachmentModel.ELEMENT_NAME.equals(elementName)) {
wikiAttachment.name = xmlReader.getElementText();
} else if (XARAttachmentModel.ELEMENT_CONTENT_SIZE.equals(elementName)) {
wikiAttachment.size = Long.valueOf(xmlReader.getElementText());
} else if (XARAttachmentModel.ELEMENT_CONTENT.equals(elementName)) {
// We copy the attachment content to use it later. We can't directly send it as a stream because XAR
// specification does not force any order for the attachment properties and we need to be sure we
// have everything when sending the event.
// Allocate a temporary file in case the attachment content is big
File temporaryFile;
try {
temporaryFile = File.createTempFile("xar/attachments/attachment", ".bin");
} catch (IOException e) {
throw new FilterException(e);
}
// Create a deferred file based content (if the content is bigger than 10000 bytes it will end up in
// a file)
wikiAttachment.content = new DeferredFileOutputStream(100000, temporaryFile);
// Copy the content to byte array or file depending on its size
for (xmlReader.next(); xmlReader.isCharacters(); xmlReader.next()) {
try {
wikiAttachment.content.write(xmlReader.getText().getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new FilterException(e);
}
}
}
}
}
return wikiAttachment;
}
use of org.xwiki.filter.FilterException in project xwiki-platform by xwiki.
the class DefaultInstanceModel method getWikiReferences.
@Override
public List<WikiReference> getWikiReferences() throws FilterException {
XWikiContext xcontext = this.xcontextProvider.get();
try {
List<String> wikis = xcontext.getWiki().getVirtualWikisDatabaseNames(xcontext);
List<WikiReference> wikiReferences = new ArrayList<>(wikis.size());
for (String wikiName : wikis) {
wikiReferences.add(new WikiReference(new WikiReference(wikiName)));
}
Collections.sort(wikis);
return wikiReferences;
} catch (XWikiException e) {
throw new FilterException("Failed to get the list of wikis", e);
}
}
Aggregations