1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-30 15:16:42 +02:00

Added disco support

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2142 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2003-10-13 23:10:15 +00:00 committed by gdombiak
parent 420ce10ed9
commit 943497731f
2 changed files with 69 additions and 5 deletions

View file

@ -44,4 +44,18 @@
<className>org.jivesoftware.smackx.GroupChatInvitation$Provider</className> <className>org.jivesoftware.smackx.GroupChatInvitation$Provider</className>
</extensionProvider> </extensionProvider>
<!-- Service Discovery # Items -->
<iqProvider>
<elementName>query</elementName>
<namespace>http://jabber.org/protocol/disco#items</namespace>
<className>org.jivesoftware.smackx.provider.DiscoverItemsProvider</className>
</iqProvider>
<!-- Service Discovery # Info -->
<iqProvider>
<elementName>query</elementName>
<namespace>http://jabber.org/protocol/disco#info</namespace>
<className>org.jivesoftware.smackx.provider.DiscoverInfoProvider</className>
</iqProvider>
</smackProviders> </smackProviders>

View file

@ -54,7 +54,10 @@ package org.jivesoftware.smackx;
import java.util.Iterator; import java.util.Iterator;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.XHTMLExtension; import org.jivesoftware.smackx.packet.XHTMLExtension;
/** /**
@ -66,6 +69,8 @@ import org.jivesoftware.smackx.packet.XHTMLExtension;
*/ */
public class XHTMLManager { public class XHTMLManager {
private final static String namespace = "http://jabber.org/protocol/xhtml-im";
/** /**
* Returns an Iterator for the XHTML bodies in the message. Returns null if * Returns an Iterator for the XHTML bodies in the message. Returns null if
* the message does not contain an XHTML extension. * the message does not contain an XHTML extension.
@ -74,8 +79,7 @@ public class XHTMLManager {
* @return an Iterator for the bodies in the message or null if none. * @return an Iterator for the bodies in the message or null if none.
*/ */
public static Iterator getBodies(Message message) { public static Iterator getBodies(Message message) {
XHTMLExtension xhtmlExtension = XHTMLExtension xhtmlExtension = (XHTMLExtension) message.getExtension("html", namespace);
(XHTMLExtension) message.getExtension("html", "http://jabber.org/protocol/xhtml-im");
if (xhtmlExtension != null) if (xhtmlExtension != null)
return xhtmlExtension.getBodies(); return xhtmlExtension.getBodies();
else else
@ -89,8 +93,7 @@ public class XHTMLManager {
* @param body the string to add as an XHTML body to the message * @param body the string to add as an XHTML body to the message
*/ */
public static void addBody(Message message, String body) { public static void addBody(Message message, String body) {
XHTMLExtension xhtmlExtension = XHTMLExtension xhtmlExtension = (XHTMLExtension) message.getExtension("html", namespace);
(XHTMLExtension) message.getExtension("html", "http://jabber.org/protocol/xhtml-im");
if (xhtmlExtension == null) { if (xhtmlExtension == null) {
// Create an XHTMLExtension and add it to the message // Create an XHTMLExtension and add it to the message
xhtmlExtension = new XHTMLExtension(); xhtmlExtension = new XHTMLExtension();
@ -107,7 +110,54 @@ public class XHTMLManager {
* @return a boolean indicating whether the message is an XHTML message * @return a boolean indicating whether the message is an XHTML message
*/ */
public static boolean isXHTMLMessage(Message message) { public static boolean isXHTMLMessage(Message message) {
return message.getExtension("html", "http://jabber.org/protocol/xhtml-im") != null; return message.getExtension("html", namespace) != null;
} }
/**
* Enables or disables the XHTML support on a given connection.<p>
*
* Before starting to send XHTML messages to a user, check that the user can handle XHTML
* messages. Enable the XHTML support to indicate that this client handles XHTML messages.
*
* @param connection the connection where the service will be enabled or disabled
* @param enabled indicates if the service will be enabled or disabled
*/
public synchronized static void setServiceEnabled(XMPPConnection connection, boolean enabled) {
if (isServiceEnabled(connection) == enabled)
return;
if (enabled) {
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(namespace);
} else {
ServiceDiscoveryManager.getInstanceFor(connection).removeFeature(namespace);
}
}
/**
* Returns true if the XHTML support is enabled for the given connection.
*
* @param connection the connection to look for XHTML support
* @return a boolean indicating if the XHTML support is enabled for the given connection
*/
public static boolean isServiceEnabled(XMPPConnection connection) {
return ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(namespace);
}
/**
* Returns true if the specified user handles XHTML messages.
*
* @param connection the connection to use to perform the service discovery
* @param userID the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com
* @return a boolean indicating whether the specified user handles XHTML messages
*/
public static boolean isServiceEnabled(XMPPConnection connection, String userID) {
try {
DiscoverInfo result =
ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(userID);
return result.containsFeature(namespace);
} catch (XMPPException e) {
e.printStackTrace();
return false;
}
}
} }