Search in sources :

Example 1 with PacketListener

use of org.jivesoftware.smack.PacketListener in project ecf by eclipse.

the class Node method addItemEventListener.

/**
 * Register a listener for item publication events.  This
 * listener will get called whenever an item is published to
 * this node.
 *
 * @param listener The handler for the event
 */
public void addItemEventListener(ItemEventListener listener) {
    PacketListener conListener = new ItemEventTranslator(listener);
    itemEventToListenerMap.put(listener, conListener);
    con.addPacketListener(conListener, new EventContentFilter(EventElementType.items.toString(), "item"));
}
Also used : PacketListener(org.jivesoftware.smack.PacketListener)

Example 2 with PacketListener

use of org.jivesoftware.smack.PacketListener in project ecf by eclipse.

the class Node method addConfigurationListener.

/**
 * Register a listener for configuration events.  This listener
 * will get called whenever the node's configuration changes.
 *
 * @param listener The handler for the event
 */
public void addConfigurationListener(NodeConfigListener listener) {
    PacketListener conListener = new NodeConfigTranslator(listener);
    configEventToListenerMap.put(listener, conListener);
    con.addPacketListener(conListener, new EventContentFilter(EventElementType.configuration.toString()));
}
Also used : PacketListener(org.jivesoftware.smack.PacketListener)

Example 3 with PacketListener

use of org.jivesoftware.smack.PacketListener in project ecf by eclipse.

the class Node method addItemDeleteListener.

/**
 * Register an listener for item delete events.  This listener
 * gets called whenever an item is deleted from the node.
 *
 * @param listener The handler for the event
 */
public void addItemDeleteListener(ItemDeleteListener listener) {
    PacketListener delListener = new ItemDeleteTranslator(listener);
    itemDeleteToListenerMap.put(listener, delListener);
    EventContentFilter deleteItem = new EventContentFilter(EventElementType.items.toString(), "retract");
    EventContentFilter purge = new EventContentFilter(EventElementType.purge.toString());
    con.addPacketListener(delListener, new OrFilter(deleteItem, purge));
}
Also used : OrFilter(org.jivesoftware.smack.filter.OrFilter) PacketListener(org.jivesoftware.smack.PacketListener)

Example 4 with PacketListener

use of org.jivesoftware.smack.PacketListener in project ecf by eclipse.

the class EntityCapsManager method init.

private void init() {
    Connection connection = weakRefConnection.get();
    instances.put(connection, this);
    connection.addConnectionListener(new ConnectionListener() {

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

        public void connectionClosedOnError(Exception e) {
            presenceSend = false;
        }

        public void reconnectionFailed(Exception e) {
        // ignore
        }

        public void reconnectingIn(int seconds) {
        // ignore
        }

        public void reconnectionSuccessful() {
        // ignore
        }
    });
    // This calculates the local entity caps version
    updateLocalEntityCaps();
    if (SmackConfiguration.autoEnableEntityCaps())
        enableEntityCaps();
    PacketFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class), new PacketExtensionFilter(ELEMENT, NAMESPACE));
    connection.addPacketListener(new PacketListener() {

        // Listen for remote presence stanzas with the caps extension
        // If we receive such a stanza, record the JID and nodeVer
        public void processPacket(Packet packet) {
            if (!entityCapsEnabled())
                return;
            CapsExtension ext = (CapsExtension) packet.getExtension(EntityCapsManager.ELEMENT, EntityCapsManager.NAMESPACE);
            String hash = ext.getHash().toLowerCase();
            if (!SUPPORTED_HASHES.containsKey(hash))
                return;
            String from = packet.getFrom();
            String node = ext.getNode();
            String ver = ext.getVer();
            jidCaps.put(from, new NodeVerHash(node, ver, hash));
        }
    }, packetFilter);
    packetFilter = new AndFilter(new PacketTypeFilter(Presence.class), new NotFilter(new PacketExtensionFilter(ELEMENT, NAMESPACE)));
    connection.addPacketListener(new PacketListener() {

        public void processPacket(Packet packet) {
            // always remove the JID from the map, even if entityCaps are
            // disabled
            String from = packet.getFrom();
            jidCaps.remove(from);
        }
    }, packetFilter);
    packetFilter = new PacketTypeFilter(Presence.class);
    connection.addPacketSendingListener(new PacketListener() {

        public void processPacket(Packet packet) {
            presenceSend = true;
        }
    }, packetFilter);
    // Intercept presence packages and add caps data when intended.
    // XEP-0115 specifies that a client SHOULD include entity capabilities
    // with every presence notification it sends.
    PacketFilter capsPacketFilter = new PacketTypeFilter(Presence.class);
    PacketInterceptor packetInterceptor = new PacketInterceptor() {

        public void interceptPacket(Packet packet) {
            if (!entityCapsEnabled)
                return;
            CapsExtension caps = new CapsExtension(ENTITY_NODE, getCapsVersion(), "sha-1");
            packet.addExtension(caps);
        }
    };
    connection.addPacketInterceptor(packetInterceptor, capsPacketFilter);
    // It's important to do this as last action. Since it changes the
    // behavior of the SDM in some ways
    sdm.setEntityCapsManager(this);
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) Connection(org.jivesoftware.smack.Connection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) ConnectionListener(org.jivesoftware.smack.ConnectionListener) CapsExtension(org.jivesoftware.smackx.entitycaps.packet.CapsExtension) PacketListener(org.jivesoftware.smack.PacketListener) PacketInterceptor(org.jivesoftware.smack.PacketInterceptor) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XMPPException(org.jivesoftware.smack.XMPPException) AndFilter(org.jivesoftware.smack.filter.AndFilter) PacketExtensionFilter(org.jivesoftware.smack.filter.PacketExtensionFilter) NotFilter(org.jivesoftware.smack.filter.NotFilter) Presence(org.jivesoftware.smack.packet.Presence)

Example 5 with PacketListener

use of org.jivesoftware.smack.PacketListener in project ecf by eclipse.

the class FileTransferManager method initListeners.

private void initListeners() {
    listeners = new ArrayList<FileTransferListener>();
    connection.addPacketListener(new PacketListener() {

        public void processPacket(Packet packet) {
            fireNewRequest((StreamInitiation) packet);
        }
    }, new AndFilter(new PacketTypeFilter(StreamInitiation.class), new IQTypeFilter(IQ.Type.SET)));
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) StreamInitiation(org.jivesoftware.smackx.packet.StreamInitiation) AndFilter(org.jivesoftware.smack.filter.AndFilter) IQTypeFilter(org.jivesoftware.smack.filter.IQTypeFilter) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) PacketListener(org.jivesoftware.smack.PacketListener)

Aggregations

PacketListener (org.jivesoftware.smack.PacketListener)16 Packet (org.jivesoftware.smack.packet.Packet)12 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)5 Message (org.jivesoftware.smack.packet.Message)5 ConnectionListener (org.jivesoftware.smack.ConnectionListener)4 XMPPException (org.jivesoftware.smack.XMPPException)3 AndFilter (org.jivesoftware.smack.filter.AndFilter)3 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)3 IOException (java.io.IOException)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 Presence (org.jivesoftware.smack.packet.Presence)2 DatagramPacket (java.net.DatagramPacket)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 List (java.util.List)1 BadLocationException (javax.swing.text.BadLocationException)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1