From 2375c59791548dc162f70b04b086fc81bc7848cb Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 28 Apr 2014 20:22:46 +0200 Subject: [PATCH] Extend JivePropertiesManager with getPropertiesNames() and getProperties() --- .../jiveproperties/JivePropertiesManager.java | 34 +++++++++++++++++++ .../packet/JivePropertiesExtension.java | 14 +++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/JivePropertiesManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/JivePropertiesManager.java index 83645fc25..2c9bae640 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/JivePropertiesManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/JivePropertiesManager.java @@ -16,6 +16,10 @@ */ package org.jivesoftware.smackx.jiveproperties; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension; @@ -74,4 +78,34 @@ public class JivePropertiesManager { } return res; } + + /** + * Return a collection of the names of all properties of the given packet. If the packet + * contains no properties extension, then an empty collection will be returned. + * + * @param packet + * @return a collection of the names of all properties. + */ + public static Collection getPropertiesNames(Packet packet) { + JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE); + if (jpe == null) { + return Collections.emptyList(); + } + return jpe.getPropertyNames(); + } + + /** + * Return a map of all properties of the given packet. If the packet contains no properties + * extension, an empty map will be returned. + * + * @param packet + * @return a map of all properties of the given packet. + */ + public static Map getProperties(Packet packet) { + JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE); + if (jpe == null) { + return Collections.emptyMap(); + } + return jpe.getProperties(); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/packet/JivePropertiesExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/packet/JivePropertiesExtension.java index 824e40400..be50315f6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/packet/JivePropertiesExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/packet/JivePropertiesExtension.java @@ -111,7 +111,19 @@ public class JivePropertiesExtension implements PacketExtension { } return Collections.unmodifiableSet(new HashSet(properties.keySet())); } - + + /** + * Returns an unmodifiable map of all properties. + * + * @return all properties. + */ + public synchronized Map getProperties() { + if (properties == null) { + return Collections.emptyMap(); + } + return Collections.unmodifiableMap(new HashMap(properties)); + } + @Override public String getElementName() { return ELEMENT;