1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 21:42:07 +01:00

Extend JivePropertiesManager

with getPropertiesNames() and getProperties()
This commit is contained in:
Florian Schmaus 2014-04-28 20:22:46 +02:00
parent 91fd15ad86
commit 2375c59791
2 changed files with 47 additions and 1 deletions

View file

@ -16,6 +16,10 @@
*/ */
package org.jivesoftware.smackx.jiveproperties; 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.smack.packet.Packet;
import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension; import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension;
@ -74,4 +78,34 @@ public class JivePropertiesManager {
} }
return res; 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<String> 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<String, Object> getProperties(Packet packet) {
JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE);
if (jpe == null) {
return Collections.emptyMap();
}
return jpe.getProperties();
}
} }

View file

@ -111,7 +111,19 @@ public class JivePropertiesExtension implements PacketExtension {
} }
return Collections.unmodifiableSet(new HashSet<String>(properties.keySet())); return Collections.unmodifiableSet(new HashSet<String>(properties.keySet()));
} }
/**
* Returns an unmodifiable map of all properties.
*
* @return all properties.
*/
public synchronized Map<String, Object> getProperties() {
if (properties == null) {
return Collections.emptyMap();
}
return Collections.unmodifiableMap(new HashMap<String, Object>(properties));
}
@Override @Override
public String getElementName() { public String getElementName() {
return ELEMENT; return ELEMENT;