aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeletedPacketParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeletedPacketParser.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeletedPacketParser.java43
1 files changed, 43 insertions, 0 deletions
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.
+ * <pre>
+ * <iq from='montague.tld'
+ * id='delete-file_002'
+ * to='romeo@montague.tld/garden'
+ * type='result'>
+ * <deleted xmlns='urn:xmpp:filetransfer:http'/>
+ * </iq>
+ * </pre>
+ * @param packet the packet to parse
+ * @return <code>true</code> if the result packet contains a deleted element of namespace <code>urn:xmpp:filetransfer:http</code>
+ * @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;
+ }
+}