From 2d462a746ea6e733f9f2836b181795c80de5aae5 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Tue, 23 Aug 2016 09:46:51 +0200 Subject: xmpp.httpupload moved to new namespace xmpp.filetransfer.http.upload; delete parts of xmpp.filetransfer.http moved to .delete package --- .../http/HttpUploadConnection.java | 13 ++---- .../filetransfer/http/DeleteRemoteFileService.java | 2 +- .../filetransfer/http/DeleteTokenReceived.java | 2 +- .../httpupload/HttpFileTransferEntity.java | 2 +- .../filetransfer/httpupload/HttpFileUploader.java | 5 +- .../httpupload/HttpUploadFileTransferService.java | 4 +- .../httpupload/HttpUploadSlotRequestReceived.java | 4 +- .../filetransfer/http/DeleteSlotPacketParser.java | 28 ------------ .../filetransfer/http/DeleteSlotRequestPacket.java | 33 -------------- ...ansferHttpDeleteSlotRequestPacketGenerator.java | 39 ---------------- .../http/delete/DeleteSlotPacketParser.java | 29 ++++++++++++ .../http/delete/DeleteSlotRequestPacket.java | 34 ++++++++++++++ ...ansferHttpDeleteSlotRequestPacketGenerator.java | 39 ++++++++++++++++ .../xmpp/filetransfer/http/upload/HttpUpload.java | 9 ++++ .../HttpUploadRequestSlotPacketGenerator.java | 46 +++++++++++++++++++ .../filetransfer/http/upload/HttpUploadSlot.java | 22 +++++++++ .../filetransfer/http/upload/SlotPacketParser.java | 30 ++++++++++++ .../http/upload/SlotRequestPacket.java | 53 ++++++++++++++++++++++ .../xmpp/httpupload/HttpUpload.java | 9 ---- .../HttpUploadRequestSlotPacketGenerator.java | 46 ------------------- .../xmpp/httpupload/HttpUploadSlot.java | 22 --------- .../xmpp/httpupload/SlotPacketParser.java | 30 ------------ .../xmpp/httpupload/SlotRequestPacket.java | 53 ---------------------- 23 files changed, 274 insertions(+), 280 deletions(-) delete mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/DeleteSlotPacketParser.java delete mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/DeleteSlotRequestPacket.java delete mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/FileTransferHttpDeleteSlotRequestPacketGenerator.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotPacketParser.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotRequestPacket.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/FileTransferHttpDeleteSlotRequestPacketGenerator.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUpload.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadSlot.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/SlotPacketParser.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/SlotRequestPacket.java delete mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUpload.java delete mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUploadRequestSlotPacketGenerator.java delete mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUploadSlot.java delete mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/SlotPacketParser.java delete mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/SlotRequestPacket.java diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java index 7c791e70..3c49d083 100644 --- a/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java @@ -29,18 +29,13 @@ import de.thedevstack.conversationsplus.services.AbstractConnectionManager; import de.thedevstack.conversationsplus.services.XmppConnectionService; import de.thedevstack.conversationsplus.ui.UiCallback; import de.thedevstack.conversationsplus.utils.CryptoHelper; -import de.thedevstack.conversationsplus.utils.Xmlns; import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor; -import de.thedevstack.conversationsplus.xml.Element; import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived; -import de.thedevstack.conversationsplus.xmpp.exceptions.MissingRequiredContentException; -import de.thedevstack.conversationsplus.xmpp.exceptions.MissingRequiredElementException; import de.thedevstack.conversationsplus.xmpp.exceptions.XmppException; -import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUpload; -import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUploadRequestSlotPacketGenerator; -import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUploadSlot; -import de.thedevstack.conversationsplus.xmpp.httpupload.SlotPacketParser; -import de.thedevstack.conversationsplus.xmpp.httpupload.SlotRequestPacket; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUpload; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUploadRequestSlotPacketGenerator; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUploadSlot; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.SlotPacketParser; import de.thedevstack.conversationsplus.xmpp.jid.Jid; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/DeleteRemoteFileService.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/DeleteRemoteFileService.java index 57f408cc..565143be 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/DeleteRemoteFileService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/DeleteRemoteFileService.java @@ -4,7 +4,7 @@ import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.utils.XmppSendUtil; import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp; -import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttpDeleteSlotRequestPacketGenerator; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.delete.FileTransferHttpDeleteSlotRequestPacketGenerator; import de.thedevstack.conversationsplus.xmpp.jid.Jid; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/DeleteTokenReceived.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/DeleteTokenReceived.java index fb83219b..cce0b713 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/DeleteTokenReceived.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/DeleteTokenReceived.java @@ -12,7 +12,7 @@ import de.thedevstack.conversationsplus.http.HttpClient; import de.thedevstack.conversationsplus.utils.MessageUtil; import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived; import de.thedevstack.conversationsplus.xmpp.exceptions.XmppException; -import de.thedevstack.conversationsplus.xmpp.filetransfer.http.DeleteSlotPacketParser; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.delete.DeleteSlotPacketParser; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; import okhttp3.Call; import okhttp3.Callback; diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpFileTransferEntity.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpFileTransferEntity.java index a8e5734f..f6596b0c 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpFileTransferEntity.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpFileTransferEntity.java @@ -11,7 +11,7 @@ import de.thedevstack.conversationsplus.services.filetransfer.FileTransferEntity import de.thedevstack.conversationsplus.services.filetransfer.FileTransferFailureReason; import de.thedevstack.conversationsplus.utils.CryptoHelper; import de.thedevstack.conversationsplus.utils.MessageUtil; -import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUploadSlot; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUploadSlot; /** * diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpFileUploader.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpFileUploader.java index 8edc5be7..705dd23c 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpFileUploader.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpFileUploader.java @@ -13,19 +13,16 @@ import java.util.Scanner; import javax.net.ssl.HttpsURLConnection; import de.thedevstack.android.logcat.Logging; -import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.entities.DownloadableFile; import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.http.HttpConnectionManager; import de.thedevstack.conversationsplus.persistance.FileBackend; import de.thedevstack.conversationsplus.services.filetransfer.FileTransferFailureReason; -import de.thedevstack.conversationsplus.utils.CryptoHelper; -import de.thedevstack.conversationsplus.utils.MessageUtil; import de.thedevstack.conversationsplus.utils.StreamUtil; import de.thedevstack.conversationsplus.utils.UiUpdateHelper; import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor; -import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUpload; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUpload; public class HttpFileUploader implements Runnable { private static final String HTTP_METHOD = "PUT"; diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpUploadFileTransferService.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpUploadFileTransferService.java index fb150a92..6fd458a9 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpUploadFileTransferService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpUploadFileTransferService.java @@ -15,8 +15,8 @@ import de.thedevstack.conversationsplus.services.FileTransferService; import de.thedevstack.conversationsplus.services.filetransfer.AbstractFileTransferService; import de.thedevstack.conversationsplus.utils.MessageUtil; import de.thedevstack.conversationsplus.utils.XmppSendUtil; -import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUpload; -import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUploadRequestSlotPacketGenerator; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUpload; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUploadRequestSlotPacketGenerator; import de.thedevstack.conversationsplus.xmpp.jid.Jid; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpUploadSlotRequestReceived.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpUploadSlotRequestReceived.java index 462a370c..75e793f1 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpUploadSlotRequestReceived.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/httpupload/HttpUploadSlotRequestReceived.java @@ -5,8 +5,8 @@ import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.services.filetransfer.FileTransferFailureReason; import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived; import de.thedevstack.conversationsplus.xmpp.exceptions.XmppException; -import de.thedevstack.conversationsplus.xmpp.httpupload.HttpUploadSlot; -import de.thedevstack.conversationsplus.xmpp.httpupload.SlotPacketParser; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUploadSlot; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.SlotPacketParser; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; /** diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/DeleteSlotPacketParser.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/DeleteSlotPacketParser.java deleted file mode 100644 index d7e136fc..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/DeleteSlotPacketParser.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.thedevstack.conversationsplus.xmpp.filetransfer.http; - -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.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/DeleteSlotRequestPacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/DeleteSlotRequestPacket.java deleted file mode 100644 index 6adc3aac..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/DeleteSlotRequestPacket.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.thedevstack.conversationsplus.xmpp.filetransfer.http; - -import de.thedevstack.conversationsplus.xml.Element; -import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; - -/** - * Created by steckbrief on 21.08.2016. - */ -public class DeleteSlotRequestPacket 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() { - super(TYPE.GET); - this.requestElement = super.addChild(DeleteSlotRequestPacket.ELEMENT_NAME, FileTransferHttp.NAMESPACE); - this.requestElement.setAttribute("type", "delete"); - } - - public DeleteSlotRequestPacket(String fileurl) { - this(); - this.setFileURL(fileurl); - } - - public void setFileURL(String fileurl) { - if (null == fileurl || fileurl.isEmpty()) { - throw new IllegalArgumentException("fileurl must not be null or empty."); - } - this.fileurl = fileurl; - this.requestElement.addChild(FILEURL_ELEMENT_NAME).setContent(fileurl); - } -} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/FileTransferHttpDeleteSlotRequestPacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/FileTransferHttpDeleteSlotRequestPacketGenerator.java deleted file mode 100644 index bc4380fe..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/FileTransferHttpDeleteSlotRequestPacketGenerator.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.thedevstack.conversationsplus.xmpp.filetransfer.http; - -import de.thedevstack.conversationsplus.xmpp.jid.Jid; -import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; - -/** - * Created by steckbrief on 21.08.2016. - */ -public final class FileTransferHttpDeleteSlotRequestPacketGenerator { - /** - * 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. - *
-     * 
-     *   
-     *     http://upload.montague.tld/files/1e56ee17-ee4c-4a9c-aedd-cb09cb3984a7/my_juliet.png
-     *   
-     * 
-     * 
- * @param host the jid of the host to request a slot from - * @param fileurl the URL of the file to be deleted - * @return the IqPacket - */ - public static IqPacket generate(Jid host, String fileurl) { - DeleteSlotRequestPacket packet = new DeleteSlotRequestPacket(fileurl); - packet.setTo(host); - return packet; - } - - /** - * Utility class - avoid instantiation - */ - private FileTransferHttpDeleteSlotRequestPacketGenerator() { - // Helper class - avoid instantiation - } -} 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 new file mode 100644 index 00000000..7c011449 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotPacketParser.java @@ -0,0 +1,29 @@ +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/DeleteSlotRequestPacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotRequestPacket.java new file mode 100644 index 00000000..e389d851 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/DeleteSlotRequestPacket.java @@ -0,0 +1,34 @@ +package de.thedevstack.conversationsplus.xmpp.filetransfer.http.delete; + +import de.thedevstack.conversationsplus.xml.Element; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; + +/** + * Created by steckbrief on 21.08.2016. + */ +public class DeleteSlotRequestPacket 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() { + super(TYPE.GET); + this.requestElement = super.addChild(DeleteSlotRequestPacket.ELEMENT_NAME, FileTransferHttp.NAMESPACE); + this.requestElement.setAttribute("type", "delete"); + } + + public DeleteSlotRequestPacket(String fileurl) { + this(); + this.setFileURL(fileurl); + } + + public void setFileURL(String fileurl) { + if (null == fileurl || fileurl.isEmpty()) { + throw new IllegalArgumentException("fileurl must not be null or empty."); + } + this.fileurl = fileurl; + this.requestElement.addChild(FILEURL_ELEMENT_NAME).setContent(fileurl); + } +} 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/FileTransferHttpDeleteSlotRequestPacketGenerator.java new file mode 100644 index 00000000..ac7de74e --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/delete/FileTransferHttpDeleteSlotRequestPacketGenerator.java @@ -0,0 +1,39 @@ +package de.thedevstack.conversationsplus.xmpp.filetransfer.http.delete; + +import de.thedevstack.conversationsplus.xmpp.jid.Jid; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; + +/** + * Created by steckbrief on 21.08.2016. + */ +public final class FileTransferHttpDeleteSlotRequestPacketGenerator { + /** + * 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. + *
+     * 
+     *   
+     *     http://upload.montague.tld/files/1e56ee17-ee4c-4a9c-aedd-cb09cb3984a7/my_juliet.png
+     *   
+     * 
+     * 
+ * @param host the jid of the host to request a slot from + * @param fileurl the URL of the file to be deleted + * @return the IqPacket + */ + public static IqPacket generate(Jid host, String fileurl) { + DeleteSlotRequestPacket packet = new DeleteSlotRequestPacket(fileurl); + packet.setTo(host); + return packet; + } + + /** + * Utility class - avoid instantiation + */ + private FileTransferHttpDeleteSlotRequestPacketGenerator() { + // Helper class - avoid instantiation + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUpload.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUpload.java new file mode 100644 index 00000000..3bcbd219 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUpload.java @@ -0,0 +1,9 @@ +package de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload; + +/** + * + */ +public interface HttpUpload { + String NAMESPACE = "urn:xmpp:http:upload"; + String DEFAULT_MIME_TYPE = "application/octet-stream"; +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java new file mode 100644 index 00000000..eaa90ab0 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java @@ -0,0 +1,46 @@ +package de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload; + +import de.thedevstack.conversationsplus.xmpp.jid.Jid; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; + +/** + * Generates the IQ Packets for requesting a http upload slot + * as defined in XEP-0363. + * @see http://xmpp.org/extensions/xep-0363.html + */ +public final class HttpUploadRequestSlotPacketGenerator { + /** + * Generates the IqPacket to request a http upload slot. + * The attributes from and id are not set in here - this is added while sending the packet. + *
+     * 
+     *   
+     *     my_juliet.png
+     *     23456
+     *     image/jpeg
+     *   
+     * 
+     * 
+ * @param host the jid of the host to request a slot from + * @param filename the filename of the file which will be transferred + * @param filesize the filesize of the file which will be transferred + * @param mime the mime type of the file which will be transferred - optional and therefore nullable + * @return the IqPacket + */ + public static IqPacket generate(Jid host, String filename, long filesize, String mime) { + SlotRequestPacket packet = new SlotRequestPacket(filename, filesize); + packet.setTo(host); + packet.setMime((mime == null) ? HttpUpload.DEFAULT_MIME_TYPE : mime); + return packet; + } + + /** + * Utility class - avoid instantiation + */ + private HttpUploadRequestSlotPacketGenerator() { + // Helper class - avoid instantiation + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadSlot.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadSlot.java new file mode 100644 index 00000000..1e320afe --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadSlot.java @@ -0,0 +1,22 @@ +package de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload; + +/** + * + */ +public class HttpUploadSlot { + private final String getUrl; + private final String putUrl; + + public HttpUploadSlot(String getUrl, String putUrl) { + this.getUrl = getUrl; + this.putUrl = putUrl; + } + + public String getGetUrl() { + return this.getUrl; + } + + public String getPutUrl() { + return this.putUrl; + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/SlotPacketParser.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/SlotPacketParser.java new file mode 100644 index 00000000..85d11b6b --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/SlotPacketParser.java @@ -0,0 +1,30 @@ +package de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload; + +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.stanzas.IqPacket; +import de.thedevstack.conversationsplus.xmpp.utils.ErrorIqPacketExceptionHelper; + +/** + * + */ +public final class SlotPacketParser extends IqPacketParser { + public static HttpUploadSlot parseGetAndPutUrl(IqPacket packet) throws XmppException { + HttpUploadSlot httpUploadSlot = null; + if (packet.getType() == IqPacket.TYPE.RESULT) { + Element slot = findRequiredChild(packet, "slot", HttpUpload.NAMESPACE); + + String getUrl = findRequiredChildContent(slot, "get"); + String putUrl = findRequiredChildContent(slot, "put"); + + httpUploadSlot = new HttpUploadSlot(getUrl, putUrl); + } else if (packet.getType() == IqPacket.TYPE.ERROR) { + ErrorIqPacketExceptionHelper.throwIqErrorException(packet); + } else { + throw new UnexpectedIqPacketTypeException(packet, packet.getType(), IqPacket.TYPE.RESULT, IqPacket.TYPE.ERROR); + } + return httpUploadSlot; + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/SlotRequestPacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/SlotRequestPacket.java new file mode 100644 index 00000000..d0866508 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/SlotRequestPacket.java @@ -0,0 +1,53 @@ +package de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload; + +import de.thedevstack.conversationsplus.xml.Element; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; + +/** + * + */ +public class SlotRequestPacket extends IqPacket { + public static final String ELEMENT_NAME = "request"; + public static final String FILENAME_ELEMENT_NAME = "filename"; + public static final String FILESIZE_ELEMENT_NAME = "size"; + public static final String MIME_ELEMENT_NAME = "content-type"; + private Element requestElement; + private String filename; + private long filesize; + private String mime; + + private SlotRequestPacket() { + super(TYPE.GET); + this.requestElement = super.addChild(SlotRequestPacket.ELEMENT_NAME, HttpUpload.NAMESPACE); + } + + public SlotRequestPacket(String filename, long filesize) { + this(); + this.setFilename(filename); + this.setFilesize(filesize); + } + + public void setFilename(String filename) { + if (null == filename || filename.isEmpty()) { + throw new IllegalArgumentException("filename must not be null or empty."); + } + this.filename = filename; + this.requestElement.addChild(FILENAME_ELEMENT_NAME).setContent(filename); + } + + public void setFilesize(long filesize) { + if (0 >= filesize) { + throw new IllegalArgumentException("filesize must not be null or empty."); + } + this.filesize = filesize; + this.requestElement.addChild(FILESIZE_ELEMENT_NAME).setContent(String.valueOf(filesize)); + } + + public void setMime(String mime) { + if (null == mime || mime.isEmpty()) { + throw new IllegalArgumentException("mime type must not be null or empty."); + } + this.mime = mime; + this.requestElement.addChild(MIME_ELEMENT_NAME).setContent(mime); + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUpload.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUpload.java deleted file mode 100644 index 28cba280..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUpload.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.thedevstack.conversationsplus.xmpp.httpupload; - -/** - * - */ -public interface HttpUpload { - String NAMESPACE = "urn:xmpp:http:upload"; - String DEFAULT_MIME_TYPE = "application/octet-stream"; -} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUploadRequestSlotPacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUploadRequestSlotPacketGenerator.java deleted file mode 100644 index 59851417..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUploadRequestSlotPacketGenerator.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.thedevstack.conversationsplus.xmpp.httpupload; - -import de.thedevstack.conversationsplus.xmpp.jid.Jid; -import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; - -/** - * Generates the IQ Packets for requesting a http upload slot - * as defined in XEP-0363. - * @see http://xmpp.org/extensions/xep-0363.html - */ -public final class HttpUploadRequestSlotPacketGenerator { - /** - * Generates the IqPacket to request a http upload slot. - * The attributes from and id are not set in here - this is added while sending the packet. - *
-     * 
-     *   
-     *     my_juliet.png
-     *     23456
-     *     image/jpeg
-     *   
-     * 
-     * 
- * @param host the jid of the host to request a slot from - * @param filename the filename of the file which will be transferred - * @param filesize the filesize of the file which will be transferred - * @param mime the mime type of the file which will be transferred - optional and therefore nullable - * @return the IqPacket - */ - public static IqPacket generate(Jid host, String filename, long filesize, String mime) { - SlotRequestPacket packet = new SlotRequestPacket(filename, filesize); - packet.setTo(host); - packet.setMime((mime == null) ? HttpUpload.DEFAULT_MIME_TYPE : mime); - return packet; - } - - /** - * Utility class - avoid instantiation - */ - private HttpUploadRequestSlotPacketGenerator() { - // Helper class - avoid instantiation - } -} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUploadSlot.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUploadSlot.java deleted file mode 100644 index 14fe5103..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/HttpUploadSlot.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.thedevstack.conversationsplus.xmpp.httpupload; - -/** - * - */ -public class HttpUploadSlot { - private final String getUrl; - private final String putUrl; - - public HttpUploadSlot(String getUrl, String putUrl) { - this.getUrl = getUrl; - this.putUrl = putUrl; - } - - public String getGetUrl() { - return this.getUrl; - } - - public String getPutUrl() { - return this.putUrl; - } -} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/SlotPacketParser.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/SlotPacketParser.java deleted file mode 100644 index 655d8759..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/SlotPacketParser.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.thedevstack.conversationsplus.xmpp.httpupload; - -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.stanzas.IqPacket; -import de.thedevstack.conversationsplus.xmpp.utils.ErrorIqPacketExceptionHelper; - -/** - * - */ -public final class SlotPacketParser extends IqPacketParser { - public static HttpUploadSlot parseGetAndPutUrl(IqPacket packet) throws XmppException { - HttpUploadSlot httpUploadSlot = null; - if (packet.getType() == IqPacket.TYPE.RESULT) { - Element slot = findRequiredChild(packet, "slot", HttpUpload.NAMESPACE); - - String getUrl = findRequiredChildContent(slot, "get"); - String putUrl = findRequiredChildContent(slot, "put"); - - httpUploadSlot = new HttpUploadSlot(getUrl, putUrl); - } else if (packet.getType() == IqPacket.TYPE.ERROR) { - ErrorIqPacketExceptionHelper.throwIqErrorException(packet); - } else { - throw new UnexpectedIqPacketTypeException(packet, packet.getType(), IqPacket.TYPE.RESULT, IqPacket.TYPE.ERROR); - } - return httpUploadSlot; - } -} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/SlotRequestPacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/SlotRequestPacket.java deleted file mode 100644 index d470d2f5..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/httpupload/SlotRequestPacket.java +++ /dev/null @@ -1,53 +0,0 @@ -package de.thedevstack.conversationsplus.xmpp.httpupload; - -import de.thedevstack.conversationsplus.xml.Element; -import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; - -/** - * - */ -public class SlotRequestPacket extends IqPacket { - public static final String ELEMENT_NAME = "request"; - public static final String FILENAME_ELEMENT_NAME = "filename"; - public static final String FILESIZE_ELEMENT_NAME = "size"; - public static final String MIME_ELEMENT_NAME = "content-type"; - private Element requestElement; - private String filename; - private long filesize; - private String mime; - - private SlotRequestPacket() { - super(TYPE.GET); - this.requestElement = super.addChild(SlotRequestPacket.ELEMENT_NAME, HttpUpload.NAMESPACE); - } - - public SlotRequestPacket(String filename, long filesize) { - this(); - this.setFilename(filename); - this.setFilesize(filesize); - } - - public void setFilename(String filename) { - if (null == filename || filename.isEmpty()) { - throw new IllegalArgumentException("filename must not be null or empty."); - } - this.filename = filename; - this.requestElement.addChild(FILENAME_ELEMENT_NAME).setContent(filename); - } - - public void setFilesize(long filesize) { - if (0 >= filesize) { - throw new IllegalArgumentException("filesize must not be null or empty."); - } - this.filesize = filesize; - this.requestElement.addChild(FILESIZE_ELEMENT_NAME).setContent(String.valueOf(filesize)); - } - - public void setMime(String mime) { - if (null == mime || mime.isEmpty()) { - throw new IllegalArgumentException("mime type must not be null or empty."); - } - this.mime = mime; - this.requestElement.addChild(MIME_ELEMENT_NAME).setContent(mime); - } -} -- cgit v1.2.3