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