mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Merge Smack 4.1.0-rc2
Conflicts: smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java version.gradle
This commit is contained in:
commit
fbf0ba13ce
48 changed files with 650 additions and 166 deletions
|
@ -57,7 +57,7 @@ import org.jivesoftware.smack.compression.XMPPInputOutputStream;
|
|||
import org.jivesoftware.smack.debugger.SmackDebugger;
|
||||
import org.jivesoftware.smack.filter.IQReplyFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.filter.StanzaIdFilter;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
|
||||
import org.jivesoftware.smack.packet.Bind;
|
||||
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||
|
@ -547,7 +547,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
// Note that we can not use IQReplyFilter here, since the users full JID is not yet
|
||||
// available. It will become available right after the resource has been successfully bound.
|
||||
Bind bindResource = Bind.newSet(resource);
|
||||
PacketCollector packetCollector = createPacketCollectorAndSend(new PacketIDFilter(bindResource), bindResource);
|
||||
PacketCollector packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(bindResource), bindResource);
|
||||
Bind response = packetCollector.nextResultOrThrow();
|
||||
// Set the connections user to the result of resource binding. It is important that we don't infer the user
|
||||
// from the login() arguments and the configurations service name, as, for example, when SASL External is used,
|
||||
|
@ -560,7 +560,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
// For more information see http://tools.ietf.org/html/draft-cridland-xmpp-session-01
|
||||
if (sessionFeature != null && !sessionFeature.isOptional() && !getConfiguration().isLegacySessionDisabled()) {
|
||||
Session session = new Session();
|
||||
packetCollector = createPacketCollectorAndSend(new PacketIDFilter(session), session);
|
||||
packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(session), session);
|
||||
packetCollector.nextResultOrThrow();
|
||||
}
|
||||
}
|
||||
|
@ -1445,7 +1445,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter,
|
||||
public void sendStanzaWithResponseCallback(Stanza stanza, final PacketFilter replyFilter,
|
||||
final PacketListener callback, final ExceptionCallback exceptionCallback,
|
||||
long timeout) throws NotConnectedException, InterruptedException {
|
||||
Objects.requireNonNull(stanza, "stanza must not be null");
|
||||
|
@ -1478,7 +1478,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
// If the packetListener got removed, then it was never run and
|
||||
// we never received a response, inform the exception callback
|
||||
if (removed && exceptionCallback != null) {
|
||||
exceptionCallback.processException(new NoResponseException(AbstractXMPPConnection.this));
|
||||
exceptionCallback.processException(NoResponseException.newWith(AbstractXMPPConnection.this, replyFilter));
|
||||
}
|
||||
}
|
||||
}, timeout, TimeUnit.MILLISECONDS);
|
||||
|
|
|
@ -205,7 +205,7 @@ public class PacketCollector {
|
|||
P result = nextResult(timeout);
|
||||
cancel();
|
||||
if (result == null) {
|
||||
throw new NoResponseException(connection);
|
||||
throw NoResponseException.newWith(connection, this);
|
||||
}
|
||||
|
||||
XMPPErrorException.ifHasErrorThenThrow(result);
|
||||
|
|
|
@ -196,7 +196,7 @@ public class SASLAuthentication {
|
|||
maybeThrowException();
|
||||
|
||||
if (!authenticationSuccessful) {
|
||||
throw new NoResponseException(connection);
|
||||
throw NoResponseException.newWith(connection);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -239,7 +239,7 @@ public class SASLAuthentication {
|
|||
maybeThrowException();
|
||||
|
||||
if (!authenticationSuccessful) {
|
||||
throw new NoResponseException(connection);
|
||||
throw NoResponseException.newWith(connection);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -274,7 +274,7 @@ public class SASLAuthentication {
|
|||
maybeThrowException();
|
||||
|
||||
if (!authenticationSuccessful) {
|
||||
throw new NoResponseException(connection);
|
||||
throw NoResponseException.newWith(connection);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smack;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.util.dns.HostAddress;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
|
@ -65,10 +66,47 @@ public class SmackException extends Exception {
|
|||
*/
|
||||
private static final long serialVersionUID = -6523363748984543636L;
|
||||
|
||||
public NoResponseException(XMPPConnection connection) {
|
||||
super("No response received within packet reply timeout. Timeout was " + connection.getPacketReplyTimeout()
|
||||
+ "ms (~" + connection.getPacketReplyTimeout() / 1000 + "s)");
|
||||
private final PacketFilter filter;
|
||||
|
||||
private NoResponseException(String message, PacketFilter filter) {
|
||||
super(message);
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filter that was used to collect the response.
|
||||
*
|
||||
* @return the used filter or <code>null</code>.
|
||||
*/
|
||||
public PacketFilter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public static NoResponseException newWith(XMPPConnection connection) {
|
||||
return newWith(connection, (PacketFilter) null);
|
||||
}
|
||||
|
||||
public static NoResponseException newWith(XMPPConnection connection,
|
||||
PacketCollector collector) {
|
||||
return newWith(connection, collector.getPacketFilter());
|
||||
}
|
||||
|
||||
public static NoResponseException newWith(XMPPConnection connection, PacketFilter filter) {
|
||||
final long replyTimeout = connection.getPacketReplyTimeout();
|
||||
final StringBuilder sb = new StringBuilder(256);
|
||||
sb.append("No response received within reply timeout. Timeout was "
|
||||
+ replyTimeout + "ms (~"
|
||||
+ replyTimeout / 1000 + "s). Used filter: ");
|
||||
if (filter != null) {
|
||||
sb.append(filter.toString());
|
||||
}
|
||||
else {
|
||||
sb.append("No filter used or filter was 'null'");
|
||||
}
|
||||
sb.append('.');
|
||||
return new NoResponseException(sb.toString(), filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class NotLoggedInException extends SmackException {
|
||||
|
|
|
@ -190,7 +190,7 @@ public class SynchronizationPoint<E extends Exception> {
|
|||
case Initial:
|
||||
case NoResponse:
|
||||
case RequestSent:
|
||||
throw new NoResponseException(connection);
|
||||
throw NoResponseException.newWith(connection);
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
|
|
|
@ -129,11 +129,6 @@ public abstract class XMPPException extends Exception {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getMessage();
|
||||
}
|
||||
|
||||
public static void ifHasErrorThenThrow(Stanza packet) throws XMPPErrorException {
|
||||
XMPPError xmppError = packet.getError();
|
||||
if (xmppError != null) {
|
||||
|
@ -157,7 +152,7 @@ public abstract class XMPPException extends Exception {
|
|||
* @param streamError the root cause of the exception.
|
||||
*/
|
||||
public StreamErrorException(StreamError streamError) {
|
||||
super();
|
||||
super(streamError.toString());
|
||||
this.streamError = streamError;
|
||||
}
|
||||
|
||||
|
@ -171,14 +166,5 @@ public abstract class XMPPException extends Exception {
|
|||
return streamError;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return streamError.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractListFilter implements PacketFilter {
|
||||
|
||||
/**
|
||||
* The list of filters.
|
||||
*/
|
||||
protected final List<PacketFilter> filters;
|
||||
|
||||
/**
|
||||
* Creates an empty filter.
|
||||
*/
|
||||
protected AbstractListFilter() {
|
||||
filters = new ArrayList<PacketFilter>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an filter using the specified filters.
|
||||
*
|
||||
* @param filters the filters to add.
|
||||
*/
|
||||
protected AbstractListFilter(PacketFilter... filters) {
|
||||
Objects.requireNonNull(filters, "Parameter must not be null.");
|
||||
for(PacketFilter filter : filters) {
|
||||
Objects.requireNonNull(filter, "Parameter must not be null.");
|
||||
}
|
||||
this.filters = new ArrayList<PacketFilter>(Arrays.asList(filters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a filter to the filter list. A stanza will pass the filter if all of the filters in the
|
||||
* list accept it.
|
||||
*
|
||||
* @param filter a filter to add to the filter list.
|
||||
*/
|
||||
public void addFilter(PacketFilter filter) {
|
||||
Objects.requireNonNull(filter, "Parameter must not be null.");
|
||||
filters.add(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" (");
|
||||
for (PacketFilter filter : filters) {
|
||||
sb.append(' ' + filter.toString() + ',');
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -17,12 +17,7 @@
|
|||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
||||
/**
|
||||
* Implements the logical AND operation over two or more packet filters.
|
||||
|
@ -30,19 +25,14 @@ import org.jivesoftware.smack.util.Objects;
|
|||
*
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
public class AndFilter implements PacketFilter {
|
||||
|
||||
/**
|
||||
* The list of filters.
|
||||
*/
|
||||
private final List<PacketFilter> filters;
|
||||
public class AndFilter extends AbstractListFilter implements PacketFilter {
|
||||
|
||||
/**
|
||||
* Creates an empty AND filter. Filters should be added using the
|
||||
* {@link #addFilter(PacketFilter)} method.
|
||||
*/
|
||||
public AndFilter() {
|
||||
filters = new ArrayList<PacketFilter>();
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,22 +41,7 @@ public class AndFilter implements PacketFilter {
|
|||
* @param filters the filters to add.
|
||||
*/
|
||||
public AndFilter(PacketFilter... filters) {
|
||||
Objects.requireNonNull(filters, "Parameter must not be null.");
|
||||
for(PacketFilter filter : filters) {
|
||||
Objects.requireNonNull(filter, "Parameter must not be null.");
|
||||
}
|
||||
this.filters = new ArrayList<PacketFilter>(Arrays.asList(filters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a filter to the filter list for the AND operation. A packet
|
||||
* will pass the filter if all of the filters in the list accept it.
|
||||
*
|
||||
* @param filter a filter to add to the filter list.
|
||||
*/
|
||||
public void addFilter(PacketFilter filter) {
|
||||
Objects.requireNonNull(filter, "Parameter must not be null.");
|
||||
filters.add(filter);
|
||||
super(filters);
|
||||
}
|
||||
|
||||
public boolean accept(Stanza packet) {
|
||||
|
@ -78,7 +53,4 @@ public class AndFilter implements PacketFilter {
|
|||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return filters.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.jivesoftware.smack.filter;
|
|||
import java.lang.reflect.ParameterizedType;
|
||||
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
||||
/**
|
||||
* Filters for packets of a particular type and allows a custom method to further filter the packets.
|
||||
|
@ -31,7 +32,7 @@ public abstract class FlexiblePacketTypeFilter<P extends Stanza> implements Pack
|
|||
protected final Class<P> packetType;
|
||||
|
||||
public FlexiblePacketTypeFilter(Class<P> packetType) {
|
||||
this.packetType = packetType;
|
||||
this.packetType = Objects.requireNonNull(packetType, "Type must not be null");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -49,4 +50,12 @@ public abstract class FlexiblePacketTypeFilter<P extends Stanza> implements Pack
|
|||
}
|
||||
|
||||
protected abstract boolean acceptSpecific(P packet);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" (" + packetType.toString() + ')');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,6 +106,6 @@ public class FromMatchesFilter implements PacketFilter {
|
|||
|
||||
public String toString() {
|
||||
String matchMode = ignoreResourcepart ? "ignoreResourcepart" : "full";
|
||||
return "FromMatchesFilter (" +matchMode + "): " + address;
|
||||
return getClass().getSimpleName() + " (" + matchMode + "): " + address;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public class IQReplyFilter implements PacketFilter {
|
|||
packetId = iqPacket.getStanzaId();
|
||||
|
||||
PacketFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT);
|
||||
PacketFilter idFilter = new PacketIDFilter(iqPacket);
|
||||
PacketFilter idFilter = new StanzaIdFilter(iqPacket);
|
||||
iqAndIdFilter = new AndFilter(iqFilter, idFilter);
|
||||
fromFilter = new OrFilter();
|
||||
fromFilter.addFilter(FromMatchesFilter.createFull(to));
|
||||
|
@ -126,4 +126,12 @@ public class IQReplyFilter implements PacketFilter {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(": iqAndIdFilter (").append(iqAndIdFilter.toString()).append("), ");
|
||||
sb.append(": fromFilter (").append(fromFilter.toString()).append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,4 +38,11 @@ public class IQResultReplyFilter extends IQReplyFilter {
|
|||
return IQTypeFilter.RESULT.accept(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" (" + super.toString() + ')');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.jivesoftware.smack.filter;
|
|||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
||||
/**
|
||||
* A filter for IQ packet types. Returns true only if the packet is an IQ packet
|
||||
|
@ -38,11 +39,16 @@ public class IQTypeFilter extends FlexiblePacketTypeFilter<IQ> {
|
|||
|
||||
private IQTypeFilter(IQ.Type type) {
|
||||
super(IQ.class);
|
||||
this.type = type;
|
||||
this.type = Objects.requireNonNull(type, "Type must not be null");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean acceptSpecific(IQ iq) {
|
||||
return iq.getType() == type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ": type=" + type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,4 +55,8 @@ public class MessageTypeFilter extends FlexiblePacketTypeFilter<Message> {
|
|||
return message.getType() == type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ": type=" + type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,4 +36,8 @@ public class MessageWithBodiesFilter extends FlexiblePacketTypeFilter<Message> {
|
|||
return !message.getBodies().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,4 +36,8 @@ public class MessageWithSubjectFilter extends FlexiblePacketTypeFilter<Message>
|
|||
return message.getSubject() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
||||
/**
|
||||
* Implements the logical NOT operation on a packet filter. In other words, packets
|
||||
|
@ -35,10 +36,7 @@ public class NotFilter implements PacketFilter {
|
|||
* @param filter the filter.
|
||||
*/
|
||||
public NotFilter(PacketFilter filter) {
|
||||
if (filter == null) {
|
||||
throw new IllegalArgumentException("Parameter must not be null.");
|
||||
}
|
||||
this.filter = filter;
|
||||
this.filter = Objects.requireNonNull(filter, "Parameter must not be null.");
|
||||
}
|
||||
|
||||
public boolean accept(Stanza packet) {
|
||||
|
|
|
@ -17,12 +17,7 @@
|
|||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
||||
/**
|
||||
* Implements the logical OR operation over two or more packet filters. In
|
||||
|
@ -30,19 +25,14 @@ import org.jivesoftware.smack.util.Objects;
|
|||
*
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
public class OrFilter implements PacketFilter {
|
||||
|
||||
/**
|
||||
* The list of filters.
|
||||
*/
|
||||
private final List<PacketFilter> filters;
|
||||
public class OrFilter extends AbstractListFilter implements PacketFilter {
|
||||
|
||||
/**
|
||||
* Creates an empty OR filter. Filters should be added using the
|
||||
* {@link #addFilter(PacketFilter)} method.
|
||||
*/
|
||||
public OrFilter() {
|
||||
filters = new ArrayList<PacketFilter>();
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,24 +41,10 @@ public class OrFilter implements PacketFilter {
|
|||
* @param filters the filters to add.
|
||||
*/
|
||||
public OrFilter(PacketFilter... filters) {
|
||||
Objects.requireNonNull(filters, "Parameter must not be null.");
|
||||
for(PacketFilter filter : filters) {
|
||||
Objects.requireNonNull(filter, "Parameter must not be null.");
|
||||
}
|
||||
this.filters = new ArrayList<PacketFilter>(Arrays.asList(filters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a filter to the filter list for the OR operation. A packet
|
||||
* will pass the filter if any filter in the list accepts it.
|
||||
*
|
||||
* @param filter a filter to add to the filter list.
|
||||
*/
|
||||
public void addFilter(PacketFilter filter) {
|
||||
Objects.requireNonNull(filter, "Parameter must not be null.");
|
||||
filters.add(filter);
|
||||
super(filters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(Stanza packet) {
|
||||
for (PacketFilter filter : filters) {
|
||||
if (filter.accept(packet)) {
|
||||
|
@ -78,7 +54,4 @@ public class OrFilter implements PacketFilter {
|
|||
return false;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return filters.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,4 +68,9 @@ public class PacketExtensionFilter implements PacketFilter {
|
|||
public boolean accept(Stanza packet) {
|
||||
return packet.hasExtension(elementName, namespace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ": element=" + elementName + " namespace=" + namespace;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.jivesoftware.smack.packet.Stanza;
|
|||
* packet filtering by using the {@link org.jivesoftware.smack.filter.AndFilter AndFilter} and
|
||||
* {@link org.jivesoftware.smack.filter.OrFilter OrFilter} filters. It's also possible to define
|
||||
* your own filters by implementing this interface. The code example below creates a trivial filter
|
||||
* for packets with a specific ID (real code should use {@link PacketIDFilter} instead).
|
||||
* for packets with a specific ID (real code should use {@link StanzaIdFilter} instead).
|
||||
*
|
||||
* <pre>
|
||||
* // Use an anonymous inner class to define a packet filter that returns
|
||||
|
|
|
@ -24,7 +24,9 @@ import org.jivesoftware.smack.util.StringUtils;
|
|||
* Filters for packets with a particular packet ID.
|
||||
*
|
||||
* @author Matt Tucker
|
||||
* @deprecated use {@link StanzaIdFilter} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class PacketIDFilter implements PacketFilter {
|
||||
|
||||
private final String packetID;
|
||||
|
@ -33,7 +35,9 @@ public class PacketIDFilter implements PacketFilter {
|
|||
* Creates a new packet ID filter using the specified packet's ID.
|
||||
*
|
||||
* @param packet the packet which the ID is taken from.
|
||||
* @deprecated use {@link StanzaIdfilter(Stanza)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PacketIDFilter(Stanza packet) {
|
||||
this(packet.getStanzaId());
|
||||
}
|
||||
|
@ -42,7 +46,9 @@ public class PacketIDFilter implements PacketFilter {
|
|||
* Creates a new packet ID filter using the specified packet ID.
|
||||
*
|
||||
* @param packetID the packet ID to filter for.
|
||||
* @deprecated use {@link StanzaIdFilter(String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PacketIDFilter(String packetID) {
|
||||
StringUtils.requireNotNullOrEmpty(packetID, "Packet ID must not be null or empty.");
|
||||
this.packetID = packetID;
|
||||
|
@ -53,6 +59,6 @@ public class PacketIDFilter implements PacketFilter {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return "PacketIDFilter by id: " + packetID;
|
||||
return getClass().getSimpleName() + ": id=" + packetID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,8 @@ public class PacketTypeFilter implements PacketFilter {
|
|||
return packetType.isInstance(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PacketTypeFilter: " + packetType.getName();
|
||||
return getClass().getSimpleName() + ": " + packetType.getName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.jivesoftware.smack.filter;
|
|||
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.packet.Presence.Type;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
||||
/**
|
||||
* A filter for Presence types. Returns true only if the stanza is an Presence packet and it matches the type provided in the
|
||||
|
@ -38,11 +39,16 @@ public class PresenceTypeFilter extends FlexiblePacketTypeFilter<Presence> {
|
|||
|
||||
private PresenceTypeFilter(Presence.Type type) {
|
||||
super(Presence.class);
|
||||
this.type = type;
|
||||
this.type = Objects.requireNonNull(type, "type must not be null");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean acceptSpecific(Presence presence) {
|
||||
return presence.getType() == type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ": type=" + type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Filters for Stanzas with a particular stanza ID.
|
||||
*
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
public class StanzaIdFilter implements PacketFilter {
|
||||
|
||||
private final String stanzaId;
|
||||
|
||||
/**
|
||||
* Creates a new stanza ID filter using the specified stanza's ID.
|
||||
*
|
||||
* @param stanza the stanza which the ID is taken from.
|
||||
*/
|
||||
public StanzaIdFilter(Stanza stanza) {
|
||||
this(stanza.getStanzaId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new stanza ID filter using the specified stanza ID.
|
||||
*
|
||||
* @param stanzaID the stanza ID to filter for.
|
||||
*/
|
||||
public StanzaIdFilter(String stanzaID) {
|
||||
this.stanzaId = StringUtils.requireNotNullOrEmpty(stanzaID, "Stanza ID must not be null or empty.");
|
||||
}
|
||||
|
||||
public boolean accept(Stanza stanza) {
|
||||
return stanzaId.equals(stanza.getStanzaId());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ": id=" + stanzaId;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
|
@ -26,7 +25,7 @@ import org.jivesoftware.smack.util.StringUtils;
|
|||
*
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
public class ThreadFilter implements PacketFilter {
|
||||
public class ThreadFilter extends FlexiblePacketTypeFilter<Message> implements PacketFilter {
|
||||
|
||||
private final String thread;
|
||||
|
||||
|
@ -40,7 +39,13 @@ public class ThreadFilter implements PacketFilter {
|
|||
this.thread = thread;
|
||||
}
|
||||
|
||||
public boolean accept(Stanza packet) {
|
||||
return packet instanceof Message && thread.equals(((Message) packet).getThread());
|
||||
@Override
|
||||
protected boolean acceptSpecific(Message message) {
|
||||
return thread.equals(message.getThread());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ": thread=" + thread;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,4 +36,8 @@ public class ToFilter implements PacketFilter {
|
|||
return packetTo.equals(to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ": to=" + to;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue