Search in sources :

Example 16 with DiscoverInfo

use of org.jivesoftware.smackx.packet.DiscoverInfo in project ecf by eclipse.

the class ServiceDiscoveryManager method discoverInfo.

/**
 * Returns the discovered information of a given XMPP entity addressed by its JID and
 * note attribute. Use this message only when trying to query information which is not
 * directly addressable.
 *
 * @see <a href="http://xmpp.org/extensions/xep-0030.html#info-basic">XEP-30 Basic Protocol</a>
 * @see <a href="http://xmpp.org/extensions/xep-0030.html#info-nodes">XEP-30 Info Nodes</a>
 *
 * @param entityID the address of the XMPP entity.
 * @param node the optional attribute that supplements the 'jid' attribute.
 * @return the discovered information.
 * @throws XMPPException if the operation failed for some reason.
 */
public DiscoverInfo discoverInfo(String entityID, String node) throws XMPPException {
    // Discover the entity's info
    DiscoverInfo disco = new DiscoverInfo();
    disco.setType(IQ.Type.GET);
    disco.setTo(entityID);
    disco.setNode(node);
    // Create a packet collector to listen for a response.
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(disco.getPacketID()));
    connection.sendPacket(disco);
    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from the server.");
    }
    if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return (DiscoverInfo) result;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) IQ(org.jivesoftware.smack.packet.IQ) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 17 with DiscoverInfo

use of org.jivesoftware.smackx.packet.DiscoverInfo in project ecf by eclipse.

the class DiscoverInfoProvider method parseIQ.

public IQ parseIQ(XmlPullParser parser) throws Exception {
    DiscoverInfo discoverInfo = new DiscoverInfo();
    boolean done = false;
    DiscoverInfo.Feature feature = null;
    DiscoverInfo.Identity identity = null;
    String category = "";
    String name = "";
    String type = "";
    String variable = "";
    String lang = "";
    discoverInfo.setNode(parser.getAttributeValue("", "node"));
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("identity")) {
                // Initialize the variables from the parsed XML
                category = parser.getAttributeValue("", "category");
                name = parser.getAttributeValue("", "name");
                type = parser.getAttributeValue("", "type");
                lang = parser.getAttributeValue(parser.getNamespace("xml"), "lang");
            } else if (parser.getName().equals("feature")) {
                // Initialize the variables from the parsed XML
                variable = parser.getAttributeValue("", "var");
            } else // Otherwise, it must be a packet extension.
            {
                discoverInfo.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("identity")) {
                // Create a new identity and add it to the discovered info.
                identity = new DiscoverInfo.Identity(category, name, type);
                if (lang != null)
                    identity.setLanguage(lang);
                discoverInfo.addIdentity(identity);
            }
            if (parser.getName().equals("feature")) {
                // Create a new feature and add it to the discovered info.
                discoverInfo.addFeature(variable);
            }
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    return discoverInfo;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo)

Example 18 with DiscoverInfo

use of org.jivesoftware.smackx.packet.DiscoverInfo in project ecf by eclipse.

the class Node method discoverInfo.

/**
 * Discover node information in standard {@link DiscoverInfo} format.
 *
 * @return The discovery information about the node.
 *
 * @throws XMPPException
 */
public DiscoverInfo discoverInfo() throws XMPPException {
    DiscoverInfo info = new DiscoverInfo();
    info.setTo(to);
    info.setNode(getId());
    return (DiscoverInfo) SyncPacketSend.getReply(con, info);
}
Also used : DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo)

Example 19 with DiscoverInfo

use of org.jivesoftware.smackx.packet.DiscoverInfo in project ecf by eclipse.

the class PubSubManager method getNode.

/**
 * Retrieves the requested node, if it exists.  It will throw an
 * exception if it does not.
 *
 * @param id - The unique id of the node
 * @return the node
 * @throws XMPPException The node does not exist
 */
public <T extends Node> T getNode(String id) throws XMPPException {
    Node node = nodeMap.get(id);
    if (node == null) {
        DiscoverInfo info = new DiscoverInfo();
        info.setTo(to);
        info.setNode(id);
        DiscoverInfo infoReply = (DiscoverInfo) SyncPacketSend.getReply(con, info);
        if (infoReply.getIdentities().next().getType().equals(NodeType.leaf.toString()))
            node = new LeafNode(con, id);
        else
            node = new CollectionNode(con, id);
        node.setTo(to);
        nodeMap.put(id, node);
    }
    return (T) node;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo)

Example 20 with DiscoverInfo

use of org.jivesoftware.smackx.packet.DiscoverInfo 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

DiscoverInfo (org.jivesoftware.smackx.packet.DiscoverInfo)20 XMPPException (org.jivesoftware.smack.XMPPException)6 ServiceDiscoveryManager (org.jivesoftware.smackx.ServiceDiscoveryManager)5 Identity (org.jivesoftware.smackx.packet.DiscoverInfo.Identity)5 DiscoverItems (org.jivesoftware.smackx.packet.DiscoverItems)5 ArrayList (java.util.ArrayList)3 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 MessageDigest (java.security.MessageDigest)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 Connection (org.jivesoftware.smack.Connection)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)1 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)1