Ejemplo n.º 1
0
		/**
     * Creates a new DestroyRoom with the reason for the destruction and an alternate room JID.
     *
     * @param alternateJID JID of the alternate room or <tt>null</tt> if none.
     * @param reason       reason for the destruction or <tt>null</tt> if none.
     */
		public DestroyRoom(JID alternateJID, String reason)
        {
			super();
			setType(Type.set);
			Element query = setChildElement("query", "http://jabber.org/protocol/muc#owner");
			Element destroy = query.addElement("destroy");
			if (alternateJID != null) {
				destroy.addAttribute("jid", alternateJID.toString());
			}
			if (reason != null) {
				destroy.addElement("reason").setText(reason);
			}
		}
Ejemplo n.º 2
0
		/**
     * Removes an item from this roster.
     *
     * @param jid the JID of the item to remove.
     */
		public void removeItem(JID jid) {
            XElement query = element.Element(XName.Get("query", "jabber:iq:roster"));
			if (query != null) {
				for (Iterator<Element> i=query.elementIterator("item"); i.hasNext(); ) {
					XElement item = i.next();
					if (item.attributeValue("jid").equals(jid.toString())) {
						query.remove(item);
						return;
					}
				}
			}
		}
Ejemplo n.º 3
0
		/**
     * Adds a new item to the roster. If the roster packet already contains an item
     * using the same JID, the information in the existing item will be overwritten
     * with the new information.<p>
     *
     * The XMPP specification recommends that if the roster item is associated with another
     * instant messaging user (human), that the JID be in bare form (e.g. user@domain).
     * Use the {@link JID#toBareJID() toBareJID()} method for a bare JID.
     *
     * @param jid the JID.
     * @param name the nickname.
     * @param ask the ask type.
     * @param subscription the subscription type.
     * @param groups a Collection of groups.
     * @return the newly created item.
     */
		public Item addItem(JID jid, String name, Ask ask, Subscription subscription,
		                Collection<String> groups)
		{
			if (jid == null) {
                throw new ArgumentException("JID cannot be null");
			}
			if (subscription == null) {
                throw new ArgumentException("Subscription cannot be null");
			}
            XElement query = element.Element(XName.Get("query", "jabber:iq:roster"));
			if (query == null)
			{
			    query = new XElement(XName.Get("query", "jabber:iq:roster");
				element.Add(query);
			}
			XElement item = null;
			for (Iterator<Element> i=query.elementIterator("item"); i.hasNext(); ) {
				XElement el = i.next();
				if (el.attributeValue("jid").equals(jid.toString())) {
					item = el;
				}
			}
			if (item == null)
			{
			    item = new XElement("item");
				query.Add(item);
			}
			item.Add(new XAttribute("jid", jid.toBareJID()));
			item.Add(new XAttribute("name", name));
			if (ask != null) {
				item.Add(new XAttribute("ask", ask.ToString()));
			}
			item.Add(new XAttribute("subscription", subscription.ToString()));
			// Erase existing groups in case the item previously existed.
			for (Iterator<XElement> i=item.elementIterator("group"); i.hasNext(); ) {
				item.remove(i.next());
			}
			// Add in groups.
			if (groups != null) {
				foreach (string group in groups) {
					item.Add(new XElement("group", group));
				}
			}
			return new Item(jid, name, ask, subscription, groups);
		}