2003-11-05 18:44:00 +01:00
|
|
|
/**
|
2004-11-03 00:53:30 +01:00
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2004-11-03 00:53:30 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2004-11-03 00:53:30 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2003-11-05 18:44:00 +01:00
|
|
|
|
|
|
|
package org.jivesoftware.smack.filter;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.packet.Message;
|
2014-05-29 16:05:20 +02:00
|
|
|
import org.jivesoftware.smack.packet.Message.Type;
|
|
|
|
|
2003-11-05 18:44:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters for packets of a specific type of Message (e.g. CHAT).
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2004-03-11 16:55:44 +01:00
|
|
|
* @see org.jivesoftware.smack.packet.Message.Type
|
2003-11-05 18:44:00 +01:00
|
|
|
* @author Ward Harold
|
|
|
|
*/
|
2015-04-06 10:45:12 +02:00
|
|
|
public final class MessageTypeFilter extends FlexibleStanzaTypeFilter<Message> {
|
2015-02-26 18:41:17 +01:00
|
|
|
|
|
|
|
public static final StanzaFilter NORMAL = new MessageTypeFilter(Type.normal);
|
|
|
|
public static final StanzaFilter CHAT = new MessageTypeFilter(Type.chat);
|
|
|
|
public static final StanzaFilter GROUPCHAT = new MessageTypeFilter(Type.groupchat);
|
|
|
|
public static final StanzaFilter HEADLINE = new MessageTypeFilter(Type.headline);
|
|
|
|
public static final StanzaFilter ERROR = new MessageTypeFilter(Type.error);
|
|
|
|
public static final StanzaFilter NORMAL_OR_CHAT = new OrFilter(NORMAL, CHAT);
|
2020-05-12 19:57:56 +02:00
|
|
|
public static final StanzaFilter NORMAL_OR_HEADLINE = new OrFilter(NORMAL, HEADLINE);
|
2015-02-26 18:41:17 +01:00
|
|
|
public static final StanzaFilter NORMAL_OR_CHAT_OR_HEADLINE = new OrFilter(NORMAL_OR_CHAT,
|
2015-01-19 16:23:50 +01:00
|
|
|
HEADLINE);
|
2003-11-05 18:44:00 +01:00
|
|
|
|
|
|
|
private final Message.Type type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new message type filter using the specified message type.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2004-03-11 16:55:44 +01:00
|
|
|
* @param type the message type.
|
2003-11-05 18:44:00 +01:00
|
|
|
*/
|
2014-05-29 16:05:20 +02:00
|
|
|
private MessageTypeFilter(Message.Type type) {
|
|
|
|
super(Message.class);
|
2003-11-05 18:44:00 +01:00
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
2014-05-29 16:05:20 +02:00
|
|
|
@Override
|
|
|
|
protected boolean acceptSpecific(Message message) {
|
2014-12-22 16:13:02 +01:00
|
|
|
return message.getType() == type;
|
2003-11-05 18:44:00 +01:00
|
|
|
}
|
|
|
|
|
2015-02-19 12:11:19 +01:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return getClass().getSimpleName() + ": type=" + type;
|
|
|
|
}
|
2003-11-05 18:44:00 +01:00
|
|
|
}
|