2014-07-14 19:22:02 +02:00
|
|
|
/**
|
|
|
|
*
|
2015-03-23 09:27:15 +01:00
|
|
|
* Copyright 2003-2007 Jive Software, 2014-2015 Florian Schmaus
|
2014-07-14 19:22:02 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.muc.packet;
|
|
|
|
|
2014-09-11 09:49:16 +02:00
|
|
|
import org.jivesoftware.smack.packet.NamedElement;
|
2015-03-23 09:27:15 +01:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
2014-07-14 19:22:02 +02:00
|
|
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-08-24 18:30:18 +02:00
|
|
|
import org.jivesoftware.smackx.muc.MUCAffiliation;
|
|
|
|
import org.jivesoftware.smackx.muc.MUCRole;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
import org.jxmpp.jid.Jid;
|
|
|
|
import org.jxmpp.jid.parts.Resourcepart;
|
2014-07-14 19:22:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Item child that holds information about roles, affiliation, jids and nicks.
|
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
2014-09-11 09:49:16 +02:00
|
|
|
public class MUCItem implements NamedElement {
|
2015-03-23 09:27:15 +01:00
|
|
|
public static final String ELEMENT = Stanza.ITEM;
|
2014-07-14 19:22:02 +02:00
|
|
|
|
2014-08-24 18:30:18 +02:00
|
|
|
private final MUCAffiliation affiliation;
|
|
|
|
private final MUCRole role;
|
2015-02-14 17:15:02 +01:00
|
|
|
private final Jid actor;
|
2015-09-28 13:05:06 +02:00
|
|
|
private final Resourcepart actorNick;
|
2014-08-24 18:30:18 +02:00
|
|
|
private final String reason;
|
2015-02-14 17:15:02 +01:00
|
|
|
private final Jid jid;
|
|
|
|
private final Resourcepart nick;
|
2014-07-14 19:22:02 +02:00
|
|
|
|
2014-08-24 18:30:18 +02:00
|
|
|
public MUCItem(MUCAffiliation affiliation) {
|
2015-09-28 13:05:06 +02:00
|
|
|
this(affiliation, null, null, null, null, null, null);
|
2014-08-24 18:30:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public MUCItem(MUCRole role) {
|
2015-09-28 13:05:06 +02:00
|
|
|
this(null, role, null, null, null, null, null);
|
2014-08-24 18:30:18 +02:00
|
|
|
}
|
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
public MUCItem(MUCRole role, Resourcepart nick) {
|
2015-09-28 13:05:06 +02:00
|
|
|
this(null, role, null, null, null, nick, null);
|
2014-08-24 18:30:18 +02:00
|
|
|
}
|
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
public MUCItem(MUCAffiliation affiliation, Jid jid, String reason) {
|
2015-09-28 13:05:06 +02:00
|
|
|
this(affiliation, null, null, reason, jid, null, null);
|
2014-08-24 18:30:18 +02:00
|
|
|
}
|
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
public MUCItem(MUCAffiliation affiliation, Jid jid) {
|
2015-09-28 13:05:06 +02:00
|
|
|
this(affiliation, null, null, null, jid, null, null);
|
2014-08-24 18:30:18 +02:00
|
|
|
}
|
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
public MUCItem(MUCRole role, Resourcepart nick, String reason) {
|
2015-09-28 13:05:06 +02:00
|
|
|
this(null, role, null, reason, null, nick, null);
|
2014-07-14 19:22:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new item child.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-07-14 19:22:02 +02:00
|
|
|
* @param affiliation the actor's affiliation to the room
|
|
|
|
* @param role the privilege level of an occupant within a room.
|
2014-08-24 18:30:18 +02:00
|
|
|
* @param actor
|
|
|
|
* @param reason
|
|
|
|
* @param jid
|
|
|
|
* @param nick
|
2015-09-28 13:05:06 +02:00
|
|
|
* @param actorNick
|
2014-07-14 19:22:02 +02:00
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public MUCItem(MUCAffiliation affiliation, MUCRole role, Jid actor,
|
2015-09-28 13:05:06 +02:00
|
|
|
String reason, Jid jid, Resourcepart nick, Resourcepart actorNick) {
|
2014-08-24 18:30:18 +02:00
|
|
|
this.affiliation = affiliation;
|
2014-07-14 19:22:02 +02:00
|
|
|
this.role = role;
|
2014-08-24 18:30:18 +02:00
|
|
|
this.actor = actor;
|
|
|
|
this.reason = reason;
|
|
|
|
this.jid = jid;
|
|
|
|
this.nick = nick;
|
2015-09-28 13:05:06 +02:00
|
|
|
this.actorNick = actorNick;
|
2014-07-14 19:22:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the actor (JID of an occupant in the room) that was kicked or banned.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-07-14 19:22:02 +02:00
|
|
|
* @return the JID of an occupant in the room that was kicked or banned.
|
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public Jid getActor() {
|
2014-07-14 19:22:02 +02:00
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
2015-09-28 13:05:06 +02:00
|
|
|
/**
|
|
|
|
* Get the nickname of the actor.
|
|
|
|
*
|
|
|
|
* @return the nickname of the actor.
|
|
|
|
* @since 4.2
|
|
|
|
*/
|
|
|
|
public Resourcepart getActorNick() {
|
|
|
|
return actorNick;
|
|
|
|
}
|
|
|
|
|
2014-07-14 19:22:02 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-07-14 19:22:02 +02:00
|
|
|
* @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.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-07-14 19:22:02 +02:00
|
|
|
* @return the actor's affiliation to the room
|
|
|
|
*/
|
2014-08-24 18:30:18 +02:00
|
|
|
public MUCAffiliation getAffiliation() {
|
2014-07-14 19:22:02 +02:00
|
|
|
return affiliation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-25 12:51:41 +01:00
|
|
|
* Returns the <room@service/nick> by which an occupant is identified within the context of a
|
2014-07-14 19:22:02 +02:00
|
|
|
* room. If the room is non-anonymous, the JID will be included in the item.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-07-14 19:22:02 +02:00
|
|
|
* @return the room JID by which an occupant is identified within the room.
|
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public Jid getJid() {
|
2014-07-14 19:22:02 +02:00
|
|
|
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.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-07-14 19:22:02 +02:00
|
|
|
* @return the new nickname of an occupant that is changing his/her nickname.
|
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public Resourcepart getNick() {
|
2014-07-14 19:22:02 +02:00
|
|
|
return nick;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the temporary position or privilege level of an occupant within a room. The possible
|
2014-08-24 18:30:18 +02:00
|
|
|
* roles are "moderator", "participant", "visitor" and "none" (it is also possible to have no defined
|
2014-07-14 19:22:02 +02:00
|
|
|
* role). A role lasts only for the duration of an occupant's visit to a room.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-07-14 19:22:02 +02:00
|
|
|
* @return the privilege level of an occupant within a room.
|
|
|
|
*/
|
2014-08-24 18:30:18 +02:00
|
|
|
public MUCRole getRole() {
|
2014-07-14 19:22:02 +02:00
|
|
|
return role;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2018-04-25 14:20:18 +02:00
|
|
|
public XmlStringBuilder toXML(String enclosingNamespace) {
|
2014-07-14 19:22:02 +02:00
|
|
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
|
|
|
xml.optAttribute("affiliation", getAffiliation());
|
|
|
|
xml.optAttribute("jid", getJid());
|
|
|
|
xml.optAttribute("nick", getNick());
|
2015-03-11 12:36:15 +01:00
|
|
|
xml.optAttribute("role", getRole());
|
2014-08-20 21:25:14 +02:00
|
|
|
xml.rightAngleBracket();
|
2014-07-14 19:22:02 +02:00
|
|
|
xml.optElement("reason", getReason());
|
|
|
|
if (getActor() != null) {
|
|
|
|
xml.halfOpenElement("actor").attribute("jid", getActor()).closeEmptyElement();
|
|
|
|
}
|
2015-03-23 09:27:15 +01:00
|
|
|
xml.closeElement(Stanza.ITEM);
|
2014-07-14 19:22:02 +02:00
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getElementName() {
|
|
|
|
return ELEMENT;
|
|
|
|
}
|
|
|
|
}
|