/** * 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; }
/** * Get the items specified from the node. This would typically be * used when the server does not return the payload due to size * constraints. The user would be required to retrieve the payload * after the items have been retrieved via {@link #getItems()} or an * event, that did not include the payload. * * @param ids Item ids of the items to retrieve * * @return The list of {@link Item} with payload * * @throws XMPPException */ public <T extends Item> List<T> getItems(Collection<String> ids) throws XMPPException { List<Item> itemList = new ArrayList<Item>(ids.size()); for (String id : ids) { itemList.add(new Item(id)); } PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); PubSub result = (PubSub)SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS); return (List<T>)itemsElem.getItems(); }
/** * 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 <T extends Node> T 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 (T) node; }
/** * 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; }
/** * Get the items specified from the node. This would typically be used when * the server does not return the payload due to size constraints. The user * would be required to retrieve the payload after the items have been * retrieved via {@link #getItems()} or an event, that did not include the * payload. * * @param ids * Item ids of the items to retrieve * * @return The list of {@link Item} with payload * * @throws XMPPException */ public <T extends Item> List<T> getItems(Collection<String> ids) throws XMPPException { List<Item> itemList = new ArrayList<Item>(ids.size()); for (String id : ids) { itemList.add(new Item(id)); } PubSub request = createPubsubPacket(Type.GET, new ItemsExtension( ItemsExtension.ItemsElementType.items, getId(), itemList)); PubSub result = (PubSub) SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension) result .getExtension(PubSubElementType.ITEMS); return (List<T>) itemsElem.getItems(); }
/** * Get information on the items in the node in standard * {@link DiscoverItems} format. * * @return The item details in {@link DiscoverItems} format * * @throws XMPPException */ public DiscoverItems discoverItems() throws XMPPException { DiscoverItems items = new DiscoverItems(); items.setTo(to); items.setNode(getId()); return (DiscoverItems)SyncPacketSend.getReply(con, items); }
/** * Get the current items stored in the node. * * @return List of {@link Item} in the node * * @throws XMPPException */ public <T extends Item> List<T> getItems() throws XMPPException { PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId())); PubSub result = (PubSub)SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS); return (List<T>)itemsElem.getItems(); }
/** * Get items persisted on the node, limited to the specified number. * * @param maxItems Maximum number of items to return * * @return List of {@link Item} * * @throws XMPPException */ public <T extends Item> List<T> getItems(int maxItems) throws XMPPException { PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId(), maxItems)); PubSub result = (PubSub)SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS); return (List<T>)itemsElem.getItems(); }
/** * Delete the items with the specified id's from the node. * * @param itemIds The list of id's of items to delete * * @throws XMPPException */ public void deleteItem(Collection<String> itemIds) throws XMPPException { List<Item> items = new ArrayList<Item>(itemIds.size()); for (String id : itemIds) { items.add(new Item(id)); } PubSub request = createPubsubPacket(Type.SET, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items)); SyncPacketSend.getReply(con, request); }
/** * Update the configuration with the contents of the new {@link Form} * * @param submitForm */ public void sendConfigurationForm(Form submitForm) throws XMPPException { PubSub packet = createPubsubPacket(Type.SET, new FormNode(FormNodeType.CONFIGURE_OWNER, getId(), submitForm), PubSubNamespace.OWNER); SyncPacketSend.getReply(con, packet); }
/** * Discover node information in standard {@link DiscoverInfo} format. * * @return The discovery information about the node. * * @throws XMPPException */ public DiscoverInfo discoverInfo() throws XMPPException { DiscoverInfo info = new DiscoverInfo(); info.setTo(to); info.setNode(getId()); return (DiscoverInfo)SyncPacketSend.getReply(con, info); }
/** * Get the current items stored in the node. * * @return List of {@link Item} in the node * * @throws XMPPException */ public <T extends Item> List<T> getItems() throws XMPPException { PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest( getId())); PubSub result = (PubSub) SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension) result .getExtension(PubSubElementType.ITEMS); return (List<T>) itemsElem.getItems(); }
/** * Get the current items stored in the node based on the subscription * associated with the provided subscription id. * * @param subscriptionId * - The subscription id for the associated subscription. * @return List of {@link Item} in the node * * @throws XMPPException */ public <T extends Item> List<T> getItems(String subscriptionId) throws XMPPException { PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest( getId(), subscriptionId)); PubSub result = (PubSub) SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension) result .getExtension(PubSubElementType.ITEMS); return (List<T>) itemsElem.getItems(); }
/** * Delete the items with the specified id's from the node. * * @param itemIds * The list of id's of items to delete * * @throws XMPPException */ public void deleteItem(Collection<String> itemIds) throws XMPPException { List<Item> items = new ArrayList<Item>(itemIds.size()); for (String id : itemIds) { items.add(new Item(id)); } PubSub request = createPubsubPacket(Type.SET, new ItemsExtension( ItemsExtension.ItemsElementType.retract, getId(), items)); SyncPacketSend.getReply(con, request); }
/** * Update the configuration with the contents of the new {@link Form} * * @param submitForm */ public void sendConfigurationForm(Form submitForm) throws XMPPException { PubSub packet = createPubsubPacket(Type.SET, new FormNode( FormNodeType.CONFIGURE_OWNER, getId(), submitForm), PubSubNamespace.OWNER); SyncPacketSend.getReply(con, packet); }