Beispiel #1
0
 /**
  * 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);
 }
Beispiel #2
0
 private static RosterPacket parseRoster(XmlPullParser parser) throws Exception {
   RosterPacket roster = new RosterPacket();
   boolean done = false;
   RosterPacket.Item item = null;
   while (!done) {
     if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equals("query")) {
       String version = parser.getAttributeValue(null, "ver");
       roster.setVersion(version);
     }
     int eventType = parser.next();
     if (eventType == XmlPullParser.START_TAG) {
       if (parser.getName().equals("item")) {
         String jid = parser.getAttributeValue("", "jid");
         String name = parser.getAttributeValue("", "name");
         // Create packet.
         item = new RosterPacket.Item(jid, name);
         // Set status.
         String ask = parser.getAttributeValue("", "ask");
         RosterPacket.ItemStatus status = RosterPacket.ItemStatus.fromString(ask);
         item.setItemStatus(status);
         // Set type.
         String subscription = parser.getAttributeValue("", "subscription");
         RosterPacket.ItemType type =
             RosterPacket.ItemType.valueOf(subscription != null ? subscription : "none");
         item.setItemType(type);
       }
       if (parser.getName().equals("group") && item != null) {
         final String groupName = parser.nextText();
         if (groupName != null && groupName.trim().length() > 0) {
           item.addGroupName(groupName);
         }
       }
     } else if (eventType == XmlPullParser.END_TAG) {
       if (parser.getName().equals("item")) {
         roster.addRosterItem(item);
       }
       if (parser.getName().equals("query")) {
         done = true;
       }
     }
   }
   return roster;
 }