mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
Extend JivePropertiesManager
with getPropertiesNames() and getProperties()
This commit is contained in:
parent
91fd15ad86
commit
2375c59791
2 changed files with 47 additions and 1 deletions
|
@ -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<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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,19 @@ public class JivePropertiesExtension implements PacketExtension {
|
|||
}
|
||||
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
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
|
|
Loading…
Reference in a new issue