mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-12 14:01:08 +01:00
Refactor PEP to use PubSub API.
Fixes SMACK-416.
This commit is contained in:
parent
0d6f00873f
commit
33e5c37af8
17 changed files with 479 additions and 453 deletions
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
*
|
||||
* 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.smackx.disco;
|
||||
|
||||
/**
|
||||
* Utility class for Features.
|
||||
*
|
||||
* @author Florian Schmaus
|
||||
*
|
||||
*/
|
||||
public class Feature {
|
||||
|
||||
public enum Support {
|
||||
optional,
|
||||
recommended,
|
||||
required,
|
||||
;
|
||||
|
||||
public boolean isRequired() {
|
||||
return this == required;
|
||||
}
|
||||
|
||||
public boolean isNotRequired() {
|
||||
return !isRequired();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,6 +41,8 @@ import org.jxmpp.util.cache.Cache;
|
|||
import org.jxmpp.util.cache.ExpirationCache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
|
|
@ -659,9 +661,20 @@ public final class ServiceDiscoveryManager extends Manager {
|
|||
* @throws InterruptedException
|
||||
* @since 4.1
|
||||
*/
|
||||
public boolean serverSupportsFeature(String feature) throws NoResponseException, XMPPErrorException,
|
||||
public boolean serverSupportsFeature(CharSequence feature) throws NoResponseException, XMPPErrorException,
|
||||
NotConnectedException, InterruptedException {
|
||||
return supportsFeature(connection().getXMPPServiceDomain(), feature);
|
||||
return serverSupportsFeatures(feature);
|
||||
}
|
||||
|
||||
public boolean serverSupportsFeatures(CharSequence... features) throws NoResponseException,
|
||||
XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return serverSupportsFeatures(Arrays.asList(features));
|
||||
}
|
||||
|
||||
public boolean serverSupportsFeatures(Collection<? extends CharSequence> features)
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException,
|
||||
InterruptedException {
|
||||
return supportsFeatures(connection().getXMPPServiceDomain(), features);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -675,9 +688,22 @@ public final class ServiceDiscoveryManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public boolean supportsFeature(Jid jid, String feature) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public boolean supportsFeature(Jid jid, CharSequence feature) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return supportsFeatures(jid, feature);
|
||||
}
|
||||
|
||||
public boolean supportsFeatures(Jid jid, CharSequence... features) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return supportsFeatures(jid, Arrays.asList(features));
|
||||
}
|
||||
|
||||
public boolean supportsFeatures(Jid jid, Collection<? extends CharSequence> features) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
DiscoverInfo result = discoverInfo(jid);
|
||||
return result.containsFeature(feature);
|
||||
for (CharSequence feature : features) {
|
||||
if (!result.containsFeature(feature)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ public class DiscoverInfo extends IQ implements TypedCloneable<DiscoverInfo> {
|
|||
* @param feature the feature to check
|
||||
* @return true if the requestes feature has been discovered
|
||||
*/
|
||||
public boolean containsFeature(String feature) {
|
||||
public boolean containsFeature(CharSequence feature) {
|
||||
return features.contains(new Feature(feature));
|
||||
}
|
||||
|
||||
|
|
@ -482,6 +482,10 @@ public class DiscoverInfo extends IQ implements TypedCloneable<DiscoverInfo> {
|
|||
this.variable = feature.variable;
|
||||
}
|
||||
|
||||
public Feature(CharSequence variable) {
|
||||
this(variable.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new feature offered by an XMPP entity or item.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue