Search in sources :

Example 26 with FilterException

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);
    }
}
Also used : FilterException(org.xwiki.filter.FilterException) IOException(java.io.IOException) FilterException(org.xwiki.filter.FilterException)

Example 27 with FilterException

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);
    }
}
Also used : FilterException(org.xwiki.filter.FilterException) IOException(java.io.IOException) FilterException(org.xwiki.filter.FilterException)

Example 28 with FilterException

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);
    }
}
Also used : FilterException(org.xwiki.filter.FilterException) IOException(java.io.IOException) FilterException(org.xwiki.filter.FilterException)

Example 29 with FilterException

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;
}
Also used : EventParameter(org.xwiki.filter.xar.internal.XARFilterUtils.EventParameter) FilterException(org.xwiki.filter.FilterException) IOException(java.io.IOException) DeferredFileOutputStream(org.apache.commons.io.output.DeferredFileOutputStream) File(java.io.File)

Example 30 with FilterException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) FilterException(org.xwiki.filter.FilterException) WikiReference(org.xwiki.model.reference.WikiReference) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

FilterException (org.xwiki.filter.FilterException)35 IOException (java.io.IOException)17 XWikiException (com.xpn.xwiki.XWikiException)10 XWikiContext (com.xpn.xwiki.XWikiContext)7 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)6 Date (java.util.Date)6 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)6 DocumentReference (org.xwiki.model.reference.DocumentReference)5 ArrayList (java.util.ArrayList)4 InputFilterStream (org.xwiki.filter.input.InputFilterStream)3 OutputFilterStream (org.xwiki.filter.output.OutputFilterStream)3 WikiReference (org.xwiki.model.reference.WikiReference)3 QueryException (org.xwiki.query.QueryException)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 BaseObject (com.xpn.xwiki.objects.BaseObject)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 ComponentManager (org.xwiki.component.manager.ComponentManager)2