From b3a4c76f1f6a1cfea88c2d813cf30c9a4d33127a Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Fri, 19 Dec 2003 18:00:16 +0000 Subject: [PATCH] Adds static init - Makes the XHTMLfeature available by default on every connection git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2183 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smackx/XHTMLManager.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/source/org/jivesoftware/smackx/XHTMLManager.java b/source/org/jivesoftware/smackx/XHTMLManager.java index 8654c081a..8af5f4fb8 100644 --- a/source/org/jivesoftware/smackx/XHTMLManager.java +++ b/source/org/jivesoftware/smackx/XHTMLManager.java @@ -54,11 +54,9 @@ package org.jivesoftware.smackx; import java.util.Iterator; -import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.*; import org.jivesoftware.smack.packet.Message; -import org.jivesoftware.smackx.packet.DiscoverInfo; -import org.jivesoftware.smackx.packet.XHTMLExtension; +import org.jivesoftware.smackx.packet.*; /** * Manages XHTML formatted texts within messages. A XHTMLManager provides a high level access to @@ -71,6 +69,16 @@ public class XHTMLManager { private final static String namespace = "http://jabber.org/protocol/xhtml-im"; + // Enable the XHTML support on every established connection + // The ServiceDiscoveryManager class should have been already initialized + static { + XMPPConnection.addConnectionListener(new ConnectionEstablishedListener() { + public void connectionEstablished(XMPPConnection connection) { + XHTMLManager.setServiceEnabled(connection, true); + } + }); + } + /** * Returns an Iterator for the XHTML bodies in the message. Returns null if * the message does not contain an XHTML extension. @@ -128,7 +136,8 @@ public class XHTMLManager { if (enabled) { ServiceDiscoveryManager.getInstanceFor(connection).addFeature(namespace); - } else { + } + else { ServiceDiscoveryManager.getInstanceFor(connection).removeFeature(namespace); } } @@ -155,7 +164,8 @@ public class XHTMLManager { DiscoverInfo result = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(userID); return result.containsFeature(namespace); - } catch (XMPPException e) { + } + catch (XMPPException e) { e.printStackTrace(); return false; }