CryptoMessage v1.3.2版本的 MD5 值为:66c611ce56a11450659dc23697562928
以下内容为反编译后的 JivePropertiesExtension.java 源代码,内容仅作参考
package org.jivesoftware.smackx.jiveproperties.packet;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.jivesoftware.smackx.xdata.FormField;
public class JivePropertiesExtension implements ExtensionElement {
private final Map<String, Object> properties;
public static final String NAMESPACE = "http://www.jivesoftware.com/xmlns/xmpp/properties";
public static final String ELEMENT = "properties";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private static final Logger LOGGER = Logger.getLogger(JivePropertiesExtension.class.getName());
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
public JivePropertiesExtension() {
this.properties = new HashMap();
}
public JivePropertiesExtension(Map<String, Object> map) {
this.properties = map;
}
public synchronized Object getProperty(String str) {
Map<String, Object> map = this.properties;
if (map == null) {
return null;
}
return map.get(str);
}
public synchronized void setProperty(String str, Object obj) {
if (!(obj instanceof Serializable)) {
throw new IllegalArgumentException("Value must be serializable");
}
this.properties.put(str, obj);
}
public synchronized void deleteProperty(String str) {
Map<String, Object> map = this.properties;
if (map == null) {
return;
}
map.remove(str);
}
public synchronized Collection<String> getPropertyNames() {
if (this.properties == null) {
return Collections.emptySet();
}
return Collections.unmodifiableSet(new HashSet(this.properties.keySet()));
}
public synchronized Map<String, Object> getProperties() {
if (this.properties == null) {
return Collections.emptyMap();
}
return Collections.unmodifiableMap(new HashMap(this.properties));
}
@Override
public CharSequence toXML(XmlEnvironment xmlEnvironment) {
String str;
XmlStringBuilder xmlStringBuilder = new XmlStringBuilder((FullyQualifiedElement) this);
xmlStringBuilder.rightAngleBracket();
for (String str2 : getPropertyNames()) {
Object property = getProperty(str2);
xmlStringBuilder.openElement("property");
xmlStringBuilder.element("name", str2);
xmlStringBuilder.halfOpenElement(FormField.Value.ELEMENT);
String str3 = "java-object";
if (property instanceof Integer) {
str = Integer.toString(((Integer) property).intValue());
str3 = "integer";
} else if (property instanceof Long) {
str = Long.toString(((Long) property).longValue());
str3 = "long";
} else if (property instanceof Float) {
str = Float.toString(((Float) property).floatValue());
str3 = "float";
} else if (property instanceof Double) {
str = Double.toString(((Double) property).doubleValue());
str3 = "double";
} else if (property instanceof Boolean) {
str = Boolean.toString(((Boolean) property).booleanValue());
str3 = "boolean";
} else if (property instanceof String) {
str = (String) property;
str3 = "string";
} else {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
try {
objectOutputStream.writeObject(property);
str = Base64.encodeToString(byteArrayOutputStream.toByteArray());
$closeResource(null, objectOutputStream);
$closeResource(null, byteArrayOutputStream);
} catch (Throwable th) {
try {
throw th;
break;
} catch (Throwable th2) {
$closeResource(th, objectOutputStream);
throw th2;
break;
}
}
} finally {
try {
break;
} catch (Throwable th3) {
}
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error encoding java object", (Throwable) e);
str = "Serializing error: " + e.getMessage();
}
}
xmlStringBuilder.attribute("type", str3);
xmlStringBuilder.rightAngleBracket();
xmlStringBuilder.escape(str);
xmlStringBuilder.closeElement(FormField.Value.ELEMENT);
xmlStringBuilder.closeElement("property");
}
xmlStringBuilder.closeElement(this);
return xmlStringBuilder;
}
private static void $closeResource(Throwable th, AutoCloseable autoCloseable) {
if (th == null) {
autoCloseable.close();
return;
}
try {
autoCloseable.close();
} catch (Throwable th2) {
th.addSuppressed(th2);
}
}
public static JivePropertiesExtension from(Message message) {
return (JivePropertiesExtension) message.getExtension(JivePropertiesExtension.class);
}
}