org.jivesoftware.smack.packet.RosterPacket Java Examples
The following examples show how to use
org.jivesoftware.smack.packet.RosterPacket.
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: InstantMessagingClient.java From olat with Apache License 2.0 | 6 votes |
/** * Sends a subscription request to the username answers are handled by the method * * @param uname * @param groupname */ protected void subscribeToUser(final String uname, final String groupname) { final Presence presence = new Presence(Presence.Type.subscribe); presence.setTo(uname + "@" + jabberServer); try { connection.sendPacket(presence); final RosterPacket rosterPacket = new RosterPacket(); rosterPacket.setType(IQ.Type.SET); final RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname); item.addGroupName(groupname); item.setItemType(RosterPacket.ItemType.both); rosterPacket.addRosterItem(item); connection.sendPacket(rosterPacket); } catch (final RuntimeException e) { log.warn("Error while trying to send Instant Messaging packet.", e); } }
Example #2
Source File: InstantMessagingClient.java From olat with Apache License 2.0 | 6 votes |
/** * Sends a subscription request to the username answers are handled by the method * * @param uname * @param groupname */ protected void subscribeToUser(final String uname, final String groupname) { final Presence presence = new Presence(Presence.Type.subscribe); presence.setTo(uname + "@" + jabberServer); try { connection.sendPacket(presence); final RosterPacket rosterPacket = new RosterPacket(); rosterPacket.setType(IQ.Type.SET); final RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname); item.addGroupName(groupname); item.setItemType(RosterPacket.ItemType.both); rosterPacket.addRosterItem(item); connection.sendPacket(rosterPacket); } catch (final RuntimeException e) { log.warn("Error while trying to send Instant Messaging packet.", e); } }
Example #3
Source File: RosterEntry.java From saros with GNU General Public License v2.0 | 6 votes |
/** * Sets the name associated with this entry. * * @param name the name. */ public void setName(String name) { // Do nothing if the name hasn't changed. if (name != null && name.equals(this.name)) { return; } // Create a RosterEntry-copy with the new name to create an // update-RosterPacket RosterEntry updatedRosterEntry = new RosterEntry(this.user, name, this.type, this.status, this.roster, this.connection); RosterPacket packet = new RosterPacket(); packet.setType(IQ.Type.SET); packet.addRosterItem(toRosterItem(updatedRosterEntry)); connection.sendPacket(packet); }
Example #4
Source File: Roster.java From AndroidPNClient with Apache License 2.0 | 6 votes |
/** * Removes a roster entry from the roster. The roster entry will also be removed from the * unfiled entries or from any roster group where it could belong and will no longer be part * of the roster. Note that this is an asynchronous call -- Smack must wait for the server * to send an updated subscription status. * * @param entry a roster entry. * @throws XMPPException if an XMPP error occurs. */ public void removeEntry(RosterEntry entry) throws XMPPException { // Only remove the entry if it's in the entry list. // The actual removal logic takes place in RosterPacketListenerprocess>>Packet(Packet) if (!entries.containsKey(entry.getUser())) { return; } RosterPacket packet = new RosterPacket(); packet.setType(IQ.Type.SET); RosterPacket.Item item = RosterEntry.toRosterItem(entry); // Set the item type as REMOVE so that the server will delete the entry item.setItemType(RosterPacket.ItemType.remove); packet.addRosterItem(item); PacketCollector collector = connection.createPacketCollector( new PacketIDFilter(packet.getPacketID())); connection.sendPacket(packet); IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } // If the server replied with an error, throw an exception. else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } }
Example #5
Source File: Roster.java From AndroidPNClient with Apache License 2.0 | 6 votes |
public void processPacket(Packet packet) { if(packet instanceof IQ){ IQ result = (IQ)packet; if(result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()){ Collection<String> addedEntries = new ArrayList<String>(); Collection<String> updatedEntries = new ArrayList<String>(); Collection<String> deletedEntries = new ArrayList<String>(); if(persistentStorage!=null){ for(RosterPacket.Item item : persistentStorage.getEntries()){ insertRosterItem(item,addedEntries,updatedEntries,deletedEntries); } synchronized (Roster.this) { rosterInitialized = true; Roster.this.notifyAll(); } fireRosterChangedEvent(addedEntries,updatedEntries,deletedEntries); } } } connection.removePacketListener(this); }
Example #6
Source File: XMPPContact.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Create a new XMPPContact from RosterEntry. * * @param entry RosterEntry * @return new XMPPContact */ static XMPPContact from(RosterEntry entry) { ContactStatus baseStatus; if (entry.getStatus() == RosterPacket.ItemStatus.SUBSCRIPTION_PENDING) { baseStatus = ContactStatus.TYPE_SUBSCRIPTION_PENDING; } else if (entry.getType() == ItemType.none || entry.getType() == ItemType.from) { /* see http://xmpp.org/rfcs/rfc3921.html chapter 8.2.1, 8.3.1 and 8.6 */ baseStatus = ContactStatus.TYPE_SUBSCRIPTION_CANCELED; } else { baseStatus = ContactStatus.TYPE_OFFLINE; } return new XMPPContact(new JID(entry.getUser()), baseStatus, entry.getName()); }
Example #7
Source File: InstantMessagingClient.java From olat with Apache License 2.0 | 5 votes |
/** * For unsubscription we have to create a packet like: <iq type="set" id="ab7ba" > <query xmlns="jabber:iq:roster"> <item subscription="remove" jid="guido@localhost" * /> </query> </iq> * * @param uname * a valid username */ protected void removeSubscription(final String uname) { final RosterPacket rosterPacket = new RosterPacket(); rosterPacket.setType(IQ.Type.SET); final RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname); item.setItemType(RosterPacket.ItemType.remove); rosterPacket.addRosterItem(item); try { connection.sendPacket(rosterPacket); } catch (final RuntimeException e) { log.warn("Error while trying to send Instant Messaging packet.", e); } }
Example #8
Source File: Roster.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Removes a roster entry from the roster. The roster entry will also be removed from the unfiled * entries or from any roster group where it could belong and will no longer be part of the * roster. Note that this is an asynchronous call -- Smack must wait for the server to send an * updated subscription status. * * @param entry a roster entry. * @throws XMPPException if an XMPP error occurs. * @throws IllegalStateException if connection is not logged in or logged in anonymously */ public void removeEntry(RosterEntry entry) throws XMPPException { if (!connection.isAuthenticated()) { throw new IllegalStateException("Not logged in to server."); } if (connection.isAnonymous()) { throw new IllegalStateException("Anonymous users can't have a roster."); } // Only remove the entry if it's in the entry list. // The actual removal logic takes place in // RosterPacketListenerprocess>>Packet(Packet) if (!entries.containsKey(entry.getUser())) { return; } RosterPacket packet = new RosterPacket(); packet.setType(IQ.Type.SET); RosterPacket.Item item = RosterEntry.toRosterItem(entry); // Set the item type as REMOVE so that the server will delete the entry item.setItemType(RosterPacket.ItemType.remove); packet.addRosterItem(item); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packet.getPacketID())); connection.sendPacket(packet); IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } // If the server replied with an error, throw an exception. else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } }
Example #9
Source File: Roster.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Creates a new roster entry and presence subscription. The server will asynchronously update the * roster with the subscription status. * * @param user the user. (e.g. [email protected]) * @param name the nickname of the user. * @param groups the list of group names the entry will belong to, or <tt>null</tt> if the the * roster entry won't belong to a group. * @throws XMPPException if an XMPP exception occurs. * @throws IllegalStateException if connection is not logged in or logged in anonymously */ public void createEntry(String user, String name, String[] groups) throws XMPPException { if (!connection.isAuthenticated()) { throw new IllegalStateException("Not logged in to server."); } if (connection.isAnonymous()) { throw new IllegalStateException("Anonymous users can't have a roster."); } // Create and send roster entry creation packet. RosterPacket rosterPacket = new RosterPacket(); rosterPacket.setType(IQ.Type.SET); RosterPacket.Item item = new RosterPacket.Item(user, name); if (groups != null) { for (String group : groups) { if (group != null && group.trim().length() > 0) { item.addGroupName(group); } } } rosterPacket.addRosterItem(item); // Wait up to a certain number of seconds for a reply from the server. PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(rosterPacket.getPacketID())); connection.sendPacket(rosterPacket); IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } // If the server replied with an error, throw an exception. else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } // Create a presence subscription packet and send. Presence presencePacket = new Presence(Presence.Type.subscribe); presencePacket.setTo(user); connection.sendPacket(presencePacket); }
Example #10
Source File: Roster.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Reloads the entire roster from the server. This is an asynchronous operation, which means the * method will return immediately, and the roster will be reloaded at a later point when the * server responds to the reload request. * * @throws IllegalStateException if connection is not logged in or logged in anonymously */ public void reload() { if (!connection.isAuthenticated()) { throw new IllegalStateException("Not logged in to server."); } if (connection.isAnonymous()) { throw new IllegalStateException("Anonymous users can't have a roster."); } connection.sendPacket(new RosterPacket()); }
Example #11
Source File: RosterEntry.java From saros with GNU General Public License v2.0 | 5 votes |
static RosterPacket.Item toRosterItem(RosterEntry entry) { RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName()); item.setItemType(entry.getType()); item.setItemStatus(entry.getStatus()); // Set the correct group names for the item. for (RosterGroup group : entry.getGroups()) { item.addGroupName(group.getName()); } return item; }
Example #12
Source File: RosterEntry.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Creates a new roster entry. * * @param user the user. * @param name the nickname for the entry. * @param type the subscription type. * @param status the subscription status (related to subscriptions pending to be approbed). * @param connection a connection to the XMPP server. */ RosterEntry( String user, String name, RosterPacket.ItemType type, RosterPacket.ItemStatus status, Roster roster, Connection connection) { this.user = user; this.name = name; this.type = type; this.status = status; this.roster = roster; this.connection = connection; }
Example #13
Source File: RosterGroup.java From AndroidPNClient with Apache License 2.0 | 5 votes |
/** * Removes a roster entry from this group. If the entry does not belong to any other group * then it will be considered as unfiled, therefore it will be added to the list of unfiled * entries. * Note that this is an asynchronous call -- Smack must wait for the server * to receive the updated roster. * * @param entry a roster entry. * @throws XMPPException if an error occured while trying to remove the entry from the group. */ public void removeEntry(RosterEntry entry) throws XMPPException { PacketCollector collector = null; // Only remove the entry if it's in the entry list. // Remove the entry locally, if we wait for RosterPacketListenerprocess>>Packet(Packet) // to take place the entry will exist in the group until a packet is received from the // server. synchronized (entries) { if (entries.contains(entry)) { RosterPacket packet = new RosterPacket(); packet.setType(IQ.Type.SET); RosterPacket.Item item = RosterEntry.toRosterItem(entry); item.removeGroupName(this.getName()); packet.addRosterItem(item); // Wait up to a certain number of seconds for a reply from the server. collector = connection .createPacketCollector(new PacketIDFilter(packet.getPacketID())); connection.sendPacket(packet); } } if (collector != null) { IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } // If the server replied with an error, throw an exception. else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } } }
Example #14
Source File: RosterGroup.java From AndroidPNClient with Apache License 2.0 | 5 votes |
/** * Adds a roster entry to this group. If the entry was unfiled then it will be removed from * the unfiled list and will be added to this group. * Note that this is an asynchronous call -- Smack must wait for the server * to receive the updated roster. * * @param entry a roster entry. * @throws XMPPException if an error occured while trying to add the entry to the group. */ public void addEntry(RosterEntry entry) throws XMPPException { PacketCollector collector = null; // Only add the entry if it isn't already in the list. synchronized (entries) { if (!entries.contains(entry)) { RosterPacket packet = new RosterPacket(); packet.setType(IQ.Type.SET); RosterPacket.Item item = RosterEntry.toRosterItem(entry); item.addGroupName(getName()); packet.addRosterItem(item); // Wait up to a certain number of seconds for a reply from the server. collector = connection .createPacketCollector(new PacketIDFilter(packet.getPacketID())); connection.sendPacket(packet); } } if (collector != null) { IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } // If the server replied with an error, throw an exception. else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } } }
Example #15
Source File: RosterGroup.java From AndroidPNClient with Apache License 2.0 | 5 votes |
/** * Sets the name of the group. Changing the group's name is like moving all the group entries * of the group to a new group specified by the new name. Since this group won't have entries * it will be removed from the roster. This means that all the references to this object will * be invalid and will need to be updated to the new group specified by the new name. * * @param name the name of the group. */ public void setName(String name) { synchronized (entries) { for (RosterEntry entry : entries) { RosterPacket packet = new RosterPacket(); packet.setType(IQ.Type.SET); RosterPacket.Item item = RosterEntry.toRosterItem(entry); item.removeGroupName(this.name); item.addGroupName(name); packet.addRosterItem(item); connection.sendPacket(packet); } } }
Example #16
Source File: Roster.java From AndroidPNClient with Apache License 2.0 | 5 votes |
/** * Creates a new roster entry and presence subscription. The server will asynchronously * update the roster with the subscription status. * * @param user the user. (e.g. [email protected]) * @param name the nickname of the user. * @param groups the list of group names the entry will belong to, or <tt>null</tt> if the * the roster entry won't belong to a group. * @throws XMPPException if an XMPP exception occurs. */ public void createEntry(String user, String name, String[] groups) throws XMPPException { // Create and send roster entry creation packet. RosterPacket rosterPacket = new RosterPacket(); rosterPacket.setType(IQ.Type.SET); RosterPacket.Item item = new RosterPacket.Item(user, name); if (groups != null) { for (String group : groups) { if (group != null && group.trim().length() > 0) { item.addGroupName(group); } } } rosterPacket.addRosterItem(item); // Wait up to a certain number of seconds for a reply from the server. PacketCollector collector = connection.createPacketCollector( new PacketIDFilter(rosterPacket.getPacketID())); connection.sendPacket(rosterPacket); IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } // If the server replied with an error, throw an exception. else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } // Create a presence subscription packet and send. Presence presencePacket = new Presence(Presence.Type.subscribe); presencePacket.setTo(user); connection.sendPacket(presencePacket); }
Example #17
Source File: InstantMessagingClient.java From olat with Apache License 2.0 | 5 votes |
/** * For unsubscription we have to create a packet like: <iq type="set" id="ab7ba" > <query xmlns="jabber:iq:roster"> <item subscription="remove" jid="guido@localhost" * /> </query> </iq> * * @param uname * a valid username */ protected void removeSubscription(final String uname) { final RosterPacket rosterPacket = new RosterPacket(); rosterPacket.setType(IQ.Type.SET); final RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname); item.setItemType(RosterPacket.ItemType.remove); rosterPacket.addRosterItem(item); try { connection.sendPacket(rosterPacket); } catch (final RuntimeException e) { log.warn("Error while trying to send Instant Messaging packet.", e); } }
Example #18
Source File: RosterEntry.java From AndroidPNClient with Apache License 2.0 | 5 votes |
/** * Creates a new roster entry. * * @param user the user. * @param name the nickname for the entry. * @param type the subscription type. * @param status the subscription status (related to subscriptions pending to be approbed). * @param connection a connection to the XMPP server. */ RosterEntry(String user, String name, RosterPacket.ItemType type, RosterPacket.ItemStatus status, Roster roster, Connection connection) { this.user = user; this.name = name; this.type = type; this.status = status; this.roster = roster; this.connection = connection; }
Example #19
Source File: RosterEntry.java From AndroidPNClient with Apache License 2.0 | 5 votes |
/** * Sets the name associated with this entry. * * @param name the name. */ public void setName(String name) { // Do nothing if the name hasn't changed. if (name != null && name.equals(this.name)) { return; } this.name = name; RosterPacket packet = new RosterPacket(); packet.setType(IQ.Type.SET); packet.addRosterItem(toRosterItem(this)); connection.sendPacket(packet); }
Example #20
Source File: RosterEntry.java From AndroidPNClient with Apache License 2.0 | 5 votes |
static RosterPacket.Item toRosterItem(RosterEntry entry) { RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName()); item.setItemType(entry.getType()); item.setItemStatus(entry.getStatus()); // Set the correct group names for the item. for (RosterGroup group : entry.getGroups()) { item.addGroupName(group.getName()); } return item; }
Example #21
Source File: Roster.java From AndroidPNClient with Apache License 2.0 | 5 votes |
/** * Reloads the entire roster from the server. This is an asynchronous operation, * which means the method will return immediately, and the roster will be * reloaded at a later point when the server responds to the reload request. */ public void reload() { RosterPacket packet = new RosterPacket(); if(persistentStorage!=null){ packet.setVersion(persistentStorage.getRosterVersion()); } requestPacketId = packet.getPacketID(); PacketFilter idFilter = new PacketIDFilter(requestPacketId); connection.addPacketListener(new RosterResultListener(), idFilter); connection.sendPacket(packet); }
Example #22
Source File: Roster.java From AndroidPNClient with Apache License 2.0 | 5 votes |
private void insertRosterItems(List<RosterPacket.Item> items){ Collection<String> addedEntries = new ArrayList<String>(); Collection<String> updatedEntries = new ArrayList<String>(); Collection<String> deletedEntries = new ArrayList<String>(); Iterator<RosterPacket.Item> iter = items.iterator(); while(iter.hasNext()){ insertRosterItem(iter.next(), addedEntries,updatedEntries,deletedEntries); } fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries); }
Example #23
Source File: RosterStorage.java From AndroidPNClient with Apache License 2.0 | 2 votes |
/** * This method stores a new RosterEntry in this store or overrides an existing one. * If ver is null an IllegalArgumentException should be thrown. * @param entry the entry to save * @param ver the version this roster push contained */ public void addEntry(RosterPacket.Item item, String ver);
Example #24
Source File: RosterStorage.java From AndroidPNClient with Apache License 2.0 | 2 votes |
/** * Update an entry which has been modified locally * @param entry the entry to be updated */ public void updateLocalEntry(RosterPacket.Item item);
Example #25
Source File: RosterStorage.java From AndroidPNClient with Apache License 2.0 | 2 votes |
/** * This method returns the RosterEntry which belongs to a specific user. * @param bareJid The bare JID of the RosterEntry * @return The RosterEntry which belongs to that user */ public RosterPacket.Item getEntry(String bareJid);
Example #26
Source File: RosterEntry.java From AndroidPNClient with Apache License 2.0 | 2 votes |
/** * Returns the roster subscription status of the entry. When the status is * RosterPacket.ItemStatus.SUBSCRIPTION_PENDING, the contact has to answer the * subscription request. * * @return the status. */ public RosterPacket.ItemStatus getStatus() { return status; }
Example #27
Source File: RosterEntry.java From saros with GNU General Public License v2.0 | 2 votes |
/** * Updates the state of the entry with the new values. * * @param name the nickname for the entry. * @param type the subscription type. * @param status the subscription status (related to subscriptions pending to be approbed). */ void updateState(String name, RosterPacket.ItemType type, RosterPacket.ItemStatus status) { this.name = name; this.type = type; this.status = status; }
Example #28
Source File: RosterEntry.java From saros with GNU General Public License v2.0 | 2 votes |
/** * Returns the roster subscription type of the entry. When the type is RosterPacket.ItemType.none * or RosterPacket.ItemType.from, refer to {@link RosterEntry getStatus()} to see if a * subscription request is pending. * * @return the type. */ public RosterPacket.ItemType getType() { return type; }
Example #29
Source File: RosterEntry.java From saros with GNU General Public License v2.0 | 2 votes |
/** * Returns the roster subscription status of the entry. When the status is * RosterPacket.ItemStatus.SUBSCRIPTION_PENDING, the contact has to answer the subscription * request. * * @return the status. */ public RosterPacket.ItemStatus getStatus() { return status; }
Example #30
Source File: RosterEntry.java From AndroidPNClient with Apache License 2.0 | 2 votes |
/** * Returns the roster subscription type of the entry. When the type is * RosterPacket.ItemType.none or RosterPacket.ItemType.from, * refer to {@link org.jivesoftware.smack.RosterEntry getStatus()} to see if a subscription request * is pending. * * @return the type. */ public RosterPacket.ItemType getType() { return type; }