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

项目:jabbot    文件:XmppBinding.java   
/**
 * Initialize PacketListener for a given {@link org.jivesoftware.smack.XMPPConnection}
 * and a Command prefix
 *
 * @param prefix the command prefix used to filter message
 * @param connection the connection on which PacketListener will be registered
 */
private void initListeners(final String prefix, final XMPPConnection connection){
       StanzaFilter filter = new AndFilter(
            new OrFilter(MessageTypeFilter.GROUPCHAT,MessageTypeFilter.CHAT),
            new StanzaFilter() {
                @Override
                public boolean accept(Stanza stanza) {
                    return stanza instanceof Message && ((Message) stanza).getBody().startsWith(prefix);
                }
            }
    );

    XmppMessageListener commandListener = new XmppMessageListener(this,listeners);
    connection.addAsyncStanzaListener(commandListener,filter);
    MultiUserChatManager.getInstanceFor(connection).addInvitationListener(new InvitationListener(this,listeners));
}
项目:msf-spaces-sdk-android    文件:SpaceHandler.java   
/**
 * Called when the mode provided by the connection is changed to online or the user sets the mode to online.
 * If Handler is in onlinemode some preparations are done like checking and perhaps retrieving the spaces service adress.
 */
private void prepareOnlineMode(){
    if (getMode() == Mode.ONLINE){
        if (domain == null){
            domain = userInfo.getDomain();
        }
        if (connectionHandler.getNetworkInformation().getSpacesServiceJID() != null) {
            this.connection.removePacketListener(packetListener);
            AndFilter andFilter = new AndFilter();
            OrFilter orFilter = new OrFilter();
            orFilter.addFilter(new IQTypeFilter(IQ.Type.ERROR));
            orFilter.addFilter(new IQTypeFilter(IQ.Type.RESULT));
            andFilter.addFilter(orFilter);
            andFilter.addFilter(new FromContainsFilter(connectionHandler.getNetworkInformation().getSpacesServiceJID()));
            this.connection.addPacketListener(packetListener, andFilter);
        }
    }
}
项目:Smack    文件:Node.java   
/**
 * 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)
{
    StanzaListener delListener = new ItemDeleteTranslator(listener); 
    itemDeleteToListenerMap.put(listener, delListener);
    EventContentFilter deleteItem = new EventContentFilter(EventElementType.items.toString(), "retract");
    EventContentFilter purge = new EventContentFilter(EventElementType.purge.toString());

    con.addSyncStanzaListener(delListener, new OrFilter(deleteItem, purge));
}
项目:EIM    文件:Node.java   
/**
 * 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));
}
项目:EIM    文件:FaultTolerantNegotiator.java   
public PacketFilter getInitiationPacketFilter(String from, String streamID) {
    if (primaryFilter == null || secondaryFilter == null) {
        primaryFilter = primaryNegotiator.getInitiationPacketFilter(from, streamID);
        secondaryFilter = secondaryNegotiator.getInitiationPacketFilter(from, streamID);
    }
    return new OrFilter(primaryFilter, secondaryFilter);
}
项目:androidPN-client.    文件:Node.java   
/**
 * 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));
}
项目:androidPN-client.    文件:FaultTolerantNegotiator.java   
public PacketFilter getInitiationPacketFilter(String from, String streamID) {
    if (primaryFilter == null || secondaryFilter == null) {
        primaryFilter = primaryNegotiator.getInitiationPacketFilter(from, streamID);
        secondaryFilter = secondaryNegotiator.getInitiationPacketFilter(from, streamID);
    }
    return new OrFilter(primaryFilter, secondaryFilter);
}
项目:xmppsupport_v2    文件:Node.java   
/**
 * 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));
}
项目:xmppsupport_v2    文件:FaultTolerantNegotiator.java   
public PacketFilter getInitiationPacketFilter(String from, String streamID) {
    if (primaryFilter == null || secondaryFilter == null) {
        primaryFilter = primaryNegotiator.getInitiationPacketFilter(from,
                streamID);
        secondaryFilter = secondaryNegotiator.getInitiationPacketFilter(
                from, streamID);
    }
    return new OrFilter(primaryFilter, secondaryFilter);
}
项目:msf-spaces-sdk-android    文件:SpaceHandler.java   
/**
 * Setter for the XMPPConnection. Use this only when you create a new connection object.
 * @param connectionHandler The XMPPConnection object this instance of a SpaceHandler should use.
 * @throws SpaceManagementException Thrown when there's no response from the server.
 */
