mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-22 20:47:57 +01:00
Add Possible(From|To)TypeFilter
This commit is contained in:
parent
f3b65f3dc8
commit
9bb724d65d
7 changed files with 190 additions and 27 deletions
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017-2018 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 org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
public abstract class AbstractExactJidTypeFilter extends AbstractJidTypeFilter {
|
||||
|
||||
protected AbstractExactJidTypeFilter(JidType jidType) {
|
||||
super(jidType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean accept(Stanza stanza) {
|
||||
final Jid jid = getJidToInspect(stanza);
|
||||
|
||||
if (jid == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (jidType) {
|
||||
case entityFull:
|
||||
return jid.isEntityFullJid();
|
||||
case entityBare:
|
||||
return jid.isEntityBareJid();
|
||||
case domainFull:
|
||||
return jid.isDomainFullJid();
|
||||
case domainBare:
|
||||
return jid.isDomainBareJid();
|
||||
case any:
|
||||
return true;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -31,7 +31,7 @@ public abstract class AbstractJidTypeFilter implements StanzaFilter {
|
|||
;
|
||||
}
|
||||
|
||||
private final JidType jidType;
|
||||
protected final JidType jidType;
|
||||
|
||||
protected AbstractJidTypeFilter(JidType jidType) {
|
||||
this.jidType = jidType;
|
||||
|
@ -39,28 +39,4 @@ public abstract class AbstractJidTypeFilter implements StanzaFilter {
|
|||
|
||||
protected abstract Jid getJidToInspect(Stanza stanza);
|
||||
|
||||
@Override
|
||||
public final boolean accept(Stanza stanza) {
|
||||
final Jid jid = getJidToInspect(stanza);
|
||||
|
||||
if (jid == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (jidType) {
|
||||
case entityFull:
|
||||
return jid.isEntityFullJid();
|
||||
case entityBare:
|
||||
return jid.isEntityBareJid();
|
||||
case domainFull:
|
||||
return jid.isDomainFullJid();
|
||||
case domainBare:
|
||||
return jid.isDomainBareJid();
|
||||
case any:
|
||||
return true;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 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 org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
public abstract class AbstractPossibleJidTypeFilter extends AbstractJidTypeFilter {
|
||||
|
||||
protected AbstractPossibleJidTypeFilter(JidType jidType) {
|
||||
super(jidType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean accept(Stanza stanza) {
|
||||
final Jid jid = getJidToInspect(stanza);
|
||||
|
||||
if (jid == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (jidType) {
|
||||
case entityFull:
|
||||
return null != jid.asEntityFullJidIfPossible();
|
||||
case entityBare:
|
||||
return null != jid.asEntityBareJidIfPossible();
|
||||
case domainFull:
|
||||
return null != jid.asDomainFullJidIfPossible();
|
||||
case domainBare:
|
||||
case any:
|
||||
return true;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@ import org.jivesoftware.smack.packet.Stanza;
|
|||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
public final class FromTypeFilter extends AbstractJidTypeFilter {
|
||||
public final class FromTypeFilter extends AbstractExactJidTypeFilter {
|
||||
|
||||
public static final FromTypeFilter ENTITY_FULL_JID = new FromTypeFilter(JidType.entityFull);
|
||||
public static final FromTypeFilter ENTITY_BARE_JID = new FromTypeFilter(JidType.entityBare);
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 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 org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
public final class PossibleFromTypeFilter extends AbstractPossibleJidTypeFilter {
|
||||
|
||||
public static final PossibleFromTypeFilter ENTITY_FULL_JID = new PossibleFromTypeFilter(JidType.entityFull);
|
||||
public static final PossibleFromTypeFilter ENTITY_BARE_JID = new PossibleFromTypeFilter(JidType.entityBare);
|
||||
public static final PossibleFromTypeFilter DOMAIN_FULL_JID = new PossibleFromTypeFilter(JidType.domainFull);
|
||||
public static final PossibleFromTypeFilter DOMAIN_BARE_JID = new PossibleFromTypeFilter(JidType.domainBare);
|
||||
public static final PossibleFromTypeFilter FROM_ANY_JID = new PossibleFromTypeFilter(JidType.any);
|
||||
|
||||
private PossibleFromTypeFilter(JidType jidType) {
|
||||
super(jidType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Jid getJidToInspect(Stanza stanza) {
|
||||
return stanza.getFrom();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 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 org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
public final class PossibleToTypeFilter extends AbstractPossibleJidTypeFilter {
|
||||
|
||||
public static final PossibleToTypeFilter ENTITY_FULL_JID = new PossibleToTypeFilter(JidType.entityFull);
|
||||
public static final PossibleToTypeFilter ENTITY_BARE_JID = new PossibleToTypeFilter(JidType.entityBare);
|
||||
public static final PossibleToTypeFilter DOMAIN_FULL_JID = new PossibleToTypeFilter(JidType.domainFull);
|
||||
public static final PossibleToTypeFilter DOMAIN_BARE_JID = new PossibleToTypeFilter(JidType.domainBare);
|
||||
public static final PossibleToTypeFilter TO_ANY_JID = new PossibleToTypeFilter(JidType.any);
|
||||
|
||||
public static final StanzaFilter ENTITY_FULL_OR_BARE_JID = new OrFilter(ENTITY_FULL_JID, ENTITY_BARE_JID);
|
||||
|
||||
private PossibleToTypeFilter(JidType jidType) {
|
||||
super(jidType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Jid getJidToInspect(Stanza stanza) {
|
||||
return stanza.getTo();
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@ import org.jivesoftware.smack.packet.Stanza;
|
|||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
public final class ToTypeFilter extends AbstractJidTypeFilter {
|
||||
public final class ToTypeFilter extends AbstractExactJidTypeFilter {
|
||||
|
||||
public static final ToTypeFilter ENTITY_FULL_JID = new ToTypeFilter(JidType.entityFull);
|
||||
public static final ToTypeFilter ENTITY_BARE_JID = new ToTypeFilter(JidType.entityBare);
|
||||
|
|
Loading…
Reference in a new issue