diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteRequestPacket.java (renamed from src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotRequestPacket.java) | 8 | ||||
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotPacketParser.java | 29 | ||||
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeletedPacketParser.java | 43 | ||||
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/FileTransferHttpDeleteRequestPacketGenerator.java (renamed from src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/FileTransferHttpDeleteSlotRequestPacketGenerator.java) | 6 |
4 files changed, 50 insertions, 36 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotRequestPacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteRequestPacket.java index e389d851..d358a266 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotRequestPacket.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteRequestPacket.java @@ -7,19 +7,19 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; /** * Created by steckbrief on 21.08.2016. */ -public class DeleteSlotRequestPacket extends IqPacket { +public class DeleteRequestPacket extends IqPacket { public static final String ELEMENT_NAME = "request"; public static final String FILEURL_ELEMENT_NAME = "fileurl"; private Element requestElement; private String fileurl; - private DeleteSlotRequestPacket() { + private DeleteRequestPacket() { super(TYPE.GET); - this.requestElement = super.addChild(DeleteSlotRequestPacket.ELEMENT_NAME, FileTransferHttp.NAMESPACE); + this.requestElement = super.addChild(DeleteRequestPacket.ELEMENT_NAME, FileTransferHttp.NAMESPACE); this.requestElement.setAttribute("type", "delete"); } - public DeleteSlotRequestPacket(String fileurl) { + public DeleteRequestPacket(String fileurl) { this(); this.setFileURL(fileurl); } diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotPacketParser.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotPacketParser.java deleted file mode 100644 index 7c011449..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotPacketParser.java +++ /dev/null @@ -1,29 +0,0 @@ -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; - -/** - * Created by steckbrief on 21.08.2016. - */ -public class DeleteSlotPacketParser extends IqPacketParser { - public static String parseDeleteToken(IqPacket packet) throws XmppException { - String deletetoken = null; - if (packet.getType() == IqPacket.TYPE.RESULT) { - Element slot = findRequiredChild(packet, "slot", FileTransferHttp.NAMESPACE); - - deletetoken = findRequiredChildContent(slot, "deletetoken"); - } else if (packet.getType() == IqPacket.TYPE.ERROR) { - ErrorIqPacketExceptionHelper.throwIqErrorException(packet); - } else { - throw new UnexpectedIqPacketTypeException(packet, packet.getType(), IqPacket.TYPE.RESULT, IqPacket.TYPE.ERROR); - } - - return deletetoken; - } -} 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; + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/FileTransferHttpDeleteSlotRequestPacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/FileTransferHttpDeleteRequestPacketGenerator.java index ac7de74e..88ad5d5a 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/FileTransferHttpDeleteSlotRequestPacketGenerator.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/FileTransferHttpDeleteRequestPacketGenerator.java @@ -6,7 +6,7 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; /** * Created by steckbrief on 21.08.2016. */ -public final class FileTransferHttpDeleteSlotRequestPacketGenerator { +public final class FileTransferHttpDeleteRequestPacketGenerator { /** * Generates the IqPacket to request a slot to delete a file previously uploaded via http upload. * The attributes from and id are not set in here - this is added while sending the packet. @@ -25,7 +25,7 @@ public final class FileTransferHttpDeleteSlotRequestPacketGenerator { * @return the IqPacket */ public static IqPacket generate(Jid host, String fileurl) { - DeleteSlotRequestPacket packet = new DeleteSlotRequestPacket(fileurl); + DeleteRequestPacket packet = new DeleteRequestPacket(fileurl); packet.setTo(host); return packet; } @@ -33,7 +33,7 @@ public final class FileTransferHttpDeleteSlotRequestPacketGenerator { /** * Utility class - avoid instantiation */ - private FileTransferHttpDeleteSlotRequestPacketGenerator() { + private FileTransferHttpDeleteRequestPacketGenerator() { // Helper class - avoid instantiation } } |