use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class MultiUserChat method getJoinedRooms.
/**
* Returns an Iterator on the rooms where the requested user has joined. The Iterator will
* contain Strings where each String represents a room (e.g. room@muc.jabber.org).
*
* @param connection the connection to use to perform the service discovery.
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
* @return an Iterator on the rooms where the requested user has joined.
*/
public static Iterator<String> getJoinedRooms(Connection connection, String user) {
try {
ArrayList<String> answer = new ArrayList<String>();
// Send the disco packet to the user
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(user, discoNode);
// Collect the entityID for each returned item
for (Iterator<DiscoverItems.Item> items = result.getItems(); items.hasNext(); ) {
answer.add(items.next().getEntityID());
}
return answer.iterator();
} catch (XMPPException e) {
e.printStackTrace();
// Return an iterator on an empty collection
return new ArrayList<String>().iterator();
}
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class MultiUserChat method getServiceNames.
/**
* Returns a collection with the XMPP addresses of the Multi-User Chat services.
*
* @param connection the XMPP connection to use for discovering Multi-User Chat services.
* @return a collection with the XMPP addresses of the Multi-User Chat services.
* @throws XMPPException if an error occured while trying to discover MUC services.
*/
public static Collection<String> getServiceNames(Connection connection) throws XMPPException {
final List<String> answer = new ArrayList<String>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = discoManager.discoverItems(connection.getServiceName());
for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext(); ) {
DiscoverItems.Item item = it.next();
try {
DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
if (info.containsFeature("http://jabber.org/protocol/muc")) {
answer.add(item.getEntityID());
}
} catch (XMPPException e) {
// Trouble finding info in some cases. This is a workaround for
// discovering info on remote servers.
}
}
return answer;
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class LeafNode method discoverItems.
/**
* Get information on the items in the node in standard
* {@link DiscoverItems} format.
*
* @return The item details in {@link DiscoverItems} format
*
* @throws XMPPException
*/
public DiscoverItems discoverItems() throws XMPPException {
DiscoverItems items = new DiscoverItems();
items.setTo(to);
items.setNode(getId());
return (DiscoverItems) SyncPacketSend.getReply(con, items);
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project ecf by eclipse.
the class XMPPChatRoomManager method checkRoom.
/**
* check if the MultiUserChat room is already existing on the XMPP server.
*
* @param conference
* @param room
* the name of the room
* @return true, if the room exists, false otherwise
* @throws XMPPException
*/
protected boolean checkRoom(String conference, String room) throws XMPPException {
final XMPPConnection conn = ecfConnection.getXMPPConnection();
final ServiceDiscoveryManager serviceDiscoveryManager = new ServiceDiscoveryManager(conn);
final DiscoverItems result = serviceDiscoveryManager.discoverItems(conference);
for (final Iterator items = result.getItems(); items.hasNext(); ) {
final DiscoverItems.Item item = ((DiscoverItems.Item) items.next());
if (room.equals(item.getEntityID())) {
return true;
}
}
return false;
}
use of org.jivesoftware.smackx.packet.DiscoverItems in project Smack by igniterealtime.
the class AdHocCommandDiscoTest method testAdHocCommands.
public void testAdHocCommands() {
try {
AdHocCommandManager manager1 = AdHocCommandManager.getAddHocCommandsManager(getConnection(0));
manager1.registerCommand("test", "test node", LocalCommand.class);
manager1.registerCommand("test2", "test node", new LocalCommandFactory() {
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
return new LocalCommand() {
public boolean isLastStage() {
return true;
}
public boolean hasPermission(String jid) {
return true;
}
public void execute() throws XMPPException {
Form result = new Form(Form.TYPE_RESULT);
FormField resultField = new FormField("test2");
resultField.setLabel("test node");
resultField.addValue("it worked");
result.addField(resultField);
setForm(result);
}
public void next(Form response) throws XMPPException {
//
}
public void complete(Form response) throws XMPPException {
//
}
public void prev() throws XMPPException {
//
}
public void cancel() throws XMPPException {
//
}
};
}
});
AdHocCommandManager manager2 = AdHocCommandManager.getAddHocCommandsManager(getConnection(1));
DiscoverItems items = manager2.discoverCommands(getFullJID(0));
assertTrue("Disco for command test failed", items.getItems().next().getNode().equals("test"));
RemoteCommand command = manager2.getRemoteCommand(getFullJID(0), "test2");
command.execute();
assertEquals("Disco for command test failed", command.getForm().getField("test2").getValues().next(), "it worked");
} catch (Exception e) {
fail(e.getMessage());
}
}
Aggregations