mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Validate ProviderManager arguments
This commit is contained in:
parent
a3de2ecc25
commit
5fcfe548f9
1 changed files with 13 additions and 0 deletions
|
@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
import org.jivesoftware.smack.SmackConfiguration;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jxmpp.util.XmppStringUtils;
|
import org.jxmpp.util.XmppStringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,6 +203,7 @@ public final class ProviderManager {
|
||||||
public static void addIQProvider(String elementName, String namespace,
|
public static void addIQProvider(String elementName, String namespace,
|
||||||
Object provider)
|
Object provider)
|
||||||
{
|
{
|
||||||
|
validate(elementName, namespace);
|
||||||
// First remove existing providers
|
// First remove existing providers
|
||||||
String key = removeIQProvider(elementName, namespace);
|
String key = removeIQProvider(elementName, namespace);
|
||||||
if (provider instanceof IQProvider) {
|
if (provider instanceof IQProvider) {
|
||||||
|
@ -272,6 +274,7 @@ public final class ProviderManager {
|
||||||
public static void addExtensionProvider(String elementName, String namespace,
|
public static void addExtensionProvider(String elementName, String namespace,
|
||||||
Object provider)
|
Object provider)
|
||||||
{
|
{
|
||||||
|
validate(elementName, namespace);
|
||||||
// First remove existing providers
|
// First remove existing providers
|
||||||
String key = removeExtensionProvider(elementName, namespace);
|
String key = removeExtensionProvider(elementName, namespace);
|
||||||
if (provider instanceof PacketExtensionProvider) {
|
if (provider instanceof PacketExtensionProvider) {
|
||||||
|
@ -320,6 +323,7 @@ public final class ProviderManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addStreamFeatureProvider(String elementName, String namespace, PacketExtensionProvider<PacketExtension> provider) {
|
public static void addStreamFeatureProvider(String elementName, String namespace, PacketExtensionProvider<PacketExtension> provider) {
|
||||||
|
validate(elementName, namespace);
|
||||||
String key = getKey(elementName, namespace);
|
String key = getKey(elementName, namespace);
|
||||||
streamFeatureProviders.put(key, provider);
|
streamFeatureProviders.put(key, provider);
|
||||||
}
|
}
|
||||||
|
@ -332,4 +336,13 @@ public final class ProviderManager {
|
||||||
private static String getKey(String elementName, String namespace) {
|
private static String getKey(String elementName, String namespace) {
|
||||||
return XmppStringUtils.generateKey(elementName, namespace);
|
return XmppStringUtils.generateKey(elementName, namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void validate(String elementName, String namespace) {
|
||||||
|
if (StringUtils.isNullOrEmpty(elementName)) {
|
||||||
|
throw new IllegalArgumentException("elementName must not be null or empty");
|
||||||
|
}
|
||||||
|
if (StringUtils.isNullOrEmpty(namespace)) {
|
||||||
|
throw new IllegalArgumentException("namespace must not be null or empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue