Java 类org.jivesoftware.smack.filter.PacketExtensionFilter 实例源码

项目:EIM    文件:MultiUserChat.java   
/**
 * Initializes the listeners to detect received room invitations and to detect when the
 * connection gets closed. As soon as a room invitation is received the invitations
 * listeners will be fired. When the connection gets closed the monitor will remove
 * his listeners on the connection.
 */
private void init() {
    // Listens for all messages that include a MUCUser extension and fire the invitation
    // listeners if the message includes an invitation.
    invitationFilter =
        new PacketExtensionFilter("x", "http://jabber.org/protocol/muc#user");
    invitationPacketListener = new PacketListener() {
        public void processPacket(Packet packet) {
            // Get the MUCUser extension
            MUCUser mucUser =
                (MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
            // Check if the MUCUser extension includes an invitation
            if (mucUser.getInvite() != null &&
                    ((Message) packet).getType() != Message.Type.error) {
                // Fire event for invitation listeners
                fireInvitationListeners(packet.getFrom(), mucUser.getInvite().getFrom(),
                        mucUser.getInvite().getReason(), mucUser.getPassword(), (Message) packet);
            }
        }
    };
    connection.addPacketListener(invitationPacketListener, invitationFilter);
    // Add a listener to detect when the connection gets closed in order to
    // cancel/release this monitor 
    connection.addConnectionListener(this);
}
项目:androidPN-client.    文件:MultiUserChat.java   
/**
 * Initializes the listeners to detect received room invitations and to detect when the
 * connection gets closed. As soon as a room invitation is received the invitations
 * listeners will be fired. When the connection gets closed the monitor will remove
 * his listeners on the connection.
 */
private void init() {
    // Listens for all messages that include a MUCUser extension and fire the invitation
    // listeners if the message includes an invitation.
    invitationFilter =
        new PacketExtensionFilter("x", "http://jabber.org/protocol/muc#user");
    invitationPacketListener = new PacketListener() {
        public void processPacket(Packet packet) {
            // Get the MUCUser extension
            MUCUser mucUser =
                (MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
            // Check if the MUCUser extension includes an invitation
            if (mucUser.getInvite() != null &&
                    ((Message) packet).getType() != Message.Type.error) {
                // Fire event for invitation listeners
                fireInvitationListeners(packet.getFrom(), mucUser.getInvite().getFrom(),
                        mucUser.getInvite().getReason(), mucUser.getPassword(), (Message) packet);
            }
        }
    };
    connection.addPacketListener(invitationPacketListener, invitationFilter);
    // Add a listener to detect when the connection gets closed in order to
    // cancel/release this monitor 
    connection.addConnectionListener(this);
}
项目:java-bells    文件:MultiUserChat.java   
/**
 * Initializes the listeners to detect received room invitations and to detect when the
 * connection gets closed. As soon as a room invitation is received the invitations
 * listeners will be fired. When the connection gets closed the monitor will remove
 * his listeners on the connection.
 */
private void init() {
    // Listens for all messages that include a MUCUser extension and fire the invitation
    // listeners if the message includes an invitation.
    invitationFilter =
        new PacketExtensionFilter("x", "http://jabber.org/protocol/muc#user");
    invitationPacketListener = new PacketListener() {
        public void processPacket(Packet packet) {
            // Get the MUCUser extension
            MUCUser mucUser =
                (MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
            // Check if the MUCUser extension includes an invitation
            if (mucUser.getInvite() != null &&
                    ((Message) packet).getType() != Message.Type.error) {
                // Fire event for invitation listeners
                fireInvitationListeners(packet.getFrom(), mucUser.getInvite().getFrom(),
                        mucUser.getInvite().getReason(), mucUser.getPassword(), (Message) packet);
            }
        }
    };
    connection.addPacketListener(invitationPacketListener, invitationFilter);
    // Add a listener to detect when the connection gets closed in order to
    // cancel/release this monitor 
    connection.addConnectionListener(this);
}
项目:telegraph    文件:MultiUserChat.java   
/**
 * Initializes the listeners to detect received room invitations and to detect when the
 * connection gets closed. As soon as a room invitation is received the invitations
 * listeners will be fired. When the connection gets closed the monitor will remove
 * his listeners on the connection.
 */
private void init() {
    // Listens for all messages that include a MUCUser extension and fire the invitation
    // listeners if the message includes an invitation.
    invitationFilter =
        new PacketExtensionFilter("x", "http://jabber.org/protocol/muc#user");
    invitationPacketListener = new PacketListener() {
        public void processPacket(Packet packet) {
            // Get the MUCUser extension
            MUCUser mucUser =
                (MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
            // Check if the MUCUser extension includes an invitation
            if (mucUser.getInvite() != null &&
                    ((Message) packet).getType() != Message.Type.error) {
                // Fire event for invitation listeners
                fireInvitationListeners(packet.getFrom(), mucUser.getInvite().getFrom(),
                        mucUser.getInvite().getReason(), mucUser.getPassword(), (Message) packet);
            }
        }
    };
    connection.addPacketListener(invitationPacketListener, invitationFilter);
    // Add a listener to detect when the connection gets closed in order to
    // cancel/release this monitor 
    connection.addConnectionListener(this);
}
项目:NewCommunication-Android    文件:MultiUserChat.java   
/**
 * Initializes the listeners to detect received room invitations and to detect when the
 * connection gets closed. As soon as a room invitation is received the invitations
 * listeners will be fired. When the connection gets closed the monitor will remove
 * his listeners on the connection.
 */
private void init() {
    // Listens for all messages that include a MUCUser extension and fire the invitation
    // listeners if the message includes an invitation.
    invitationFilter =
        new PacketExtensionFilter("x", "http://jabber.org/protocol/muc#user");
    invitationPacketListener = new PacketListener() {
        public void processPacket(Packet packet) {
            // Get the MUCUser extension
            MUCUser mucUser =
                (MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
            // Check if the MUCUser extension includes an invitation
            if (mucUser.getInvite() != null &&
                    ((Message) packet).getType() != Message.Type.error) {
                // Fire event for invitation listeners
                fireInvitationListeners(packet.getFrom(), mucUser.getInvite().getFrom(),
                        mucUser.getInvite().getReason(), mucUser.getPassword(), (Message) packet);
            }
        }
    };
    connection.addPacketListener(invitationPacketListener, invitationFilter);
    // Add a listener to detect when the connection gets closed in order to
    // cancel/release this monitor 
    connection.addConnectionListener(this);
}
项目:androidPN-client.    文件:DeliveryReceiptManager.java   
private DeliveryReceiptManager(Connection connection) {
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    sdm.addFeature(DeliveryReceipt.NAMESPACE);
    this.connection = connection;
    instances.put(connection, this);

    // register listener for delivery receipts and requests
    connection.addPacketListener(this, new PacketExtensionFilter(DeliveryReceipt.NAMESPACE));
}
项目:xmppsupport_v2    文件:MultiUserChat.java   
/**
 * Initializes the listeners to detect received room invitations and to
 * detect when the connection gets closed. As soon as a room invitation
 * is received the invitations listeners will be fired. When the
 * connection gets closed the monitor will remove his listeners on the
 * connection.
 */
private void init() {
    // Listens for all messages that include a MUCUser extension and
    // fire the invitation
    // listeners if the message includes an invitation.
    invitationFilter = new PacketExtensionFilter("x",
            "http://jabber.org/protocol/muc#user");
    invitationPacketListener = new PacketListener() {
        public void processPacket(Packet packet) {
            // Get the MUCUser extension
            MUCUser mucUser = (MUCUser) packet.getExtension("x",
                    "http://jabber.org/protocol/muc#user");
            // Check if the MUCUser extension includes an invitation
            if (mucUser.getInvite() != null
                    && ((Message) packet).getType() != Message.Type.error) {
                // Fire event for invitation listeners
                fireInvitationListeners(packet.getFrom(), mucUser
                        .getInvite().getFrom(), mucUser.getInvite()
                        .getReason(), mucUser.getPassword(),
                        (Message) packet);
            }
        }
    };
    connection.addPacketListener(invitationPacketListener,
            invitationFilter);
    // Add a listener to detect when the connection gets closed in order
    // to
    // cancel/release this monitor
    connection.addConnectionListener(this);
}
项目:java-bells    文件:DeliveryReceiptManager.java   
private DeliveryReceiptManager(Connection connection) {
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    sdm.addFeature(DeliveryReceipt.NAMESPACE);
    this.connection = connection;
    instances.put(connection, this);

    // register listener for delivery receipts and requests
    connection.addPacketListener(this, new PacketExtensionFilter(DeliveryReceipt.NAMESPACE));
}
项目:telegraph    文件:EntityCapsManager.java   
public void addPacketListener(Connection connection) {
    PacketFilter f =
        new AndFilter(
                new PacketTypeFilter(Presence.class),
                new PacketExtensionFilter(CapsExtension.NODE_NAME, CapsExtension.XMLNS));
    connection.addPacketListener(new CapsPacketListener(this), f);
}
项目:NewCommunication-Android    文件:EntityCapsManager.java   
public void addPacketListener(Connection connection) {
    PacketFilter f =
        new AndFilter(
                new PacketTypeFilter(Presence.class),
                new PacketExtensionFilter(CapsExtension.NODE_NAME, CapsExtension.XMLNS));
    connection.addPacketListener(new CapsPacketListener(), f);
}
项目:xmppsupport_v2    文件:EntityCapsManager.java   
public void addPacketListener(Connection connection) {
    PacketFilter f = new AndFilter(new PacketTypeFilter(Presence.class),
            new PacketExtensionFilter(CapsExtension.NODE_NAME,
                    CapsExtension.XMLNS));
    connection.addPacketListener(new CapsPacketListener(this), f);
}
项目:java-bells    文件:GroupChatInvitationTest.java   
protected void setUp() throws Exception {
    super.setUp();
    // Register listener for groupchat invitations.
    PacketFilter filter = new PacketExtensionFilter("x", "jabber:x:conference");
    collector = getConnection(1).createPacketCollector(filter);
}
项目:spark-svn-mirror    文件:ReversiPanel.java   
/**
 * Creates a new Reversi panel.
 *
 * @param connection Connection associated.
 * @param gameID Game ID number
 * @param startingPlayer Whether we are the starting player or not
 * @param opponentJID JID of opponent
 */
public ReversiPanel(XMPPConnection connection, final int gameID, boolean startingPlayer, String opponentJID) {
    this.connection = connection;
    this.gameID = gameID;
    this.opponentJID = opponentJID;
    otherPlayer = startingPlayer? ReversiModel.WHITE : ReversiModel.BLACK;

    // Load all images.

    // Start the game
    reversi = new ReversiModel();

    if (connection != null) {
        gameMoveListener = new PacketListener() {
            public void processPacket(Packet packet) {
                GameMove move = (GameMove)packet.getExtension(GameMove.ELEMENT_NAME, GameMove.NAMESPACE);
                // If this is a move for the current game.
                if (move.getGameID() == gameID) {
                    int position = move.getPosition();
                    // Make sure that the other player is allowed to make the move right now.
                    if (reversi.getCurrentPlayer() == otherPlayer && reversi.isValidMove(position)) {
                        reversi.makeMove(position);
                        // Redraw board.
                        ReversiPanel.this.repaint();
                    }
                    else {
                        // TODO: other user automatically forfeits!
                    }
                    // Execute move.
                }
            }
        };

        connection.addPacketListener(gameMoveListener, new PacketExtensionFilter(GameMove.ELEMENT_NAME,
                GameMove.NAMESPACE));
        // TODO: at end of game, remove listener.
    }

    setOpaque(false);

    // Use absolute layout
    setLayout(null);
    // Set its size:
    setPreferredSize(new Dimension(TOTAL_WIDTH, TOTAL_HEIGHT));

    // Make a new panel which is the game board grid:
    JPanel reversiBoard = new JPanel(new GridLayout(NUM_BLOCKS,NUM_BLOCKS,0,0));
    reversiBoard.setOpaque(false);
    for (int i=0; i<NUM_BLOCKS*NUM_BLOCKS; i++) {
        ReversiBlock block = new ReversiBlock(this, i);
        blocks.add(block);
        reversiBoard.add(block);
    }
    // Add the reversi board to the main panel:
    add(reversiBoard);
    // Position it:
    reversiBoard.setBounds(BORDER_SIZE, BORDER_SIZE, BOARD_SIZE, BOARD_SIZE);


    // TODO: listen for click on resign button!!
}
项目:spark-svn-mirror    文件:GUI.java   
public GUI(boolean imStarting, JFrame owner, XMPPConnection connection, int gameID) {
setLayout(new BorderLayout());
_owner = owner;
_connection = connection;
_gameID = gameID;
_gameboard = new GameBoard(imStarting);

_display = new Display();
_myfield = new GameboardGUI();
_theirfield = new GameboardGUI();

JPanel West = new JPanel(new BorderLayout(0, 5));
JPanel wnorth = new JPanel(new BorderLayout());
wnorth.add(new JLabel("Their Board"), BorderLayout.NORTH);
wnorth.add(_theirfield, BorderLayout.SOUTH);

JPanel wsouth = new JPanel(new BorderLayout());
wsouth.add(new JLabel("My Board"), BorderLayout.NORTH);
wsouth.add(_myfield);

JPanel East = new JPanel();
West.add(wsouth, BorderLayout.SOUTH);
West.add(wnorth, BorderLayout.NORTH);
East.add(_display);

add(East, BorderLayout.EAST);
add(West, BorderLayout.WEST);

_connection.addPacketListener(new PacketListener() {

    @Override
    public void processPacket(Packet packet) {

    MovePacket move = (MovePacket) packet.getExtension(
        MovePacket.ELEMENT_NAME, MovePacket.NAMESPACE);

    if (move.getGameID() == _gameID) {
        boolean opponentMadeHit = _gameboard.placeBomb(move.getPositionX(), move.getPositionY());

        if(opponentMadeHit)
        {
        Message m = createAnswer(move, packet.getFrom());
        _connection.sendPacket(m);
        }
    }

    }
}, new PacketExtensionFilter(MovePacket.ELEMENT_NAME,
    MovePacket.NAMESPACE));

// Start placing of the Ships
       _splistener = new ShipPlacementListener(_display, _gameboard, _myfield);
       _splistener.addObserver(this);

       _myfield.initiateShipPlacement(_splistener);

   }