思特奇智慧酒店云平台 v0.0.5版本的 MD5 值为:dedb172bb322639d79d7e0e26262fb5c
以下内容为反编译后的 PubSubManager.java 源代码,内容仅作参考
package org.jivesoftware.smackx.pubsub;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.EmptyResultIQ;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.StanzaError;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.pubsub.PubSubException;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.jivesoftware.smackx.pubsub.util.NodeUtils;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
public final class PubSubManager extends Manager {
public static final String AUTO_CREATE_FEATURE = "http://jabber.org/protocol/pubsub#auto-create";
public final Map<String, Node> nodeMap;
public final pw3 pubSubService;
public static final Logger LOGGER = Logger.getLogger(PubSubManager.class.getName());
public static final Map<XMPPConnection, Map<pw3, PubSubManager>> INSTANCES = new WeakHashMap();
public PubSubManager(XMPPConnection xMPPConnection, pw3 pw3Var) {
super(xMPPConnection);
this.nodeMap = new ConcurrentHashMap();
this.pubSubService = pw3Var;
}
public static PubSubManager getInstance(XMPPConnection xMPPConnection) {
qw3 pubSubService;
if (xMPPConnection.isAuthenticated()) {
try {
pubSubService = getPubSubService(xMPPConnection);
} catch (InterruptedException e) {
LOGGER.log(Level.FINE, "Interrupted while trying to determine PubSub service", (Throwable) e);
} catch (SmackException.NoResponseException e2) {
e = e2;
LOGGER.log(Level.WARNING, "Could not determine PubSub service", e);
pubSubService = null;
if (pubSubService == null) {
}
return getInstance(xMPPConnection, pubSubService);
} catch (SmackException.NotConnectedException e3) {
e = e3;
LOGGER.log(Level.WARNING, "Could not determine PubSub service", e);
pubSubService = null;
if (pubSubService == null) {
}
return getInstance(xMPPConnection, pubSubService);
} catch (XMPPException.XMPPErrorException e4) {
e = e4;
LOGGER.log(Level.WARNING, "Could not determine PubSub service", e);
pubSubService = null;
if (pubSubService == null) {
}
return getInstance(xMPPConnection, pubSubService);
}
if (pubSubService == null) {
try {
pubSubService = bx3.b("pubsub." + ((Object) xMPPConnection.getXMPPServiceDomain()));
} catch (lx3 e5) {
throw new RuntimeException(e5);
}
}
return getInstance(xMPPConnection, pubSubService);
}
pubSubService = null;
if (pubSubService == null) {
}
return getInstance(xMPPConnection, pubSubService);
}
private LeafNode getLeafNodeProsodyWorkaround(String str) throws SmackException.NoResponseException, SmackException.NotConnectedException, InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException {
LeafNode leafNode = new LeafNode(this, str);
try {
leafNode.getItems(1);
this.nodeMap.put(str, leafNode);
return leafNode;
} catch (XMPPException.XMPPErrorException e) {
if (e.getStanzaError().getCondition() == StanzaError.Condition.feature_not_implemented) {
throw new PubSubException.NotALeafNodeException(str, this.pubSubService);
}
throw e;
}
}
private LeafNode getOrCreateLeafNodeProsodyWorkaround(String str) throws XMPPException.XMPPErrorException, SmackException.NoResponseException, SmackException.NotConnectedException, InterruptedException, PubSubException.NotALeafNodeException {
try {
return createNode(str);
} catch (XMPPException.XMPPErrorException e) {
if (e.getStanzaError().getCondition() == StanzaError.Condition.conflict) {
return getLeafNodeProsodyWorkaround(str);
}
throw e;
}
}
public static qw3 getPubSubService(XMPPConnection xMPPConnection) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(xMPPConnection).findService(PubSub.NAMESPACE, true, PubSub.ELEMENT, "service");
}
private PubSub sendPubsubPacket(IQ.Type type, ExtensionElement extensionElement, PubSubNamespace pubSubNamespace) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return sendPubsubPacket(this.pubSubService, type, Collections.singletonList(extensionElement), pubSubNamespace);
}
public boolean canCreateNodesAndPublishItems() throws SmackException.NoResponseException, SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException {
try {
LeafNode createNode = createNode();
if (createNode != null) {
deleteNode(createNode.getId());
return true;
}
return true;
} catch (XMPPException.XMPPErrorException e) {
if (e.getStanzaError().getCondition() == StanzaError.Condition.forbidden) {
return false;
}
throw e;
}
}
public LeafNode createNode() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
LeafNode leafNode = new LeafNode(this, ((NodeExtension) sendPubsubPacket(IQ.Type.set, new NodeExtension(PubSubElementType.CREATE), null).getExtension("create", PubSubNamespace.basic.getXmlns())).getNode());
this.nodeMap.put(leafNode.getId(), leafNode);
return leafNode;
}
public void deleteNode(String str) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
sendPubsubPacket(IQ.Type.set, new NodeExtension(PubSubElementType.DELETE, str), PubSubElementType.DELETE.getNamespace());
this.nodeMap.remove(str);
}
public DiscoverItems discoverNodes(String str) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
DiscoverItems discoverItems = new DiscoverItems();
if (str != null) {
discoverItems.setNode(str);
}
discoverItems.setTo(this.pubSubService);
return (DiscoverItems) connection().createStanzaCollectorAndSend(discoverItems).nextResultOrThrow();
}
public List<Affiliation> getAffiliations() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return ((AffiliationsExtension) sendPubsubPacket(IQ.Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS), null).getExtension(PubSubElementType.AFFILIATIONS)).getAffiliations();
}
public XMPPConnection getConnection() {
return connection();
}
public ConfigureForm getDefaultConfiguration() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return NodeUtils.getFormFromPacket(sendPubsubPacket(IQ.Type.get, new NodeExtension(PubSubElementType.DEFAULT), PubSubElementType.DEFAULT.getNamespace()), PubSubElementType.DEFAULT);
}
public LeafNode getLeafNode(String str) throws PubSubException.NotALeafNodeException, SmackException.NoResponseException, SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, PubSubException.NotAPubSubNodeException {
try {
Node node = getNode(str);
if (node instanceof LeafNode) {
return (LeafNode) node;
}
throw new PubSubException.NotALeafNodeException(str, this.pubSubService);
} catch (XMPPException.XMPPErrorException e) {
if (e.getStanzaError().getCondition() == StanzaError.Condition.service_unavailable) {
return getLeafNodeProsodyWorkaround(str);
}
throw e;
}
}
public <T extends Node> T getNode(String str) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, PubSubException.NotAPubSubNodeException {
T t = (T) this.nodeMap.get(str);
if (t == null) {
DiscoverInfo discoverInfo = new DiscoverInfo();
discoverInfo.setTo(this.pubSubService);
discoverInfo.setNode(str);
DiscoverInfo discoverInfo2 = (DiscoverInfo) connection().createStanzaCollectorAndSend(discoverInfo).nextResultOrThrow();
if (discoverInfo2.hasIdentity(PubSub.ELEMENT, "leaf")) {
t = new LeafNode(this, str);
} else if (discoverInfo2.hasIdentity(PubSub.ELEMENT, "collection")) {
t = new CollectionNode(this, str);
} else {
throw new PubSubException.NotAPubSubNodeException(str, discoverInfo2);
}
this.nodeMap.put(str, t);
}
return t;
}
public LeafNode getOrCreateLeafNode(String str) throws SmackException.NoResponseException, SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException {
try {
return (LeafNode) getNode(str);
} catch (XMPPException.XMPPErrorException e) {
if (e.getStanzaError().getCondition() == StanzaError.Condition.item_not_found) {
try {
return createNode(str);
} catch (XMPPException.XMPPErrorException e2) {
if (e2.getStanzaError().getCondition() == StanzaError.Condition.conflict) {
try {
return (LeafNode) getNode(str);
} catch (PubSubException.NotAPubSubNodeException e3) {
throw new IllegalStateException(e3);
}
}
throw e2;
}
} else if (e.getStanzaError().getCondition() == StanzaError.Condition.service_unavailable) {
Logger logger = LOGGER;
logger.warning("The PubSub service " + ((Object) this.pubSubService) + " threw an DiscoInfoNodeAssertionError, trying workaround for Prosody bug #805 (https://prosody.im/issues/issue/805)");
return getOrCreateLeafNodeProsodyWorkaround(str);
} else {
throw e;
}
} catch (PubSubException.NotAPubSubNodeException unused) {
return createNode(str);
}
}
public pw3 getServiceJid() {
return this.pubSubService;
}
public List<Subscription> getSubscriptions() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return ((SubscriptionsExtension) sendPubsubPacket(IQ.Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS), null).getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns())).getSubscriptions();
}
public DiscoverInfo getSupportedFeatures() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).discoverInfo(this.pubSubService);
}
public boolean supportsAutomaticNodeCreation() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(this.pubSubService, AUTO_CREATE_FEATURE);
}
public <I extends Item> LeafNode tryToPublishAndPossibleAutoCreate(String str, I i) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
LeafNode leafNode = new LeafNode(this, str);
leafNode.publish((LeafNode) i);
this.nodeMap.put(str, leafNode);
return leafNode;
}
public PubSub sendPubsubPacket(xw3 xw3Var, IQ.Type type, List<ExtensionElement> list, PubSubNamespace pubSubNamespace) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
PubSub pubSub = new PubSub(xw3Var, type, pubSubNamespace);
for (ExtensionElement extensionElement : list) {
pubSub.addExtension(extensionElement);
}
return sendPubsubPacket(pubSub);
}
public LeafNode createNode(String str) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return (LeafNode) createNode(str, null);
}
public Node createNode(String str, Form form) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
boolean z;
PubSub createPubsubPacket = PubSub.createPubsubPacket(this.pubSubService, IQ.Type.set, new NodeExtension(PubSubElementType.CREATE, str));
if (form != null) {
createPubsubPacket.addExtension(new FormNode(FormNodeType.CONFIGURE, form));
FormField field = form.getField(ConfigureNodeFields.node_type.getFieldName());
if (field != null) {
z = field.getValues().get(0).equals(NodeType.leaf.toString());
sendPubsubPacket(createPubsubPacket);
Node leafNode = !z ? new LeafNode(this, str) : new CollectionNode(this, str);
this.nodeMap.put(leafNode.getId(), leafNode);
return leafNode;
}
}
z = true;
sendPubsubPacket(createPubsubPacket);
if (!z) {
}
this.nodeMap.put(leafNode.getId(), leafNode);
return leafNode;
}
public PubSub sendPubsubPacket(PubSub pubSub) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
IQ iq = (IQ) connection().createStanzaCollectorAndSend(pubSub).nextResultOrThrow();
if (iq instanceof EmptyResultIQ) {
return null;
}
return (PubSub) iq;
}
public static synchronized PubSubManager getInstance(XMPPConnection xMPPConnection, pw3 pw3Var) {
PubSubManager pubSubManager;
synchronized (PubSubManager.class) {
Map<pw3, PubSubManager> map = INSTANCES.get(xMPPConnection);
if (map == null) {
map = new HashMap<>();
INSTANCES.put(xMPPConnection, map);
}
pubSubManager = map.get(pw3Var);
if (pubSubManager == null) {
pubSubManager = new PubSubManager(xMPPConnection, pw3Var);
map.put(pw3Var, pubSubManager);
}
}
return pubSubManager;
}
}