diff --git a/source/org/jivesoftware/smackx/packet/MUCAdmin.java b/source/org/jivesoftware/smackx/packet/MUCAdmin.java
index c5105bfcf..1344e0a1b 100644
--- a/source/org/jivesoftware/smackx/packet/MUCAdmin.java
+++ b/source/org/jivesoftware/smackx/packet/MUCAdmin.java
@@ -51,18 +51,216 @@
*/
package org.jivesoftware.smackx.packet;
+import java.util.*;
+
import org.jivesoftware.smack.packet.IQ;
/**
- * Represents .....
+ * IQ packet that serves for kicking users, granting and revoking voice, banning users,
+ * modifying the ban list, granting and revoking membership and granting and revoking
+ * moderator privileges. All these operations are scoped by the
+ * 'http://jabber.org/protocol/muc#admin' namespace.
*
* @author Gaston Dombiak
*/
public class MUCAdmin extends IQ {
- public String getChildElementXML() {
- // TODO Auto-generated method stub
- return null;
+ private List items = new ArrayList();
+
+ /**
+ * Returns an Iterator for item childs that holds information about roles, affiliation,
+ * jids and nicks.
+ *
+ * @return an Iterator for item childs that holds information about roles, affiliation,
+ * jids and nicks.
+ */
+ public Iterator getItems() {
+ synchronized (items) {
+ return Collections.unmodifiableList(new ArrayList(items)).iterator();
+ }
}
+ /**
+ * Adds an item child that holds information about roles, affiliation, jids and nicks.
+ *
+ * @param item the item child that holds information about roles, affiliation, jids and nicks.
+ */
+ public void addItem(Item item) {
+ synchronized (items) {
+ items.add(item);
+ }
+ }
+
+ public String getChildElementXML() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("");
+ synchronized (items) {
+ for (int i = 0; i < items.size(); i++) {
+ Item item = (Item) items.get(i);
+ buf.append(item.toXML());
+ }
+ }
+ // Add packet extensions, if any are defined.
+ buf.append(getExtensionsXML());
+ buf.append("");
+ return buf.toString();
+ }
+
+ /**
+ * Item child that holds information about roles, affiliation, jids and nicks.
+ *
+ * @author Gaston Dombiak
+ */
+ public static class Item {
+ private String actor;
+ private String reason;
+ private String affiliation;
+ private String jid;
+ private String nick;
+ private String role;
+
+ /**
+ * Creates a new item child.
+ *
+ * @param affiliation the actor's affiliation to the room
+ * @param role the privilege level of an occupant within a room.
+ */
+ public Item(String affiliation, String role) {
+ this.affiliation = affiliation;
+ this.role = role;
+ }
+
+ /**
+ * Returns the actor (JID of an occupant in the room) that was kicked or banned.
+ *
+ * @return the JID of an occupant in the room that was kicked or banned.
+ */
+ public String getActor() {
+ return actor;
+ }
+
+ /**
+ * Returns the reason for the item child. The reason is optional and could be used to
+ * explain the reason why a user (occupant) was kicked or banned.
+ *
+ * @return the reason for the item child.
+ */
+ public String getReason() {
+ return reason;
+ }
+
+ /**
+ * Returns the occupant's affiliation to the room. The affiliation is a semi-permanent
+ * association or connection with a room. The possible affiliations are "owner", "admin",
+ * "member", and "outcast" (naturally it is also possible to have no affiliation). An
+ * affiliation lasts across a user's visits to a room.
+ *
+ * @return the actor's affiliation to the room
+ */
+ public String getAffiliation() {
+ return affiliation;
+ }
+
+ /**
+ * Returns the by which an occupant is identified within the context
+ * of a room. If the room is non-anonymous, the JID will be included in the item.
+ *
+ * @return the room JID by which an occupant is identified within the room.
+ */
+ public String getJid() {
+ return jid;
+ }
+
+ /**
+ * Returns the new nickname of an occupant that is changing his/her nickname. The new
+ * nickname is sent as part of the unavailable presence.
+ *
+ * @return the new nickname of an occupant that is changing his/her nickname.
+ */
+ public String getNick() {
+ return nick;
+ }
+
+ /**
+ * Returns the temporary position or privilege level of an occupant within a room. The
+ * possible roles are "moderator", "participant", and "visitor" (it is also possible to
+ * have no defined role). A role lasts only for the duration of an occupant's visit to
+ * a room.
+ *
+ * @return the privilege level of an occupant within a room.
+ */
+ public String getRole() {
+ return role;
+ }
+
+ /**
+ * Sets the actor (JID of an occupant in the room) that was kicked or banned.
+ *
+ * @param actor the actor (JID of an occupant in the room) that was kicked or banned.
+ */
+ public void setActor(String actor) {
+ this.actor = actor;
+ }
+
+ /**
+ * Sets the reason for the item child. The reason is optional and could be used to
+ * explain the reason why a user (occupant) was kicked or banned.
+ *
+ * @param reason the reason why a user (occupant) was kicked or banned.
+ */
+ public void setReason(String reason) {
+ this.reason = reason;
+ }
+
+ /**
+ * Sets the by which an occupant is identified within the context
+ * of a room. If the room is non-anonymous, the JID will be included in the item.
+ *
+ * @param jid the JID by which an occupant is identified within a room.
+ */
+ public void setJid(String jid) {
+ this.jid = jid;
+ }
+
+ /**
+ * Sets the new nickname of an occupant that is changing his/her nickname. The new
+ * nickname is sent as part of the unavailable presence.
+ *
+ * @param nick the new nickname of an occupant that is changing his/her nickname.
+ */
+ public void setNick(String nick) {
+ this.nick = nick;
+ }
+
+ public String toXML() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(" ");
+ }
+ else {
+ buf.append(">");
+ if (getReason() != null) {
+ buf.append("").append(getReason()).append("");
+ }
+ if (getActor() != null) {
+ buf.append("");
+ }
+ buf.append("");
+ }
+ return buf.toString();
+ }
+ };
}
diff --git a/source/org/jivesoftware/smackx/provider/MUCAdminProvider.java b/source/org/jivesoftware/smackx/provider/MUCAdminProvider.java
index 7314ad9c9..b6a54b390 100644
--- a/source/org/jivesoftware/smackx/provider/MUCAdminProvider.java
+++ b/source/org/jivesoftware/smackx/provider/MUCAdminProvider.java
@@ -54,21 +54,60 @@ package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
+import org.jivesoftware.smackx.packet.MUCAdmin;
import org.xmlpull.v1.XmlPullParser;
/**
- * Represents .....
+ * The MUCAdminProvider parses MUCAdmin packets. (@see MUCAdmin)
*
* @author Gaston Dombiak
*/
public class MUCAdminProvider implements IQProvider {
- /* (non-Javadoc)
- * @see org.jivesoftware.smack.provider.IQProvider#parseIQ(org.xmlpull.v1.XmlPullParser)
- */
public IQ parseIQ(XmlPullParser parser) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ MUCAdmin mucAdmin = new MUCAdmin();
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+ if (eventType == XmlPullParser.START_TAG) {
+ if (parser.getName().equals("item")) {
+ mucAdmin.addItem(parseItem(parser));
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals("query")) {
+ done = true;
+ }
+ }
+ }
+
+ return mucAdmin;
}
+ private MUCAdmin.Item parseItem(XmlPullParser parser) throws Exception {
+ boolean done = false;
+ MUCAdmin.Item item =
+ new MUCAdmin.Item(
+ parser.getAttributeValue("", "affiliation"),
+ parser.getAttributeValue("", "role"));
+ item.setNick(parser.getAttributeValue("", "nick"));
+ item.setJid(parser.getAttributeValue("", "jid"));
+ while (!done) {
+ int eventType = parser.next();
+ if (eventType == XmlPullParser.START_TAG) {
+ if (parser.getName().equals("actor")) {
+ item.setActor(parser.getAttributeValue("", "jid"));
+ }
+ if (parser.getName().equals("reason")) {
+ item.setReason(parser.nextText());
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals("item")) {
+ done = true;
+ }
+ }
+ }
+ return item;
+ }
}