001/**
002 *
003 * Copyright 2014 Andriy Tsykholyas
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.hoxt;
018
019import org.jivesoftware.smack.ConnectionCreationListener;
020import org.jivesoftware.smack.SmackException.NoResponseException;
021import org.jivesoftware.smack.SmackException.NotConnectedException;
022import org.jivesoftware.smack.XMPPConnection;
023import org.jivesoftware.smack.XMPPConnectionRegistry;
024import org.jivesoftware.smack.XMPPException.XMPPErrorException;
025
026import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
027import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
028
029import org.jxmpp.jid.Jid;
030
031/**
032 * Manager for HTTP ove XMPP transport (XEP-0332) extension.
033 *
034 * @author Andriy Tsykholyas
035 * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
036 */
037public class HOXTManager {
038
039    /**
040     * Namespace for this extension.
041     */
042    public static final String NAMESPACE = AbstractHttpOverXmpp.NAMESPACE;
043
044    static {
045        XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
046            @Override
047            public void connectionCreated(XMPPConnection connection) {
048                ServiceDiscoveryManager.getInstanceFor(connection).addFeature(NAMESPACE);
049            }
050        });
051    }
052
053    /**
054     * Returns true if the given entity understands the HTTP ove XMPP transport format and allows the exchange of such.
055     *
056     * @param jid jid
057     * @param connection connection
058     * @return true if the given entity understands the HTTP ove XMPP transport format and exchange.
059     * @throws XMPPErrorException
060     * @throws NoResponseException
061     * @throws NotConnectedException
062     * @throws InterruptedException
063     */
064    public static boolean isSupported(Jid jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
065        return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(jid, NAMESPACE);
066    }
067}