1 20 21 package org.jivesoftware.smackx.packet; 22 23 import java.util.*; 24 25 import org.jivesoftware.smack.packet.IQ; 26 27 36 public class DiscoverItems extends IQ { 37 38 private List items = new ArrayList(); 39 private String node; 40 41 46 public void addItem(Item item) { 47 synchronized (items) { 48 items.add(item); 49 } 50 } 51 52 57 public Iterator getItems() { 58 synchronized (items) { 59 return Collections.unmodifiableList(new ArrayList(items)).iterator(); 60 } 61 } 62 63 72 public String getNode() { 73 return node; 74 } 75 76 85 public void setNode(String node) { 86 this.node = node; 87 } 88 89 public String getChildElementXML() { 90 StringBuffer buf = new StringBuffer (); 91 buf.append("<query xmlns=\"http://jabber.org/protocol/disco#items\""); 92 if (getNode() != null) { 93 buf.append(" node=\""); 94 buf.append(getNode()); 95 buf.append("\""); 96 } 97 buf.append(">"); 98 synchronized (items) { 99 for (int i = 0; i < items.size(); i++) { 100 Item item = (Item) items.get(i); 101 buf.append(item.toXML()); 102 } 103 } 104 buf.append("</query>"); 105 return buf.toString(); 106 } 107 108 116 public static class Item { 117 118 121 public static final String UPDATE_ACTION = "update"; 122 123 126 public static final String REMOVE_ACTION = "remove"; 127 128 private String entityID; 129 private String name; 130 private String node; 131 private String action; 132 133 138 public Item(String entityID) { 139 this.entityID = entityID; 140 } 141 142 147 public String getEntityID() { 148 return entityID; 149 } 150 151 156 public String getName() { 157 return name; 158 } 159 160 165 public void setName(String name) { 166 this.name = name; 167 } 168 169 178 public String getNode() { 179 return node; 180 } 181 182 191 public void setNode(String node) { 192 this.node = node; 193 } 194 195 203 public String getAction() { 204 return action; 205 } 206 207 215 public void setAction(String action) { 216 this.action = action; 217 } 218 219 public String toXML() { 220 StringBuffer buf = new StringBuffer (); 221 buf.append("<item jid=\"").append(entityID).append("\""); 222 if (name != null) { 223 buf.append(" name=\"").append(name).append("\""); 224 } 225 if (node != null) { 226 buf.append(" node=\"").append(node).append("\""); 227 } 228 if (action != null) { 229 buf.append(" action=\"").append(action).append("\""); 230 } 231 buf.append("/>"); 232 return buf.toString(); 233 } 234 } 235 } | Popular Tags |