public void changeConnectionHandler(ConnectionHandler connectionHandler) throws SpaceManagementException {
    this.connectionHandler = connectionHandler;
    this.connection = this.connectionHandler.getXMPPConnection();

    if (connectionHandler.getNetworkInformation().getSpacesServiceJID() != null){
        AndFilter andFilter = new AndFilter();
        OrFilter orFilter = new OrFilter();
        orFilter.addFilter(new IQTypeFilter(IQ.Type.ERROR));
        orFilter.addFilter(new IQTypeFilter(IQ.Type.RESULT));
        andFilter.addFilter(orFilter);
        andFilter.addFilter(new FromContainsFilter(connectionHandler.getNetworkInformation().getSpacesServiceJID()));
        this.connection.addPacketListener(packetListener, andFilter);
    }
}
项目:java-bells    文件:Node.java   
/**
 * 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));
}
项目:java-bells    文件:FaultTolerantNegotiator.java   
public PacketFilter getInitiationPacketFilter(String from, String streamID) {
    if (primaryFilter == null || secondaryFilter == null) {
        primaryFilter = primaryNegotiator.getInitiationPacketFilter(from, streamID);
        secondaryFilter = secondaryNegotiator.getInitiationPacketFilter(from, streamID);
    }
    return new OrFilter(primaryFilter, secondaryFilter);
}
项目:telegraph    文件:Node.java   
/**
 * 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));
}
项目:telegraph    文件:FaultTolerantNegotiator.java   
public PacketFilter getInitiationPacketFilter(String from, String streamID) {
    if (primaryFilter == null || secondaryFilter == null) {
        primaryFilter = primaryNegotiator.getInitiationPacketFilter(from, streamID);
        secondaryFilter = secondaryNegotiator.getInitiationPacketFilter(from, streamID);
    }
    return new OrFilter(primaryFilter, secondaryFilter);
}
项目:NewCommunication-Android    文件:Node.java   
/**
 * 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));
}
项目:NewCommunication-Android    文件:FaultTolerantNegotiator.java   
public PacketFilter getInitiationPacketFilter(String from, String streamID) {
    if (primaryFilter == null || secondaryFilter == null) {
        primaryFilter = primaryNegotiator.getInitiationPacketFilter(from, streamID);
        secondaryFilter = secondaryNegotiator.getInitiationPacketFilter(from, streamID);
    }
    return new OrFilter(primaryFilter, secondaryFilter);
}
项目:jmeter-bzm-plugins    文件:NoOp.java   
@Override
public PacketFilter getPacketFilter() {
    return new OrFilter(PacketTypeFilter.MESSAGE, PacketTypeFilter.PRESENCE, new PacketTypeFilter(IQ.class));
}
项目:Camel    文件:XmppConsumer.java   
@Override
protected void doStart() throws Exception {
    try {
        connection = endpoint.createConnection();
    } catch (SmackException e) {
        if (endpoint.isTestConnectionOnStartup()) {
            throw new RuntimeException("Could not connect to XMPP server.", e);
        } else {
            LOG.warn(e.getMessage());
            if (getExceptionHandler() != null) {
                getExceptionHandler().handleException(e.getMessage(), e);
            }
            scheduleDelayedStart();
            return;
        }
    }

    chatManager = ChatManager.getInstanceFor(connection);
    chatManager.addChatListener(this);

    OrFilter pubsubPacketFilter = new OrFilter();
    if (endpoint.isPubsub()) {
        //xep-0060: pubsub#notification_type can be 'headline' or 'normal'
        pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.headline));
        pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.normal));
        connection.addPacketListener(this, pubsubPacketFilter);
    }

    if (endpoint.getRoom() == null) {
        privateChat = chatManager.getThreadChat(endpoint.getChatId());

        if (privateChat != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Adding listener to existing chat opened to " + privateChat.getParticipant());
            }
            privateChat.addMessageListener(this);
        } else {
            privateChat = ChatManager.getInstanceFor(connection).createChat(endpoint.getParticipant(), endpoint.getChatId(), this);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Opening private chat to " + privateChat.getParticipant());
            }
        }
    } else {
        // add the presence packet listener to the connection so we only get packets that concerns us
        // we must add the listener before creating the muc

        final AndFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class));
        connection.addPacketListener(this, packetFilter);

        muc = new MultiUserChat(connection, endpoint.resolveRoom(connection));
        muc.addMessageListener(this);
        DiscussionHistory history = new DiscussionHistory();
        history.setMaxChars(0); // we do not want any historical messages

        muc.join(endpoint.getNickname(), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
        if (LOG.isInfoEnabled()) {
            LOG.info("Joined room: {} as: {}", muc.getRoom(), endpoint.getNickname());
        }
    }

    this.startRobustConnectionMonitor();
    super.doStart();
}
项目:spark-svn-mirror    文件:ChatRoomImpl.java   
/**
 * Constructs a 1-to-1 ChatRoom.
 *
 * @param participantJID      the participants jid to chat with.
 * @param participantNickname the nickname of the participant.
 * @param title               the title of the room.
 */
