Search in sources :

Example 1 with NodeInformationProvider

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

the class EntityCapsManager method updateLocalEntityCaps.

/**
 * Updates the local user Entity Caps information with the data provided
 *
 * If we are connected and there was already a presence send, another
 * presence is send to inform others about your new Entity Caps node string.
 *
 * @param discoverInfo
 *            the local users discover info (mostly the service discovery
 *            features)
 * @param identityType
 *            the local users identity type
 * @param identityName
 *            the local users identity name
 * @param extendedInfo
 *            the local users extended info
 */
public void updateLocalEntityCaps() {
    Connection connection = weakRefConnection.get();
    DiscoverInfo discoverInfo = new DiscoverInfo();
    discoverInfo.setType(IQ.Type.RESULT);
    discoverInfo.setNode(getLocalNodeVer());
    if (connection != null)
        discoverInfo.setFrom(connection.getUser());
    sdm.addDiscoverInfoTo(discoverInfo);
    currentCapsVersion = generateVerificationString(discoverInfo, "sha-1");
    addDiscoverInfoByNode(ENTITY_NODE + '#' + currentCapsVersion, discoverInfo);
    if (lastLocalCapsVersions.size() > 10) {
        String oldCapsVersion = lastLocalCapsVersions.poll();
        sdm.removeNodeInformationProvider(ENTITY_NODE + '#' + oldCapsVersion);
    }
    lastLocalCapsVersions.add(currentCapsVersion);
    caps.put(currentCapsVersion, discoverInfo);
    if (connection != null)
        jidCaps.put(connection.getUser(), new NodeVerHash(ENTITY_NODE, currentCapsVersion, "sha-1"));
    sdm.setNodeInformationProvider(ENTITY_NODE + '#' + currentCapsVersion, new NodeInformationProvider() {

        List<String> features = sdm.getFeaturesList();

        List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getIdentities());

        List<PacketExtension> packetExtensions = sdm.getExtendedInfoAsList();

        public List<Item> getNodeItems() {
            return null;
        }

        public List<String> getNodeFeatures() {
            return features;
        }

        public List<Identity> getNodeIdentities() {
            return identities;
        }

        public List<PacketExtension> getNodePacketExtensions() {
            return packetExtensions;
        }
    });
    // to respect ConnectionConfiguration.isSendPresence()
    if (connection != null && connection.isAuthenticated() && presenceSend) {
        Presence presence = new Presence(Presence.Type.available);
        connection.sendPacket(presence);
    }
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) NodeInformationProvider(org.jivesoftware.smackx.NodeInformationProvider) Connection(org.jivesoftware.smack.Connection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) LinkedList(java.util.LinkedList) Presence(org.jivesoftware.smack.packet.Presence) LinkedList(java.util.LinkedList) List(java.util.List) Identity(org.jivesoftware.smackx.packet.DiscoverInfo.Identity)

Example 2 with NodeInformationProvider

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

the class AdHocCommandManager method registerCommand.

/**
 * Registers a new command with this command manager, which is related to a
 * connection. The <tt>node</tt> is an unique identifier of that
 * command for the connection related to this command manager. The <tt>name</tt>
 * is the human readeale name of the command. The <tt>factory</tt> generates
 * new instances of the command.
 *
 * @param node the unique identifier of the command.
 * @param name the human readable name of the command.
 * @param factory a factory to create new instances of the command.
 */
public void registerCommand(String node, final String name, LocalCommandFactory factory) {
    AdHocCommandInfo commandInfo = new AdHocCommandInfo(node, name, connection.getUser(), factory);
    commands.put(node, commandInfo);
    // Set the NodeInformationProvider that will provide information about
    // the added command
    ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(node, new NodeInformationProvider() {

        public List<DiscoverItems.Item> getNodeItems() {
            return null;
        }

        public List<String> getNodeFeatures() {
            List<String> answer = new ArrayList<String>();
            answer.add(DISCO_NAMESPACE);
            // TODO: check if this service is provided by the
            // TODO: current connection.
            answer.add("jabber:x:data");
            return answer;
        }

        public List<DiscoverInfo.Identity> getNodeIdentities() {
            List<DiscoverInfo.Identity> answer = new ArrayList<DiscoverInfo.Identity>();
            DiscoverInfo.Identity identity = new DiscoverInfo.Identity("automation", name, "command-node");
            answer.add(identity);
            return answer;
        }

        public List<PacketExtension> getNodePacketExtensions() {
            return null;
        }
    });
}
Also used : DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) NodeInformationProvider(org.jivesoftware.smackx.NodeInformationProvider) Identity(org.jivesoftware.smackx.packet.DiscoverInfo.Identity) ArrayList(java.util.ArrayList) List(java.util.List) DiscoverItems(org.jivesoftware.smackx.packet.DiscoverItems) Identity(org.jivesoftware.smackx.packet.DiscoverInfo.Identity)

