private List<Subscription> getSubscriptions(SubscriptionsNamespace subscriptionsNamespace, List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSubElementType pubSubElementType = subscriptionsNamespace.type; PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(pubSubElementType, getId())); if (additionalExtensions != null) { for (ExtensionElement pe : additionalExtensions) { pubSub.addExtension(pe); } } PubSub reply = sendPubsubPacket(pubSub); if (returnedExtensions != null) { returnedExtensions.addAll(reply.getExtensions()); } SubscriptionsExtension subElem = reply.getExtension(pubSubElementType); return subElem.getSubscriptions(); }
@SuppressWarnings("unchecked") @Override protected SubscriptionsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) { SubscriptionsNamespace subscriptionsNamespace = SubscriptionsNamespace.fromXmlns(currentNamespace); String nodeId = attributeMap.get("node"); return new SubscriptionsExtension(subscriptionsNamespace, nodeId, (List<Subscription>) content); }
@Override public CharSequence toXML(String enclosingNamespace) { if ((items == null) || (items.size() == 0)) { return super.toXML(enclosingNamespace); } else { StringBuilder builder = new StringBuilder("<"); builder.append(getElementName()); if (getNode() != null) { builder.append(" node='"); builder.append(getNode()); builder.append('\''); } builder.append('>'); for (Subscription item : items) { builder.append(item.toXML(null)); } builder.append("</"); builder.append(getElementName()); builder.append('>'); return builder.toString(); } } }
builder.append(getElementName()); if (getNode() != null) builder.append(getNode()); builder.append("'"); builder.append(getElementName()); builder.append(">"); return builder.toString();
/** * Gets the subscriptions on the root node. * * @return List of exceptions * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Stanza reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS), null); SubscriptionsExtension subElem = reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns()); return subElem.getSubscriptions(); }
/** * Modify the subscriptions for this PubSub node as owner. * <p> * Note that the subscriptions are _not_ checked against the existing subscriptions * since these are not cached (and indeed could change asynchronously) * </p> * * @param changedSubs subscriptions that have changed * @return <code>null</code> or a PubSub stanza with additional information on success. * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException * @see <a href="https://xmpp.org/extensions/xep-0060.html#owner-subscriptions-modify">XEP-60 ยง 8.8.2 Modify Subscriptions</a> * @since 4.3 */ public PubSub modifySubscriptionsAsOwner(List<Subscription> changedSubs) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub pubSub = createPubsubPacket(Type.set, new SubscriptionsExtension(SubscriptionsNamespace.owner, getId(), changedSubs)); return sendPubsubPacket(pubSub); }
builder.append(getElementName()); if (getNode() != null) builder.append(getNode()); builder.append("'"); builder.append(getElementName()); builder.append(">"); return builder.toString();
@Test public void subscriptionsOwnerResultTest() throws Exception { // @formatter:off final String resultStanza = "<iq from='pubsub.example.org' to='julia@example.org/Smack' id='HaT4m-13' type='result'>" + "<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>" + "<subscriptions node='test'>" + "<subscription jid='foo@example.org/Smack' subscription='subscribed' subid='58C1A6F99F2A7'/>" + "<subscription jid='julia@example.org/Smack' subscription='subscribed' subid='58C18F8917321'/>" + "</subscriptions>" + "</pubsub>" + "</iq>"; // @formatter:on XmlPullParser parser = TestUtils.getIQParser(resultStanza); PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser); SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS_OWNER); List<Subscription> subscriptions = subElem.getSubscriptions(); assertEquals(2, subscriptions.size()); Subscription sub1 = subscriptions.get(0); assertThat("foo@example.org/Smack", equalsCharSequence(sub1.getJid())); assertEquals(Subscription.State.subscribed, sub1.getState()); assertEquals("58C1A6F99F2A7", sub1.getId()); Subscription sub2 = subscriptions.get(1); assertThat("julia@example.org/Smack", equalsCharSequence(sub2.getJid())); assertEquals(Subscription.State.subscribed, sub2.getState()); assertEquals("58C18F8917321", sub2.getId()); } }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new SubscriptionsExtension(attributeMap.get("node"), (List<Subscription>)content); }
builder.append(getElementName()); if (getNode() != null) builder.append(getNode()); builder.append("'"); builder.append(getElementName()); builder.append(">"); return builder.toString();
@Test public void modifySubscriptionsAsOwnerTest() throws InterruptedException, SmackException, IOException, XMPPException, Exception { ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); PubSubManager mgr = new PubSubManager(con, JidTestUtil.PUBSUB_EXAMPLE_ORG); Node testNode = new LeafNode(mgr, "princely_musings"); List<Subscription> ChangeSubs = Arrays.asList( new Subscription(JidCreate.from("romeo@montague.org"), Subscription.State.subscribed), new Subscription(JidCreate.from("juliet@capulet.org"), Subscription.State.none) ); testNode.modifySubscriptionsAsOwner(ChangeSubs); PubSub request = con.getSentPacket(); assertEquals("http://jabber.org/protocol/pubsub#owner", request.getChildElementNamespace()); assertEquals("pubsub", request.getChildElementName()); XmlPullParser parser = TestUtils.getIQParser(request.toXML(null).toString()); PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser); SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS_OWNER); List<Subscription> subscriptions = subElem.getSubscriptions(); assertEquals(2, subscriptions.size()); Subscription sub1 = subscriptions.get(0); assertEquals("romeo@montague.org", sub1.getJid().toString()); assertEquals(Subscription.State.subscribed, sub1.getState()); Subscription sub2 = subscriptions.get(1); assertEquals("juliet@capulet.org", sub2.getJid().toString()); assertEquals(Subscription.State.none, sub2.getState()); }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new SubscriptionsExtension(attributeMap.get("node"), (List<Subscription>)content); }
/** * Get the subscriptions currently associated with this node. * * @return List of {@link Subscription} * * @throws XMPPException */ public List<Subscription> getSubscriptions() throws XMPPException { PubSub reply = (PubSub)sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId())); SubscriptionsExtension subElem = (SubscriptionsExtension)reply.getExtension(PubSubElementType.SUBSCRIPTIONS); return subElem.getSubscriptions(); }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new SubscriptionsExtension(attributeMap.get("node"), (List<Subscription>)content); }
/** * Get the subscriptions currently associated with this node. * * @return List of {@link Subscription} * * @throws XMPPException */ public List<Subscription> getSubscriptions() throws XMPPException { PubSub reply = (PubSub)sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId())); SubscriptionsExtension subElem = (SubscriptionsExtension)reply.getExtension(PubSubElementType.SUBSCRIPTIONS); return subElem.getSubscriptions(); }
/** * Get the subscriptions currently associated with this node. * * @return List of {@link Subscription} * * @throws XMPPException */ public List<Subscription> getSubscriptions() throws XMPPException { PubSub reply = (PubSub)sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId())); SubscriptionsExtension subElem = (SubscriptionsExtension)reply.getExtension(PubSubElementType.SUBSCRIPTIONS); return subElem.getSubscriptions(); }
/** * Gets the subscriptions on the root node. * * @return List of exceptions * * @throws XMPPException */ public List<Subscription> getSubscriptions() throws XMPPException { Packet reply = sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.SUBSCRIPTIONS)); SubscriptionsExtension subElem = (SubscriptionsExtension)reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns()); return subElem.getSubscriptions(); }
/** * Gets the subscriptions on the root node. * * @return List of exceptions * * @throws XMPPException */ public List<Subscription> getSubscriptions() throws XMPPException { Packet reply = sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.SUBSCRIPTIONS)); SubscriptionsExtension subElem = (SubscriptionsExtension)reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns()); return subElem.getSubscriptions(); }
/** * Gets the subscriptions on the root node. * * @return List of exceptions * * @throws XMPPException */ public List<Subscription> getSubscriptions() throws XMPPException { Packet reply = sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.SUBSCRIPTIONS)); SubscriptionsExtension subElem = (SubscriptionsExtension)reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns()); return subElem.getSubscriptions(); }