1 20 21 package org.jivesoftware.smackx.provider; 22 23 import org.jivesoftware.smack.packet.IQ; 24 import org.jivesoftware.smack.provider.IQProvider; 25 import org.jivesoftware.smackx.packet.MUCAdmin; 26 import org.xmlpull.v1.XmlPullParser; 27 28 33 public class MUCAdminProvider implements IQProvider { 34 35 public IQ parseIQ(XmlPullParser parser) throws Exception { 36 MUCAdmin mucAdmin = new MUCAdmin(); 37 boolean done = false; 38 while (!done) { 39 int eventType = parser.next(); 40 if (eventType == XmlPullParser.START_TAG) { 41 if (parser.getName().equals("item")) { 42 mucAdmin.addItem(parseItem(parser)); 43 } 44 } 45 else if (eventType == XmlPullParser.END_TAG) { 46 if (parser.getName().equals("query")) { 47 done = true; 48 } 49 } 50 } 51 52 return mucAdmin; 53 } 54 55 private MUCAdmin.Item parseItem(XmlPullParser parser) throws Exception { 56 boolean done = false; 57 MUCAdmin.Item item = 58 new MUCAdmin.Item( 59 parser.getAttributeValue("", "affiliation"), 60 parser.getAttributeValue("", "role")); 61 item.setNick(parser.getAttributeValue("", "nick")); 62 item.setJid(parser.getAttributeValue("", "jid")); 63 while (!done) { 64 int eventType = parser.next(); 65 if (eventType == XmlPullParser.START_TAG) { 66 if (parser.getName().equals("actor")) { 67 item.setActor(parser.getAttributeValue("", "jid")); 68 } 69 if (parser.getName().equals("reason")) { 70 item.setReason(parser.nextText()); 71 } 72 } 73 else if (eventType == XmlPullParser.END_TAG) { 74 if (parser.getName().equals("item")) { 75 done = true; 76 } 77 } 78 } 79 return item; 80 } 81 } 82 | Popular Tags |