From 11e2b1accd933eb9fcb4477a60dd0864d9f72a67 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Mon, 31 Jul 2017 08:44:32 +0200 Subject: Implements FS#245: Implement FiletransferHttp (upload and delete), some minor bug fixes including to fail a JingleTransfer in case criterias are not met --- .../http/delete/DeletedPacketParser.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeletedPacketParser.java (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeletedPacketParser.java') diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeletedPacketParser.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeletedPacketParser.java new file mode 100644 index 00000000..df17a997 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeletedPacketParser.java @@ -0,0 +1,43 @@ +package de.thedevstack.conversationsplus.xmpp.filetransfer.http.delete; + +import de.thedevstack.conversationsplus.xml.Element; +import de.thedevstack.conversationsplus.xmpp.IqPacketParser; +import de.thedevstack.conversationsplus.xmpp.exceptions.UnexpectedIqPacketTypeException; +import de.thedevstack.conversationsplus.xmpp.exceptions.XmppException; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; +import de.thedevstack.conversationsplus.xmpp.utils.ErrorIqPacketExceptionHelper; + +/** + * IqPacketParser to parse the response of a remote file delete request. + * This parser parses a IqPacket according to the specification 'filetransfer for XMPP over http". + */ +public class DeletedPacketParser extends IqPacketParser { + /** + * Parses an IqPacket. + *
+     * 
+     *   
+     * 
+     * 
+ * @param packet the packet to parse + * @return true if the result packet contains a deleted element of namespace urn:xmpp:filetransfer:http + * @throws XmppException in case of IqPacket type error or {@link UnexpectedIqPacketTypeException} in case of an unexpected IqPacket type. + */ + public static boolean parseDeleteToken(IqPacket packet) throws XmppException { + boolean successfullyDeleted = false; + if (packet.getType() == IqPacket.TYPE.RESULT) { + Element deletedElement = findRequiredChild(packet, "deleted", FileTransferHttp.NAMESPACE); + successfullyDeleted = null != deletedElement; + } else if (packet.getType() == IqPacket.TYPE.ERROR) { + ErrorIqPacketExceptionHelper.throwIqErrorException(packet); + } else { + throw new UnexpectedIqPacketTypeException(packet, packet.getType(), IqPacket.TYPE.RESULT, IqPacket.TYPE.ERROR); + } + + return successfullyDeleted; + } +} -- cgit v1.2.3