From 16ede9806a7350cda4b8aecd44e3965613f16ce9 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 6 Apr 2017 12:32:34 +0200 Subject: [PATCH] Add PubSubManaer.supportsAutomaticNodeCreation() --- .../smackx/pubsub/PubSubManager.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java index a5caf0352..3fa1832c2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java @@ -64,6 +64,8 @@ import org.jxmpp.stringprep.XmppStringprepException; */ public final class PubSubManager extends Manager { + public static final String AUTO_CREATE_FEATURE = "http://jabber.org/protocol/pubsub#auto-create"; + private static final Logger LOGGER = Logger.getLogger(PubSubManager.class.getName()); private static final Map> INSTANCES = new WeakHashMap<>(); @@ -325,6 +327,10 @@ public final class PubSubManager extends Manager { /** * Try to publish an item and, if the node with the given ID does not exists, auto-create the node. + *

+ * Not every PubSub service supports automatic node creation. You can discover if this service supports it by using + * {@link #supportsAutomaticNodeCreation()}. + *

* * @param id The unique id of the node. * @param item The item to publish. @@ -464,6 +470,23 @@ public final class PubSubManager extends Manager { return mgr.discoverInfo(pubSubService); } + /** + * Check if the PubSub service supports automatic node creation. + * + * @return true if the PubSub service supports automatic node creation. + * @throws NoResponseException + * @throws XMPPErrorException + * @throws NotConnectedException + * @throws InterruptedException + * @since 4.2.1 + * @see XEP-0060 ยง 7.1.4 Automatic Node Creation + */ + public boolean supportsAutomaticNodeCreation() + throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); + return sdm.supportsFeature(pubSubService, AUTO_CREATE_FEATURE); + } + /** * Check if it is possible to create PubSub nodes on this service. It could be possible that the * PubSub service allows only certain XMPP entities (clients) to create nodes and publish items