public ChatRoomImpl(final String participantJID, String participantNickname, String title, boolean initUi) {
    this.active = true;
    //activateNotificationTime = System.currentTimeMillis();
    this.participantJID = participantJID;
    this.participantNickname = participantNickname;

    // Loads the current history for this user.
    loadHistory();

    // Register PacketListeners
    PacketFilter fromFilter = new FromMatchesFilter(participantJID);
    PacketFilter orFilter = new OrFilter(new PacketTypeFilter(Presence.class), new PacketTypeFilter(Message.class));
    PacketFilter andFilter = new AndFilter(orFilter, fromFilter);

    SparkManager.getConnection().addPacketListener(this, andFilter);

    // The roomname will be the participantJID
    this.roomname = participantJID;

    // Use the agents username as the Tab Title
    this.tabTitle = title;

    // The name of the room will be the node of the user jid + conversation.
    this.roomTitle = participantNickname;

    // Add RoomInfo
    this.getSplitPane().setRightComponent(null);
    getSplitPane().setDividerSize(0);


    presence = PresenceManager.getPresence(participantJID);

    roster = SparkManager.getConnection().getRoster();

    RosterEntry entry = roster.getEntry(participantJID);

    tabIcon = PresenceManager.getIconFromPresence(presence);

    if (initUi) {
        // Create toolbar buttons.
        infoButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_24x24));
        infoButton.setToolTipText(Res.getString("message.view.information.about.this.user"));
        // Create basic toolbar.
        addChatRoomButton(infoButton);
        // Show VCard.
        infoButton.addActionListener(this);
    }

    // If the user is not in the roster, then allow user to add them.
    addToRosterButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.ADD_IMAGE_24x24));
    if (entry == null && !StringUtils.parseResource(participantJID).equals(participantNickname)) {
        addToRosterButton.setToolTipText(Res.getString("message.add.this.user.to.your.roster"));
        if(!Default.getBoolean(Default.ADD_CONTACT_DISABLED)) {
            addChatRoomButton(addToRosterButton);
        }
        addToRosterButton.addActionListener(this);
    }

    // If this is a private chat from a group chat room, do not show toolbar.
    if (StringUtils.parseResource(participantJID).equals(participantNickname)) {
        getToolBar().setVisible(false);
    }

    createChatStateTimerTask();

    lastActivity = System.currentTimeMillis();
    getChatInputEditor().addFocusListener(new ChatStateFocusListener());
}