1 20 21 package org.jivesoftware.smackx.provider; 22 23 import org.jivesoftware.smack.packet.*; 24 import org.jivesoftware.smack.provider.*; 25 import org.jivesoftware.smack.util.PacketParserUtils; 26 import org.jivesoftware.smackx.packet.MUCOwner; 27 import org.xmlpull.v1.XmlPullParser; 28 29 34 public class MUCOwnerProvider implements IQProvider { 35 36 public IQ parseIQ(XmlPullParser parser) throws Exception { 37 MUCOwner mucOwner = new MUCOwner(); 38 boolean done = false; 39 while (!done) { 40 int eventType = parser.next(); 41 if (eventType == XmlPullParser.START_TAG) { 42 if (parser.getName().equals("item")) { 43 mucOwner.addItem(parseItem(parser)); 44 } 45 else if (parser.getName().equals("destroy")) { 46 mucOwner.setDestroy(parseDestroy(parser)); 47 } 48 else { 50 mucOwner.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(), 51 parser.getNamespace(), parser)); 52 } 53 } 54 else if (eventType == XmlPullParser.END_TAG) { 55 if (parser.getName().equals("query")) { 56 done = true; 57 } 58 } 59 } 60 61 return mucOwner; 62 } 63 64 private MUCOwner.Item parseItem(XmlPullParser parser) throws Exception { 65 boolean done = false; 66 MUCOwner.Item item = new MUCOwner.Item(parser.getAttributeValue("", "affiliation")); 67 item.setNick(parser.getAttributeValue("", "nick")); 68 item.setRole(parser.getAttributeValue("", "role")); 69 item.setJid(parser.getAttributeValue("", "jid")); 70 while (!done) { 71 int eventType = parser.next(); 72 if (eventType == XmlPullParser.START_TAG) { 73 if (parser.getName().equals("actor")) { 74 item.setActor(parser.getAttributeValue("", "jid")); 75 } 76 if (parser.getName().equals("reason")) { 77 item.setReason(parser.nextText()); 78 } 79 } 80 else if (eventType == XmlPullParser.END_TAG) { 81 if (parser.getName().equals("item")) { 82 done = true; 83 } 84 } 85 } 86 return item; 87 } 88 89 private MUCOwner.Destroy parseDestroy(XmlPullParser parser) throws Exception { 90 boolean done = false; 91 MUCOwner.Destroy destroy = new MUCOwner.Destroy(); 92 destroy.setJid(parser.getAttributeValue("", "jid")); 93 while (!done) { 94 int eventType = parser.next(); 95 if (eventType == XmlPullParser.START_TAG) { 96 if (parser.getName().equals("reason")) { 97 destroy.setReason(parser.nextText()); 98 } 99 } 100 else if (eventType == XmlPullParser.END_TAG) { 101 if (parser.getName().equals("destroy")) { 102 done = true; 103 } 104 } 105 } 106 return destroy; 107 } 108 } 109 | Popular Tags |