1 20 21 package org.jivesoftware.smackx.packet; 22 import java.util.*; 23 24 import org.jivesoftware.smack.packet.IQ; 25 26 34 public class MUCAdmin extends IQ { 35 36 private List items = new ArrayList(); 37 38 45 public Iterator getItems() { 46 synchronized (items) { 47 return Collections.unmodifiableList(new ArrayList(items)).iterator(); 48 } 49 } 50 51 56 public void addItem(Item item) { 57 synchronized (items) { 58 items.add(item); 59 } 60 } 61 62 public String getChildElementXML() { 63 StringBuffer buf = new StringBuffer (); 64 buf.append("<query xmlns=\"http://jabber.org/protocol/muc#admin\">"); 65 synchronized (items) { 66 for (int i = 0; i < items.size(); i++) { 67 Item item = (Item) items.get(i); 68 buf.append(item.toXML()); 69 } 70 } 71 buf.append(getExtensionsXML()); 73 buf.append("</query>"); 74 return buf.toString(); 75 } 76 77 82 public static class Item { 83 private String actor; 84 private String reason; 85 private String affiliation; 86 private String jid; 87 private String nick; 88 private String role; 89 90 96 public Item(String affiliation, String role) { 97 this.affiliation = affiliation; 98 this.role = role; 99 } 100 101 106 public String getActor() { 107 return actor; 108 } 109 110 116 public String getReason() { 117 return reason; 118 } 119 120 128 public String getAffiliation() { 129 return affiliation; 130 } 131 132 138 public String getJid() { 139 return jid; 140 } 141 142 148 public String getNick() { 149 return nick; 150 } 151 152 160 public String getRole() { 161 return role; 162 } 163 164 169 public void setActor(String actor) { 170 this.actor = actor; 171 } 172 173 179 public void setReason(String reason) { 180 this.reason = reason; 181 } 182 183 189 public void setJid(String jid) { 190 this.jid = jid; 191 } 192 193 199 public void setNick(String nick) { 200 this.nick = nick; 201 } 202 203 public String toXML() { 204 StringBuffer buf = new StringBuffer (); 205 buf.append("<item"); 206 if (getAffiliation() != null) { 207 buf.append(" affiliation=\"").append(getAffiliation()).append("\""); 208 } 209 if (getJid() != null) { 210 buf.append(" jid=\"").append(getJid()).append("\""); 211 } 212 if (getNick() != null) { 213 buf.append(" nick=\"").append(getNick()).append("\""); 214 } 215 if (getRole() != null) { 216 buf.append(" role=\"").append(getRole()).append("\""); 217 } 218 if (getReason() == null && getActor() == null) { 219 buf.append("/>"); 220 } 221 else { 222 buf.append(">"); 223 if (getReason() != null) { 224 buf.append("<reason>").append(getReason()).append("</reason>"); 225 } 226 if (getActor() != null) { 227 buf.append("<actor jid=\"").append(getActor()).append("\"/>"); 228 } 229 buf.append("</item>"); 230 } 231 return buf.toString(); 232 } 233 }; 234 } 235 | Popular Tags |