HOXTManager.java

  1. /**
  2.  *
  3.  * Copyright 2014 Andriy Tsykholyas
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.hoxt;

  18. import org.jivesoftware.smack.ConnectionCreationListener;
  19. import org.jivesoftware.smack.SmackException.NoResponseException;
  20. import org.jivesoftware.smack.XMPPConnection;
  21. import org.jivesoftware.smack.XMPPConnectionRegistry;
  22. import org.jivesoftware.smack.XMPPException.XMPPErrorException;
  23. import org.jivesoftware.smack.SmackException.NotConnectedException;
  24. import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
  25. import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
  26. import org.jxmpp.jid.Jid;

  27. /**
  28.  * Manager for HTTP ove XMPP transport (XEP-0332) extension.
  29.  *
  30.  * @author Andriy Tsykholyas
  31.  * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
  32.  */
  33. public class HOXTManager {

  34.     /**
  35.      * Namespace for this extension.
  36.      */
  37.     public static final String NAMESPACE = AbstractHttpOverXmpp.NAMESPACE;

  38.     static {
  39.         XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
  40.             @Override
  41.             public void connectionCreated(XMPPConnection connection) {
  42.                 ServiceDiscoveryManager.getInstanceFor(connection).addFeature(NAMESPACE);
  43.             }
  44.         });
  45.     }

  46.     /**
  47.      * Returns true if the given entity understands the HTTP ove XMPP transport format and allows the exchange of such.
  48.      *
  49.      * @param jid jid
  50.      * @param connection connection
  51.      * @return true if the given entity understands the HTTP ove XMPP transport format and exchange.
  52.      * @throws XMPPErrorException
  53.      * @throws NoResponseException
  54.      * @throws NotConnectedException
  55.      * @throws InterruptedException
  56.      */
  57.     public static boolean isSupported(Jid jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  58.         return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(jid, NAMESPACE);
  59.     }
  60. }