/** * Returns an iterator on <tt>OfflineMessageHeader</tt> that keep information about the * offline message. The OfflineMessageHeader includes a stamp that could be used to retrieve * the complete message or delete the specific message. * * @return an iterator on <tt>OfflineMessageHeader</tt> that keep information about the offline * message. * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public Iterator<OfflineMessageHeader> getHeaders() throws XMPPException { List<OfflineMessageHeader> answer = new ArrayList<OfflineMessageHeader>(); DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems( null, namespace); for (Iterator it = items.getItems(); it.hasNext();) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); answer.add(new OfflineMessageHeader(item)); } return answer.iterator(); }
public void processPacket(Packet packet) { DiscoverItems discoverItems = (DiscoverItems) packet; if (discoverItems != null && discoverItems.getType() == IQ.Type.GET) { DiscoverItems response = new DiscoverItems(); response.setType(IQ.Type.RESULT); response.setTo(discoverItems.getFrom()); response.setPacketID(discoverItems.getPacketID()); response.setNode(discoverItems.getNode()); getNodeInformationProvider(discoverItems.getNode()); if (nodeInformationProvider != null) { if (items != null) { for (DiscoverItems.Item item : items) { response.addItem(item); } else if(discoverItems.getNode() != null) { response.setType(IQ.Type.ERROR); response.setError(new XMPPError(XMPPError.Condition.item_not_found));
public void processPacket(Packet packet) { DiscoverItems discoverItems = (DiscoverItems) packet; // Send back the items defined in the client if the request is of type GET if (discoverItems != null && discoverItems.getType() == IQ.Type.GET) { DiscoverItems response = new DiscoverItems(); response.setType(IQ.Type.RESULT); response.setTo(discoverItems.getFrom()); response.setPacketID(discoverItems.getPacketID()); response.setNode(discoverItems.getNode()); // Add the defined items related to the requested node. Look for // the NodeInformationProvider associated with the requested node. NodeInformationProvider nodeInformationProvider = getNodeInformationProvider(discoverItems.getNode()); if (nodeInformationProvider != null) { // Specified node was found, add node items response.addItems(nodeInformationProvider.getNodeItems()); // Add packet extensions response.addExtensions(nodeInformationProvider.getNodePacketExtensions()); } else if(discoverItems.getNode() != null) { // Return <item-not-found/> error since client doesn't contain // the specified node response.setType(IQ.Type.ERROR); response.setError(new XMPPError(XMPPError.Condition.item_not_found)); } connection.sendPacket(response); } } };
/** * Get all the nodes that currently exist as a child of the specified * collection node. If the service does not support collection nodes * then all nodes will be returned. * * To retrieve contents of the root collection node (if it exists), * or there is no root collection node, pass null as the nodeId. * * @param nodeId - The id of the collection node for which the child * nodes will be returned. * @return {@link DiscoverItems} representing the existing nodes * * @throws XMPPException */ public DiscoverItems discoverNodes(String nodeId) throws XMPPException { DiscoverItems items = new DiscoverItems(); if (nodeId != null) items.setNode(nodeId); items.setTo(to); DiscoverItems nodeItems = (DiscoverItems)SyncPacketSend.getReply(con, items); return nodeItems; }
DiscoverItems disco = new DiscoverItems(); disco.setType(IQ.Type.GET); disco.setTo(entityID); disco.setNode(node); connection.createPacketCollector(new PacketIDFilter(disco.getPacketID()));
public IQ parseIQ(XmlPullParser parser) throws Exception { DiscoverItems discoverItems = new DiscoverItems(); boolean done = false; DiscoverItems.Item item; String action = ""; String node = ""; discoverItems.setNode(parser.getAttributeValue("", "node")); while (!done) { int eventType = parser.next(); item.setNode(node); item.setAction(action); discoverItems.addItem(item);
/** * Publish the commands to an specific JID. * * @param jid the full JID to publish the commands to. * @throws XMPPException if the operation failed for some reason. */ public void publishCommands(String jid) throws XMPPException { ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager .getInstanceFor(connection); // Collects the commands to publish as items DiscoverItems discoverItems = new DiscoverItems(); Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands(); for (AdHocCommandInfo info : xCommandsList) { DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID()); item.setName(info.getName()); item.setNode(info.getNode()); discoverItems.addItem(item); } serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems); }
public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append("<query xmlns=\"http://jabber.org/protocol/disco#items\""); if (getNode() != null) { buf.append(" node=\""); buf.append(getNode()); buf.append("\""); } buf.append(">"); synchronized (items) { for (Item item : items) { buf.append(item.toXML()); } } buf.append("</query>"); return buf.toString(); }
DiscoverItems response = new DiscoverItems(); response.setType(IQ.Type.RESULT); response.setTo(discoverItems.getFrom());
/** * Adds a collection of items to the discovered information. Does nothing if itemsToAdd is null * * @param itemsToAdd */ public void addItems(Collection<Item> itemsToAdd) { if (itemsToAdd == null) return; for (Item i : itemsToAdd) { addItem(i); } }
DiscoverItems disco = new DiscoverItems(); disco.setType(IQ.Type.GET); disco.setTo(entityID); disco.setNode(node); connection.createPacketCollector(new PacketIDFilter(disco.getPacketID()));
/** * Get all the nodes that currently exist as a child of the specified * collection node. If the service does not support collection nodes * then all nodes will be returned. * * To retrieve contents of the root collection node (if it exists), * or there is no root collection node, pass null as the nodeId. * * @param nodeId - The id of the collection node for which the child * nodes will be returned. * @return {@link DiscoverItems} representing the existing nodes * * @throws XMPPException */ public DiscoverItems discoverNodes(String nodeId) throws XMPPException { DiscoverItems items = new DiscoverItems(); if (nodeId != null) items.setNode(nodeId); items.setTo(to); DiscoverItems nodeItems = (DiscoverItems)SyncPacketSend.getReply(con, items); return nodeItems; }
public IQ parseIQ(XmlPullParser parser) throws Exception { DiscoverItems discoverItems = new DiscoverItems(); boolean done = false; DiscoverItems.Item item; String action = ""; String node = ""; discoverItems.setNode(parser.getAttributeValue("", "node")); while (!done) { int eventType = parser.next(); item.setNode(node); item.setAction(action); discoverItems.addItem(item);
/** * Publish the commands to an specific JID. * * @param jid the full JID to publish the commands to. * @throws XMPPException if the operation failed for some reason. */ public void publishCommands(String jid) throws XMPPException { ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager .getInstanceFor(connection); // Collects the commands to publish as items DiscoverItems discoverItems = new DiscoverItems(); Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands(); for (AdHocCommandInfo info : xCommandsList) { DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID()); item.setName(info.getName()); item.setNode(info.getNode()); discoverItems.addItem(item); } serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems); }
public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append("<query xmlns=\"http://jabber.org/protocol/disco#items\""); if (getNode() != null) { buf.append(" node=\""); buf.append(getNode()); buf.append("\""); } buf.append(">"); synchronized (items) { for (Item item : items) { buf.append(item.toXML()); } } buf.append("</query>"); return buf.toString(); }
DiscoverItems response = new DiscoverItems(); response.setType(IQ.Type.RESULT); response.setTo(discoverItems.getFrom());
public void processPacket(Packet packet) { DiscoverItems discoverItems = (DiscoverItems) packet; // Send back the items defined in the client if the request is of type GET if (discoverItems != null && discoverItems.getType() == IQ.Type.GET) { DiscoverItems response = new DiscoverItems(); response.setType(IQ.Type.RESULT); response.setTo(discoverItems.getFrom()); response.setPacketID(discoverItems.getPacketID()); // Add the defined items related to the requested node. Look for // the NodeInformationProvider associated with the requested node. if (getNodeInformationProvider(discoverItems.getNode()) != null) { Iterator items = getNodeInformationProvider(discoverItems.getNode()).getNodeItems(); while (items.hasNext()) { response.addItem((DiscoverItems.Item) items.next()); } } else if(discoverItems.getNode() != null) { // Return an <item-not-found/> error since the client // doesn't contain the specified node response.setNode(discoverItems.getNode()); response.setType(IQ.Type.ERROR); response.setError(new XMPPError(404, "item-not-found")); } connection.sendPacket(response); } } };
DiscoverItems disco = new DiscoverItems(); disco.setType(IQ.Type.GET); disco.setTo(entityID); disco.setNode(node); connection.createPacketCollector(new PacketIDFilter(disco.getPacketID()));
/** * Returns an iterator on <tt>OfflineMessageHeader</tt> that keep information about the * offline message. The OfflineMessageHeader includes a stamp that could be used to retrieve * the complete message or delete the specific message. * * @return an iterator on <tt>OfflineMessageHeader</tt> that keep information about the offline * message. * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public Iterator<OfflineMessageHeader> getHeaders() throws XMPPException { List<OfflineMessageHeader> answer = new ArrayList<OfflineMessageHeader>(); DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems( null, namespace); for (Iterator it = items.getItems(); it.hasNext();) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); answer.add(new OfflineMessageHeader(item)); } return answer.iterator(); }
/** * Get all the nodes that currently exist as a child of the specified * collection node. If the service does not support collection nodes * then all nodes will be returned. * * To retrieve contents of the root collection node (if it exists), * or there is no root collection node, pass null as the nodeId. * * @param nodeId - The id of the collection node for which the child * nodes will be returned. * @return {@link DiscoverItems} representing the existing nodes * * @throws XMPPException */ public DiscoverItems discoverNodes(String nodeId) throws XMPPException { DiscoverItems items = new DiscoverItems(); if (nodeId != null) items.setNode(nodeId); items.setTo(to); DiscoverItems nodeItems = (DiscoverItems)SyncPacketSend.getReply(con, items); return nodeItems; }