summaryrefslogtreecommitdiffstats
path: root/src/de/thedevstack/smackx/filetransferhttp/FileTransferHttpManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/thedevstack/smackx/filetransferhttp/FileTransferHttpManager.java')
-rw-r--r--src/de/thedevstack/smackx/filetransferhttp/FileTransferHttpManager.java77
1 files changed, 77 insertions, 0 deletions
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<XMPPConnection, FileTransferHttpManager> 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);
+ }
+
+}