From 6aae296280da44244fea0301a7abe59d4c83437f Mon Sep 17 00:00:00 2001 From: steckbrief Date: Sat, 4 Nov 2017 21:04:04 +0100 Subject: initial version of filetransfer:http extension (support for request type=list) --- .../filetransferhttp/FileTransferHttpManager.java | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/de/thedevstack/smackx/filetransferhttp/FileTransferHttpManager.java (limited to 'src/de/thedevstack/smackx/filetransferhttp/FileTransferHttpManager.java') diff --git a/src/de/thedevstack/smackx/filetransferhttp/FileTransferHttpManager.java b/src/de/thedevstack/smackx/filetransferhttp/FileTransferHttpManager.java new file mode 100644 index 0000000..fffbcbd --- /dev/null +++ b/src/de/thedevstack/smackx/filetransferhttp/FileTransferHttpManager.java @@ -0,0 +1,77 @@ +package de.thedevstack.smackx.filetransferhttp; + +import java.util.Map; +import java.util.WeakHashMap; +import java.util.logging.Logger; + +import org.jivesoftware.smack.ConnectionCreationListener; +import org.jivesoftware.smack.Manager; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPConnectionRegistry; +import org.jivesoftware.smack.SmackException.NoResponseException; +import org.jivesoftware.smack.SmackException.NotConnectedException; +import org.jivesoftware.smack.XMPPException.XMPPErrorException; +import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; + +import de.thedevstack.smackx.filetransferhttp.element.FileList; +import de.thedevstack.smackx.filetransferhttp.element.Request; + +public class FileTransferHttpManager extends Manager { + + private static final Logger LOGGER = Logger.getLogger(FileTransferHttpManager.class.getName()); + + static { + XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { + @Override + public void connectionCreated(XMPPConnection connection) { + getInstanceFor(connection); + } + }); + } + + private static final Map INSTANCES = new WeakHashMap<>(); + + + /** + * Obtain the HttpFileUploadManager responsible for a connection. + * + * @param connection the connection object. + * @return a HttpFileUploadManager instance + */ + public static synchronized FileTransferHttpManager getInstanceFor(XMPPConnection connection) { + FileTransferHttpManager fileTransferHttpManager = INSTANCES.get(connection); + + if (fileTransferHttpManager == null) { + fileTransferHttpManager = new FileTransferHttpManager(connection); + INSTANCES.put(connection, fileTransferHttpManager); + } + + return fileTransferHttpManager; + } + + private FileTransferHttpManager(XMPPConnection connection) { + super(connection); + } + + public FileList requestFileList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + final XMPPConnection connection = connection(); + Request request = new Request(); + request.setTo(connection.getXMPPServiceDomain()); + return connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + } + + + /** + * Returns true if XMPP Carbons are supported by the server. + * + * @return true if supported + * @throws NotConnectedException + * @throws XMPPErrorException + * @throws NoResponseException + * @throws InterruptedException + */ + public boolean isSupportedByServer() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + return ServiceDiscoveryManager.getInstanceFor(connection()).serverSupportsFeature(FileTransferHttp.NAMESPACE); + } + +} -- cgit v1.2.3