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.XMPPConnection;
022import org.jivesoftware.smack.XMPPConnectionRegistry;
023import org.jivesoftware.smack.XMPPException.XMPPErrorException;
024import org.jivesoftware.smack.SmackException.NotConnectedException;
025import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
026import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
027import org.jxmpp.jid.Jid;
028
029/**
030 * Manager for HTTP ove XMPP transport (XEP-0332) extension.
031 *
032 * @author Andriy Tsykholyas
033 * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
034 */
035public class HOXTManager {
036
037    /**
038     * Namespace for this extension.
039     */
040    public static final String NAMESPACE = AbstractHttpOverXmpp.NAMESPACE;
041
042    static {
043        XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
044            @Override
045            public void connectionCreated(XMPPConnection connection) {
046                ServiceDiscoveryManager.getInstanceFor(connection).addFeature(NAMESPACE);
047            }
048        });
049    }
050
051    /**
052     * Returns true if the given entity understands the HTTP ove XMPP transport format and allows the exchange of such.
053     *
054     * @param jid jid
055     * @param connection connection
056     * @return true if the given entity understands the HTTP ove XMPP transport format and exchange.
057     * @throws XMPPErrorException
058     * @throws NoResponseException
059     * @throws NotConnectedException
060     * @throws InterruptedException 
061     */
062    public static boolean isSupported(Jid jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
063        return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(jid, NAMESPACE);
064    }
065}