2005-08-10 06:49:54 +02:00
|
|
|
/**
|
|
|
|
*
|
2017-01-29 11:08:16 +01:00
|
|
|
* Copyright 2003-2014 Jive Software, 2017 Florian Schmaus.
|
2005-08-10 06:49:54 +02:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2005-08-10 06:49:54 +02: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.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smack.filter;
|
|
|
|
|
2015-02-05 11:17:27 +01:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
import org.jxmpp.jid.Jid;
|
2005-08-10 06:49:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter for packets where the "from" field exactly matches a specified JID. If the specified
|
|
|
|
* address is a bare JID then the filter will match any address whose bare JID matches the
|
|
|
|
* specified JID. But if the specified address is a full JID then the filter will only match
|
2018-03-31 14:17:30 +02:00
|
|
|
* if the sender of the stanza matches the specified resource.
|
2005-08-10 06:49:54 +02:00
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
2017-01-29 11:08:16 +01:00
|
|
|
public final class FromMatchesFilter extends AbstractFromToMatchesFilter {
|
2005-08-10 06:49:54 +02:00
|
|
|
|
2018-03-29 12:35:11 +02:00
|
|
|
public static final FromMatchesFilter MATCH_NO_FROM_SET = create(null);
|
2005-08-10 06:49:54 +02:00
|
|
|
|
2014-02-23 21:08:35 +01:00
|
|
|
/**
|
|
|
|
* Creates a filter matching on the "from" field. The from address must be the same as the
|
|
|
|
* filter address. The second parameter specifies whether the full or the bare addresses are
|
|
|
|
* compared.
|
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* @param address The address to filter for. If <code>null</code> is given, the stanza must not
|
2014-02-23 21:08:35 +01:00
|
|
|
* have a from address.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param ignoreResourcepart TODO javadoc me please
|
2014-02-23 21:08:35 +01:00
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public FromMatchesFilter(Jid address, boolean ignoreResourcepart) {
|
2017-01-29 11:08:16 +01:00
|
|
|
super(address, ignoreResourcepart);
|
2014-02-23 21:08:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a filter matching on the "from" field. If the filter address is bare, compares
|
|
|
|
* the filter address with the bare from address. Otherwise, compares the filter address
|
|
|
|
* with the full from address.
|
|
|
|
*
|
2017-01-29 11:08:16 +01:00
|
|
|
* @param address The address to filter for. If <code>null</code> is given, the stanza must not
|
2014-02-23 21:08:35 +01:00
|
|
|
* have a from address.
|
2017-12-23 20:21:19 +01:00
|
|
|
* @return filter for the "from" address.
|
2014-02-23 21:08:35 +01:00
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public static FromMatchesFilter create(Jid address) {
|
2017-01-29 11:08:16 +01:00
|
|
|
return new FromMatchesFilter(address, address != null ? address.hasNoResource() : false) ;
|
2014-02-23 21:08:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a filter matching on the "from" field. Compares the bare version of from and filter
|
|
|
|
* address.
|
|
|
|
*
|
2017-01-29 11:08:16 +01:00
|
|
|
* @param address The address to filter for. If <code>null</code> is given, the stanza must not
|
2014-02-23 21:08:35 +01:00
|
|
|
* have a from address.
|
2017-12-23 20:21:19 +01:00
|
|
|
* @return filter matching the "from" address.
|
2014-02-23 21:08:35 +01:00
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public static FromMatchesFilter createBare(Jid address) {
|
2014-02-23 21:08:35 +01:00
|
|
|
return new FromMatchesFilter(address, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-29 11:08:16 +01:00
|
|
|
* Creates a filter matching on the "from" field. Compares the full version, if available, of from and filter
|
2014-02-23 21:08:35 +01:00
|
|
|
* address.
|
|
|
|
*
|
2017-01-29 11:08:16 +01:00
|
|
|
* @param address The address to filter for. If <code>null</code> is given, the stanza must not
|
2014-02-23 21:08:35 +01:00
|
|
|
* have a from address.
|
2017-12-23 20:21:19 +01:00
|
|
|
* @return filter matching the "from" address.
|
2014-02-23 21:08:35 +01:00
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public static FromMatchesFilter createFull(Jid address) {
|
2014-02-23 21:08:35 +01:00
|
|
|
return new FromMatchesFilter(address, false);
|
2005-08-10 06:49:54 +02:00
|
|
|
}
|
|
|
|
|
2017-01-29 11:08:16 +01:00
|
|
|
@Override
|
|
|
|
protected Jid getAddressToCompare(Stanza stanza) {
|
|
|
|
return stanza.getFrom();
|
2005-08-10 06:49:54 +02:00
|
|
|
}
|
2006-07-07 17:05:00 +02:00
|
|
|
|
2005-08-10 06:49:54 +02:00
|
|
|
}
|