Java Code Examples for org.jivesoftware.smackx.pubsub.packet.PubSub#addExtension()
The following examples show how to use
org.jivesoftware.smackx.pubsub.packet.PubSub#addExtension() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PubSubManager.java From Smack with Apache License 2.0 | 6 votes |
/** * Creates a node with specified configuration. * * Note: This is the only way to create a collection node. * * @param nodeId The name of the node, which must be unique within the * pubsub service * @param config The configuration for the node * @return The node that was created * @throws XMPPErrorException if there was an XMPP error returned. * @throws NoResponseException if there was no response from the remote entity. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public Node createNode(String nodeId, FillableConfigureForm config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub request = PubSub.createPubsubPacket(pubSubService, Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId)); boolean isLeafNode = true; if (config != null) { DataForm submitForm = config.getDataFormToSubmit(); request.addExtension(new FormNode(FormNodeType.CONFIGURE, submitForm)); NodeType nodeType = config.getNodeType(); // Note that some implementations do to have the pubsub#node_type field in their defauilt configuration, // which I believe to be a bug. However, since PubSub specifies the default node type to be 'leaf' we assume // leaf if the field does not exist. isLeafNode = nodeType == null || nodeType == NodeType.leaf; } // Errors will cause exceptions in getReply, so it only returns // on success. sendPubsubPacket(request); Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId); nodeMap.put(newNode.getId(), newNode); return newNode; }
Example 2
Source File: Node.java From Smack with Apache License 2.0 | 6 votes |
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(); }
Example 3
Source File: Node.java From Smack with Apache License 2.0 | 6 votes |
private List<Affiliation> getAffiliations(AffiliationNamespace affiliationsNamespace, List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSubElementType pubSubElementType = affiliationsNamespace.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()); } AffiliationsExtension affilElem = reply.getExtension(pubSubElementType); return affilElem.getAffiliations(); }
Example 4
Source File: PubSubManager.java From Smack with Apache License 2.0 | 5 votes |
PubSub sendPubsubPacket(Jid to, Type type, List<ExtensionElement> extList, PubSubNamespace ns) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { // CHECKSTYLE:OFF PubSub pubSub = new PubSub(to, type, ns); for (ExtensionElement pe : extList) { pubSub.addExtension(pe); } // CHECKSTYLE:ON return sendPubsubPacket(pubSub); }
Example 5
Source File: PubSubNodeTest.java From Smack with Apache License 2.0 | 5 votes |
@Test public void getAffiliationsAsOwnerTest() throws InterruptedException, SmackException, IOException, XMPPException, Exception { Protocol protocol = new Protocol(); XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, JidTestUtil.FULL_JID_1_RESOURCE_1); PubSubManager mgr = new PubSubManager(connection, JidTestUtil.PUBSUB_EXAMPLE_ORG); Node testNode = new LeafNode(mgr, "princely_musings"); List<Affiliation> affiliations = Arrays.asList( new Affiliation(JidTestUtil.BARE_JID_1, Affiliation.Type.member), new Affiliation(JidTestUtil.BARE_JID_2, Affiliation.Type.publisher) ); AffiliationsExtension affiliationsExtension = new AffiliationsExtension(AffiliationNamespace.owner, affiliations); PubSub response = new PubSub(JidTestUtil.PUBSUB_EXAMPLE_ORG, Type.result, PubSubNamespace.owner); response.addExtension(affiliationsExtension); protocol.addResponse(response); List<Affiliation> returnedAffiliations = testNode.getAffiliationsAsOwner(); PubSub request = (PubSub) protocol.getRequests().get(0); assertEquals("http://jabber.org/protocol/pubsub#owner", request.getChildElementNamespace()); assertEquals("pubsub", request.getChildElementName()); Affiliation affiliationOne = returnedAffiliations.get(0); assertEquals(affiliationOne.getJid(), JidTestUtil.BARE_JID_1); assertEquals(affiliationOne.getAffiliation(), Affiliation.Type.member); Affiliation affiliationTwo = returnedAffiliations.get(1); assertEquals(affiliationTwo.getJid(), JidTestUtil.BARE_JID_2); assertEquals(affiliationTwo.getAffiliation(), Affiliation.Type.publisher); }
Example 6
Source File: Node.java From Smack with Apache License 2.0 | 3 votes |
/** * The user subscribes to the node using the supplied jid and subscription * options. The bare jid portion of this one must match the jid for the * connection. * * Please note that the {@link Subscription.State} should be checked * on return since more actions may be required by the caller. * {@link Subscription.State#pending} - The owner must approve the subscription * request before messages will be received. * {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true, * the caller must configure the subscription before messages will be received. If it is false * the caller can configure it but is not required to do so. * * @param jid The jid to subscribe as. * @param subForm TODO javadoc me please * * @return The subscription * @throws XMPPErrorException if there was an XMPP error returned. * @throws NoResponseException if there was no response from the remote entity. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public Subscription subscribe(Jid jid, FillableSubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { DataForm submitForm = subForm.getDataFormToSubmit(); PubSub request = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId())); request.addExtension(new FormNode(FormNodeType.OPTIONS, submitForm)); PubSub reply = sendPubsubPacket(request); return reply.getExtension(PubSubElementType.SUBSCRIPTION); }