Search in sources :

Example 6 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.ServiceDiscoveryManager in project ecf by eclipse.

the class AdHocCommandManager method publishCommands.

/**
 * Publish the commands to an specific JID.
 *
 * @param jid the full JID to publish the commands to.
 * @throws XMPPException if the operation failed for some reason.
 */
public void publishCommands(String jid) throws XMPPException {
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    // Collects the commands to publish as items
    DiscoverItems discoverItems = new DiscoverItems();
    Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands();
    for (AdHocCommandInfo info : xCommandsList) {
        DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID());
        item.setName(info.getName());
        item.setNode(info.getNode());
        discoverItems.addItem(item);
    }
    serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems);
}
Also used : DiscoverItems(org.jivesoftware.smackx.packet.DiscoverItems) ServiceDiscoveryManager(org.jivesoftware.smackx.ServiceDiscoveryManager)

Example 7 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.ServiceDiscoveryManager 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;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.packet.DiscoverItems) XMPPException(org.jivesoftware.smack.XMPPException) ServiceDiscoveryManager(org.jivesoftware.smackx.ServiceDiscoveryManager)

Example 8 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.ServiceDiscoveryManager in project ecf by eclipse.

the class Socks5BytestreamManager method disableService.

/**
 * Disables the SOCKS5 Bytestream manager by removing the SOCKS5 Bytestream feature from the
 * service discovery, disabling the listener for SOCKS5 Bytestream initiation requests and
 * resetting its internal state.
 * <p>
 * To re-enable the SOCKS5 Bytestream feature invoke {@link #getBytestreamManager(Connection)}.
 * Using the file transfer API will automatically re-enable the SOCKS5 Bytestream feature.
 */
public synchronized void disableService() {
    // remove initiation packet listener
    this.connection.removePacketListener(this.initiationListener);
    // shutdown threads
    this.initiationListener.shutdown();
    // clear listeners
    this.allRequestListeners.clear();
    this.userListeners.clear();
    // reset internal state
    this.lastWorkingProxy = null;
    this.proxyBlacklist.clear();
    this.ignoredBytestreamRequests.clear();
    // remove manager from static managers map
    managers.remove(this.connection);
    // shutdown local SOCKS5 proxy if there are no more managers for other connections
    if (managers.size() == 0) {
        Socks5Proxy.getSocks5Proxy().stop();
    }
    // remove feature from service discovery
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection);
    // check if service discovery is not already disposed by connection shutdown
    if (serviceDiscoveryManager != null) {
        serviceDiscoveryManager.removeFeature(NAMESPACE);
    }
}
Also used : ServiceDiscoveryManager(org.jivesoftware.smackx.ServiceDiscoveryManager)

Example 9 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.ServiceDiscoveryManager in project ecf by eclipse.

the class Socks5BytestreamManager method supportsSocks5.

/**
 * Returns <code>true</code> if the given target JID supports feature SOCKS5 Bytestream.
 *
 * @param targetJID the target JID
 * @return <code>true</code> if the given target JID supports feature SOCKS5 Bytestream
 *         otherwise <code>false</code>
 * @throws XMPPException if there was an error querying target for supported features
 */
private boolean supportsSocks5(String targetJID) throws XMPPException {
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection);
    DiscoverInfo discoverInfo = serviceDiscoveryManager.discoverInfo(targetJID);
    return discoverInfo.containsFeature(NAMESPACE);
}
Also used : DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) ServiceDiscoveryManager(org.jivesoftware.smackx.ServiceDiscoveryManager)

Example 10 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.ServiceDiscoveryManager in project ecf by eclipse.

the class Workgroup method isEmailAvailable.

/**
 * The workgroup service may be configured to send email. This queries the Workgroup Service
 * to see if the email service has been configured and is available.
 *
 * @return true if the email service is available, otherwise return false.
 */
public boolean isEmailAvailable() {
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
    try {
        String workgroupService = StringUtils.parseServer(workgroupJID);
        DiscoverInfo infoResult = discoManager.discoverInfo(workgroupService);
        return infoResult.containsFeature("jive:email:provider");
    } catch (XMPPException e) {
        return false;
    }
}
Also used : DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) ServiceDiscoveryManager(org.jivesoftware.smackx.ServiceDiscoveryManager)

Aggregations

ServiceDiscoveryManager (org.jivesoftware.smackx.ServiceDiscoveryManager)11 ArrayList (java.util.ArrayList)6 DiscoverItems (org.jivesoftware.smackx.packet.DiscoverItems)6 DiscoverInfo (org.jivesoftware.smackx.packet.DiscoverInfo)5 XMPPException (org.jivesoftware.smack.XMPPException)3 Iterator (java.util.Iterator)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 Identity (org.jivesoftware.smackx.packet.DiscoverInfo.Identity)1 Item (org.jivesoftware.smackx.packet.DiscoverItems.Item)1