Example 3 with NodeInformationProvider

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

the class AdHocCommandManager method init.

/**
 * <ul>
 * <li>Adds listeners to the connection</li>
 * <li>Registers the ad-hoc command feature to the ServiceDiscoveryManager</li>
 * <li>Registers the items of the feature</li>
 * <li>Adds packet listeners to handle execution requests</li>
 * <li>Creates and start the session sweeper</li>
 * </ul>
 */
private void init() {
    // Register the new instance and associate it with the connection
    instances.put(connection, this);
    // Add a listener to the connection that removes the registered instance
    // when the connection is closed
    connection.addConnectionListener(new ConnectionListener() {

        public void connectionClosed() {
            // Unregister this instance since the connection has been closed
            instances.remove(connection);
        }

        public void connectionClosedOnError(Exception e) {
            // Unregister this instance since the connection has been closed
            instances.remove(connection);
        }

        public void reconnectionSuccessful() {
            // Register this instance since the connection has been
            // reestablished
            instances.put(connection, AdHocCommandManager.this);
        }

        public void reconnectingIn(int seconds) {
        // Nothing to do
        }

        public void reconnectionFailed(Exception e) {
        // Nothing to do
        }
    });
    // Add the feature to the service discovery manage to show that this
    // connection supports the AdHoc-Commands protocol.
    // This information will be used when another client tries to
    // discover whether this client supports AdHoc-Commands or not.
    ServiceDiscoveryManager.getInstanceFor(connection).addFeature(DISCO_NAMESPACE);
    // Set the NodeInformationProvider that will provide information about
    // which AdHoc-Commands are registered, whenever a disco request is
    // received
    ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(discoNode, new NodeInformationProvider() {

        public List<DiscoverItems.Item> getNodeItems() {
            List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>();
            Collection<AdHocCommandInfo> commandsList = getRegisteredCommands();
            for (AdHocCommandInfo info : commandsList) {
                DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID());
                item.setName(info.getName());
                item.setNode(info.getNode());
                answer.add(item);
            }
            return answer;
        }

        public List<String> getNodeFeatures() {
            return null;
        }

        public List<Identity> getNodeIdentities() {
            return null;
        }

        public List<PacketExtension> getNodePacketExtensions() {
            return null;
        }
    });
    // The packet listener and the filter for processing some AdHoc Commands
    // Packets
    PacketListener listener = new PacketListener() {

        public void processPacket(Packet packet) {
            AdHocCommandData requestData = (AdHocCommandData) packet;
            processAdHocCommand(requestData);
        }
    };
    PacketFilter filter = new PacketTypeFilter(AdHocCommandData.class);
    connection.addPacketListener(listener, filter);
    sessionsSweeper = null;
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) NodeInformationProvider(org.jivesoftware.smackx.NodeInformationProvider) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) DiscoverItems(org.jivesoftware.smackx.packet.DiscoverItems) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) AdHocCommandData(org.jivesoftware.smackx.packet.AdHocCommandData) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

List (java.util.List)3 NodeInformationProvider (org.jivesoftware.smackx.NodeInformationProvider)3 ArrayList (java.util.ArrayList)2 DiscoverInfo (org.jivesoftware.smackx.packet.DiscoverInfo)2 Identity (org.jivesoftware.smackx.packet.DiscoverInfo.Identity)2 DiscoverItems (org.jivesoftware.smackx.packet.DiscoverItems)2 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 Connection (org.jivesoftware.smack.Connection)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)1 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)1 Packet (org.jivesoftware.smack.packet.Packet)1 PacketExtension (org.jivesoftware.smack.packet.PacketExtension)1 Presence (org.jivesoftware.smack.packet.Presence)1 AdHocCommandData (org.jivesoftware.smackx.packet.AdHocCommandData)1