package de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp; 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 account the account requesting a slot * @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(Account account, Jid recipient, String filename, long filesize, String mime) { String namespace = getNamespace(account); Jid host = getHost(account, namespace); IqPacket requestPacket; switch (namespace) { case HttpUpload.NAMESPACE: requestPacket = new HttpUploadSlotRequestPacket(filename, filesize, mime); break; case FileTransferHttp.NAMESPACE: default: requestPacket = new FileTransferHttpUploadSlotRequestPacket(recipient.toString(), filename, filesize, mime); } requestPacket.setTo(host); return requestPacket; } private static String getNamespace(Account account) { if (null != account.getXmppConnection().findDiscoItemByFeature(FileTransferHttp.NAMESPACE)) { return FileTransferHttp.NAMESPACE; } else { return HttpUpload.NAMESPACE; } } private static Jid getHost(Account account, String namespace) { return account.getXmppConnection().findDiscoItemByFeature(namespace); } /** * Utility class - avoid instantiation */ private HttpUploadRequestSlotPacketGenerator() { // Helper class - avoid instantiation } }