曹妃甸核酸检测平台.apk(点击下载) / XHTMLManager.java


package asmack.org.jivesoftware.smackx;

import asmack.org.jivesoftware.smack.Connection;
import asmack.org.jivesoftware.smack.ConnectionCreationListener;
import asmack.org.jivesoftware.smack.XMPPException;
import asmack.org.jivesoftware.smack.packet.Message;
import asmack.org.jivesoftware.smackx.packet.XHTMLExtension;
import java.util.Iterator;

public class XHTMLManager {
    private static final String namespace = "http://jabber.org/protocol/xhtml-im";

    static {
        Connection.addConnectionCreationListener(new ConnectionCreationListener() {
            /* class asmack.org.jivesoftware.smackx.XHTMLManager.AnonymousClass1 */

            @Override // asmack.org.jivesoftware.smack.ConnectionCreationListener
            public void connectionCreated(Connection connection) {
                XHTMLManager.setServiceEnabled(connection, true);
            }
        });
    }

    public static void addBody(Message message, String str) {
        XHTMLExtension xHTMLExtension = (XHTMLExtension) message.getExtension("html", namespace);
        if (xHTMLExtension == null) {
            xHTMLExtension = new XHTMLExtension();
            message.addExtension(xHTMLExtension);
        }
        xHTMLExtension.addBody(str);
    }

    public static Iterator getBodies(Message message) {
        XHTMLExtension xHTMLExtension = (XHTMLExtension) message.getExtension("html", namespace);
        if (xHTMLExtension != null) {
            return xHTMLExtension.getBodies();
        }
        return null;
    }

    public static boolean isServiceEnabled(Connection connection) {
        return ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(namespace);
    }

    public static boolean isServiceEnabled(Connection connection, String str) {
        try {
            return ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(str).containsFeature(namespace);
        } catch (XMPPException e2) {
            e2.printStackTrace();
            return false;
        }
    }

    public static boolean isXHTMLMessage(Message message) {
        return message.getExtension("html", namespace) != null;
    }

    public static synchronized void setServiceEnabled(Connection connection, boolean z) {
        synchronized (XHTMLManager.class) {
            if (isServiceEnabled(connection) != z) {
                if (z) {
                    ServiceDiscoveryManager.getInstanceFor(connection).addFeature(namespace);
                } else {
                    ServiceDiscoveryManager.getInstanceFor(connection).removeFeature(namespace);
                }
            }
        }
    }
}