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