/** * Creates an instant node, if supported. * * @return The node that was created * @exception XMPPException */ public Node createNode() throws XMPPException { PubSub reply = (PubSub) sendPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.CREATE)); NodeExtension elem = (NodeExtension) reply.getExtension("create", PubSubNamespace.BASIC.getXmlns()); Node newNode = new Node(con, elem.getNode()); newNode.setTo(to); nodeMap.put(newNode.getId(), newNode); return newNode; }
/** * Creates a node with specified configuration. * * @param name 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 * @exception XMPPException */ public Node createNode(String name, Form config) throws XMPPException { PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name)); if (config != null) request.addExtension(new FormNode(FormNodeType.CONFIGURE, config)); // Errors will cause exceptions in getReply, so it only returns // on success. sendPubsubPacket(con, to, Type.SET, request); Node newNode = new Node(con, name); newNode.setTo(to); nodeMap.put(newNode.getId(), newNode); return newNode; }
/** * Retrieves the requested node, if it exists. It will throw an exception if it does not. * * @param id - The unique id of the node * @return the node * @throws XMPPException The node does not exist */ public Node getNode(String id) throws XMPPException { Node node = nodeMap.get(id); if (node == null) { DiscoverInfo info = new DiscoverInfo(); info.setTo(to); info.setNode(id); SyncPacketSend.getReply(con, info); node = new Node(con, id); node.setTo(to); nodeMap.put(id, node); } return node; }
@Test(expected = SmackException.class) public void getConfigFormWithTimeout() throws XMPPException, SmackException { ThreadedDummyConnection con = new ThreadedDummyConnection(); PubSubManager mgr = new PubSubManager(con); DiscoverInfo info = new DiscoverInfo(); Identity ident = new Identity("pubsub", null, "leaf"); info.addIdentity(ident); con.addIQReply(info); Node node = mgr.getNode("princely_musings"); SmackConfiguration.setDefaultPacketReplyTimeout(100); con.setTimeout(); node.getNodeConfiguration(); }
/** * Retrieves the requested node, if it exists. It will throw an exception if it does not. * * @param id - The unique id of the node * @return the node * @throws XMPPException The node does not exist */ public Node getNode(String id) throws XMPPException { Node node = nodeMap.get(id); if (node == null) { DiscoverInfo info = new DiscoverInfo(); info.setTo(to); info.setNode(id); DiscoverInfo infoReply = (DiscoverInfo) SyncPacketSend.getReply(con, info); if (infoReply.getIdentities().next().getType().equals(NodeType.leaf.toString())) node = new LeafNode(con, id); else node = new CollectionNode(con, id); node.setTo(to); nodeMap.put(id, node); } return node; }
/** * Creates a node with specified configuration. * * <p>Note: This is the only way to create a collection node. * * @param name 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 * @exception XMPPException */ public Node createNode(String name, Form config) throws XMPPException { PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name)); boolean isLeafNode = true; if (config != null) { request.addExtension(new FormNode(FormNodeType.CONFIGURE, config)); FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName()); if (nodeTypeField != null) isLeafNode = nodeTypeField.getValues().next().equals(NodeType.leaf.toString()); } // Errors will cause exceptions in getReply, so it only returns // on success. sendPubsubPacket(con, to, Type.SET, request); Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name); newNode.setTo(to); nodeMap.put(newNode.getId(), newNode); return newNode; }
@Test public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException, InterruptedException { ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE); DiscoverInfo info = new DiscoverInfo(); Identity ident = new Identity("pubsub", null, "leaf"); info.addIdentity(ident); con.addIQReply(info); Node node = mgr.getNode("princely_musings"); PubSub errorIq = new PubSub(); XMPPError error = new XMPPError(Condition.forbidden); errorIq.setError(error); con.addIQReply(errorIq); try { node.getNodeConfiguration(); } catch (XMPPErrorException e) { Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType()); } }
public void stopListening() { if (isListening) { node.removeItemEventListener(this); isListening = false; } }
public void startListening() { if (isListening == false) { node.addItemEventListener(this); isListening = true; } }