/** * Returns a collection of HostedRooms where each HostedRoom has the XMPP address of the room * and the room's name. Once discovered the rooms hosted by a chat service it is possible to * discover more detailed room information or join the room. * * @param connection the XMPP connection to use for discovering hosted rooms by the MUC service. * @param serviceName the service that is hosting the rooms to discover. * @return a collection of HostedRooms. * @throws XMPPException if an error occured while trying to discover the information. */ public static Collection<HostedRoom> getHostedRooms(Connection connection, String serviceName) throws XMPPException { List<HostedRoom> answer = new ArrayList<HostedRoom>(); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); DiscoverItems items = discoManager.discoverItems(serviceName); for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) { answer.add(new HostedRoom(it.next())); } return answer; }
/** * Returns an iterator on <tt>OfflineMessageHeader</tt> that keep information about the * offline message. The OfflineMessageHeader includes a stamp that could be used to retrieve * the complete message or delete the specific message. * * @return an iterator on <tt>OfflineMessageHeader</tt> that keep information about the offline * message. * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public Iterator<OfflineMessageHeader> getHeaders() throws XMPPException { List<OfflineMessageHeader> answer = new ArrayList<OfflineMessageHeader>(); DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems( null, namespace); for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) { DiscoverItems.Item item = it.next(); answer.add(new OfflineMessageHeader(item)); } return answer.iterator(); }
/** * Returns an iterator on <tt>OfflineMessageHeader</tt> that keep information about the * offline message. The OfflineMessageHeader includes a stamp that could be used to retrieve * the complete message or delete the specific message. * * @return an iterator on <tt>OfflineMessageHeader</tt> that keep information about the offline * message. * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public Iterator<OfflineMessageHeader> getHeaders() throws XMPPException { List<OfflineMessageHeader> answer = new ArrayList<OfflineMessageHeader>(); DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems( null, namespace); for (Iterator it = items.getItems(); it.hasNext();) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); answer.add(new OfflineMessageHeader(item)); } return answer.iterator(); }
/** * Returns an iterator on <tt>OfflineMessageHeader</tt> that keep information about the * offline message. The OfflineMessageHeader includes a stamp that could be used to retrieve * the complete message or delete the specific message. * * @return an iterator on <tt>OfflineMessageHeader</tt> that keep information about the offline * message. * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public Iterator<OfflineMessageHeader> getHeaders() throws XMPPException { List<OfflineMessageHeader> answer = new ArrayList<OfflineMessageHeader>(); DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems( null, namespace); for (Iterator it = items.getItems(); it.hasNext();) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); answer.add(new OfflineMessageHeader(item)); } return answer.iterator(); }
/** * Returns a collection of HostedRooms where each HostedRoom has the XMPP address of the room * and the room's name. Once discovered the rooms hosted by a chat service it is possible to * discover more detailed room information or join the room. * * @param connection the XMPP connection to use for discovering hosted rooms by the MUC service. * @param serviceName the service that is hosting the rooms to discover. * @return a collection of HostedRooms. * @throws XMPPException if an error occured while trying to discover the information. */ public static Collection<HostedRoom> getHostedRooms(Connection connection, String serviceName) throws XMPPException { List<HostedRoom> answer = new ArrayList<HostedRoom>(); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); DiscoverItems items = discoManager.discoverItems(serviceName); for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) { answer.add(new HostedRoom(it.next())); } return answer; }
/** * Returns a collection of HostedRooms where each HostedRoom has the XMPP address of the room * and the room's name. Once discovered the rooms hosted by a chat service it is possible to * discover more detailed room information or join the room. * * @param connection the XMPP connection to use for discovering hosted rooms by the MUC service. * @param serviceName the service that is hosting the rooms to discover. * @return a collection of HostedRooms. * @throws XMPPException if an error occured while trying to discover the information. */ public static Collection getHostedRooms(XMPPConnection connection, String serviceName) throws XMPPException { List answer = new ArrayList(); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); DiscoverItems items = discoManager.discoverItems(serviceName); for (Iterator it = items.getItems(); it.hasNext();) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); answer.add(new HostedRoom(item)); } return answer; }
/** * Returns an iterator on <tt>OfflineMessageHeader</tt> that keep information about the * offline message. The OfflineMessageHeader includes a stamp that could be used to retrieve * the complete message or delete the specific message. * * @return an iterator on <tt>OfflineMessageHeader</tt> that keep information about the offline * message. * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public Iterator getHeaders() throws XMPPException { List answer = new ArrayList(); DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems( null, namespace); for (Iterator it = items.getItems(); it.hasNext();) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); answer.add(new OfflineMessageHeader(item)); } return answer.iterator(); }
/** * Returns a collection of HostedRooms where each HostedRoom has the XMPP address of the room * and the room's name. Once discovered the rooms hosted by a chat service it is possible to * discover more detailed room information or join the room. * * @param connection the XMPP connection to use for discovering hosted rooms by the MUC service. * @param serviceName the service that is hosting the rooms to discover. * @return a collection of HostedRooms. * @throws XMPPException if an error occured while trying to discover the information. */ public static Collection<HostedRoom> getHostedRooms(Connection connection, String serviceName) throws XMPPException { List<HostedRoom> answer = new ArrayList<HostedRoom>(); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); DiscoverItems items = discoManager.discoverItems(serviceName); for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext();) { answer.add(new HostedRoom(it.next())); } return answer; }
/** * 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(); } }
/** * Loads all gateways the users server offers * @throws XMPPException */ private void loadLocalGateways() throws XMPPException{ DiscoverItems items = sdManager.discoverItems(connection.getHost()); Iterator<Item> iter = items.getItems(); while(iter.hasNext()){ String itemJID = iter.next().getEntityID(); discoverGateway(itemJID); } }
/** * 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 getJoinedRooms(XMPPConnection connection, String user) { try { ArrayList answer = new ArrayList(); // Send the disco packet to the user DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(user, discoNode); // Collect the entityID for each returned item for (Iterator items=result.getItems(); items.hasNext();) { answer.add(((DiscoverItems.Item)items.next()).getEntityID()); } return answer.iterator(); } catch (XMPPException e) { e.printStackTrace(); // Return an iterator on an empty collection return new ArrayList().iterator(); } }
/** * 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(); } }
/** * 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(); } }
private void initProxies() { proxies = new ArrayList<String>(); ServiceDiscoveryManager manager = ServiceDiscoveryManager .getInstanceFor(connection); try { DiscoverItems discoItems = manager.discoverItems(connection.getServiceName()); Iterator it = discoItems.getItems(); while (it.hasNext()) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); String proxy = checkIsProxy(manager, item); if (proxy != null) { proxies.add(proxy); } } } catch (XMPPException e) { return; } if (proxies.size() > 0) { initStreamHosts(); } }
/** * 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; }
/** * 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; }
/** * 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 getServiceNames(XMPPConnection connection) throws XMPPException { final List answer = new ArrayList(); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); DiscoverItems items = discoManager.discoverItems(connection.getServiceName()); for (Iterator it = items.getItems(); it.hasNext();) { DiscoverItems.Item item = (DiscoverItems.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; }
/** * Returns a collection of search services found on the server. * * @return a Collection of search services found on the server. * @throws XMPPException thrown if a server error has occurred. */ public Collection getSearchServices() throws XMPPException { List searchServices = new ArrayList(); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con); DiscoverItems items = discoManager.discoverItems(con.getServiceName()); for (Iterator it = items.getItems(); it.hasNext();) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); try { DiscoverInfo info = discoManager.discoverInfo(item.getEntityID()); if (info.containsFeature("jabber:iq:search")) { searchServices.add(item.getEntityID()); } } catch (XMPPException e) { // No info found. break; } } return searchServices; } }
/** * 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; }
/** * Delete all nodes */ public synchronized void deleteAllNodes() { if ((xmppCon == null) || (!xmppCon.isConnected())) login(); try { DiscoverItems dItems = manager.discoverNodes(null); Iterator<DiscoverItems.Item> iItems = dItems.getItems(); while(iItems.hasNext()) { DiscoverItems.Item it = iItems.next(); logger.debug("Deleting node " + it.getNode()); try { Node n = manager.getNode(it.getNode()); if ((n != null) && (n instanceof LeafNode)){ LeafNode ln = (LeafNode)n; ln.deleteAllItems(); } else logger.info("Unable to delete items of node " + it.getNode()); manager.deleteNode(it.getNode()); } catch (XMPPException e) { logger.error("Error deleting node: " + e); } } } catch (XMPPException e) { logger.error("Error deleting nodes: " + e); } }