1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-14 15:01:07 +01:00

Prefix subprojects with 'smack-'

instead of using the old baseName=smack appendix=project.name approach,
we are now going convention over configuration and renaming the
subprojects directories to the proper name.

Having a prefix is actually very helpful, because the resulting
libraries will be named like the subproject. And a core-4.0.0-rc1.jar is
not as explicit about what it actually *is* as a
smack-core-4.0.0-rc1.jar.

SMACK-265
This commit is contained in:
Florian Schmaus 2014-04-28 19:27:53 +02:00
parent b6fb1f3743
commit 91fd15ad86
758 changed files with 42 additions and 42 deletions

View file

@ -0,0 +1,95 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import org.jivesoftware.smackx.muc.packet.MUCAdmin;
import org.jivesoftware.smackx.muc.packet.MUCOwner;
/**
* Represents an affiliation of a user to a given room. The affiliate's information will always have
* the bare jid of the real user and its affiliation. If the affiliate is an occupant of the room
* then we will also have information about the role and nickname of the user in the room.
*
* @author Gaston Dombiak
*/
public class Affiliate {
// Fields that must have a value
private String jid;
private String affiliation;
// Fields that may have a value
private String role;
private String nick;
Affiliate(MUCOwner.Item item) {
super();
this.jid = item.getJid();
this.affiliation = item.getAffiliation();
this.role = item.getRole();
this.nick = item.getNick();
}
Affiliate(MUCAdmin.Item item) {
super();
this.jid = item.getJid();
this.affiliation = item.getAffiliation();
this.role = item.getRole();
this.nick = item.getNick();
}
/**
* Returns the bare JID of the affiliated user. This information will always be available.
*
* @return the bare JID of the affiliated user.
*/
public String getJid() {
return jid;
}
/**
* Returns the affiliation of the afffiliated user. Possible affiliations are: "owner", "admin",
* "member", "outcast". This information will always be available.
*
* @return the affiliation of the afffiliated user.
*/
public String getAffiliation() {
return affiliation;
}
/**
* Returns the current role of the affiliated user if the user is currently in the room.
* If the user is not present in the room then the answer will be null.
*
* @return the current role of the affiliated user in the room or null if the user is not in
* the room.
*/
public String getRole() {
return role;
}
/**
* Returns the current nickname of the affiliated user if the user is currently in the room.
* If the user is not present in the room then the answer will be null.
*
* @return the current nickname of the affiliated user in the room or null if the user is not in
* the room.
*/
public String getNick() {
return nick;
}
}

View file

@ -0,0 +1,113 @@
/**
*
* Copyright 2003-2006 Jive Software.
*
* 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;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.packet.Packet;
/**
* A variant of the {@link org.jivesoftware.smack.PacketCollector} class
* that does not force attachment to a <code>XMPPConnection</code>
* on creation and no filter is required. Used to collect message
* packets targeted to a group chat room.
*
* @author Larry Kirschner
*/
class ConnectionDetachedPacketCollector {
private ArrayBlockingQueue<Packet> resultQueue;
/**
* Creates a new packet collector. If the packet filter is <tt>null</tt>, then
* all packets will match this collector.
*/
public ConnectionDetachedPacketCollector() {
this(SmackConfiguration.getPacketCollectorSize());
}
/**
* Creates a new packet collector. If the packet filter is <tt>null</tt>, then
* all packets will match this collector.
*/
public ConnectionDetachedPacketCollector(int maxSize) {
this.resultQueue = new ArrayBlockingQueue<Packet>(maxSize);
}
/**
* Polls to see if a packet is currently available and returns it, or
* immediately returns <tt>null</tt> if no packets are currently in the
* result queue.
*
* @return the next packet result, or <tt>null</tt> if there are no more
* results.
*/
public Packet pollResult() {
return resultQueue.poll();
}
/**
* Returns the next available packet. The method call will block (not return)
* until a packet is available.
*
* @return the next available packet.
*/
public Packet nextResult() {
try {
return resultQueue.take();
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
/**
* Returns the next available packet. The method call will block (not return)
* until a packet is available or the <tt>timeout</tt> has elapased. If the
* timeout elapses without a result, <tt>null</tt> will be returned.
*
* @param timeout the amount of time to wait for the next packet (in milleseconds).
* @return the next available packet.
*/
public Packet nextResult(long timeout) {
try {
return resultQueue.poll(timeout, TimeUnit.MILLISECONDS);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
/**
* Processes a packet to see if it meets the criteria for this packet collector.
* If so, the packet is added to the result queue.
*
* @param packet the packet to process.
*/
protected void processPacket(Packet packet) {
if (packet == null) {
return;
}
while (!resultQueue.offer(packet)) {
// Since we know the queue is full, this poll should never actually block.
resultQueue.poll();
}
}
}

View file

@ -0,0 +1,73 @@
/**
*
* Copyright 2003-2006 Jive Software.
*
* 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;
import org.jivesoftware.smack.PacketInterceptor;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.Presence;
/**
* Packet interceptor that will intercept presence packets sent to the MUC service to indicate
* that the user wants to be a deaf occupant. A user can only indicate that he wants to be a
* deaf occupant while joining the room. It is not possible to become deaf or stop being deaf
* after the user joined the room.<p>
*
* Deaf occupants will not get messages broadcasted to all room occupants. However, they will
* be able to get private messages, presences, IQ packets or room history. To use this
* functionality you will need to send the message
* {@link MultiUserChat#addPresenceInterceptor(org.jivesoftware.smack.PacketInterceptor)} and
* pass this interceptor as the parameter.<p>
*
* Note that this is a custom extension to the MUC service so it may not work with other servers
* than Wildfire.
*
* @author Gaston Dombiak
*/
public class DeafOccupantInterceptor implements PacketInterceptor {
public void interceptPacket(Packet packet) {
Presence presence = (Presence) packet;
// Check if user is joining a room
if (Presence.Type.available == presence.getType() &&
presence.getExtension("x", "http://jabber.org/protocol/muc") != null) {
// Add extension that indicates that user wants to be a deaf occupant
packet.addExtension(new DeafExtension());
}
}
private static class DeafExtension implements PacketExtension {
public String getElementName() {
return "x";
}
public String getNamespace() {
return "http://jivesoftware.org/protocol/muc";
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace())
.append("\">");
buf.append("<deaf-occupant/>");
buf.append("</").append(getElementName()).append(">");
return buf.toString();
}
}
}

View file

@ -0,0 +1,76 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
/**
* Default implementation of the ParticipantStatusListener interface.<p>
*
* This class does not provide any behavior by default. It just avoids having
* to implement all the inteface methods if the user is only interested in implementing
* some of the methods.
*
* @author Gaston Dombiak
*/
public class DefaultParticipantStatusListener implements ParticipantStatusListener {
public void joined(String participant) {
}
public void left(String participant) {
}
public void kicked(String participant, String actor, String reason) {
}
public void voiceGranted(String participant) {
}
public void voiceRevoked(String participant) {
}
public void banned(String participant, String actor, String reason) {
}
public void membershipGranted(String participant) {
}
public void membershipRevoked(String participant) {
}
public void moderatorGranted(String participant) {
}
public void moderatorRevoked(String participant) {
}
public void ownershipGranted(String participant) {
}
public void ownershipRevoked(String participant) {
}
public void adminGranted(String participant) {
}
public void adminRevoked(String participant) {
}
public void nicknameChanged(String participant, String newNickname) {
}
}

View file

@ -0,0 +1,67 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
/**
* Default implementation of the UserStatusListener interface.<p>
*
* This class does not provide any behavior by default. It just avoids having
* to implement all the inteface methods if the user is only interested in implementing
* some of the methods.
*
* @author Gaston Dombiak
*/
public class DefaultUserStatusListener implements UserStatusListener {
public void kicked(String actor, String reason) {
}
public void voiceGranted() {
}
public void voiceRevoked() {
}
public void banned(String actor, String reason) {
}
public void membershipGranted() {
}
public void membershipRevoked() {
}
public void moderatorGranted() {
}
public void moderatorRevoked() {
}
public void ownershipGranted() {
}
public void ownershipRevoked() {
}
public void adminGranted() {
}
public void adminRevoked() {
}
}

View file

@ -0,0 +1,168 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import java.util.Date;
import org.jivesoftware.smackx.muc.packet.MUCInitialPresence;
/**
* The DiscussionHistory class controls the number of characters or messages to receive
* when entering a room. The room will decide the amount of history to return if you don't
* specify a DiscussionHistory while joining a room.<p>
*
* You can use some or all of these variable to control the amount of history to receive:
* <ul>
* <li>maxchars -> total number of characters to receive in the history.
* <li>maxstanzas -> total number of messages to receive in the history.
* <li>seconds -> only the messages received in the last "X" seconds will be included in the
* history.
* <li>since -> only the messages received since the datetime specified will be included in
* the history.
* </ul>
*
* Note: Setting maxchars to 0 indicates that the user requests to receive no history.
*
* @author Gaston Dombiak
*/
public class DiscussionHistory {
private int maxChars = -1;
private int maxStanzas = -1;
private int seconds = -1;
private Date since;
/**
* Returns the total number of characters to receive in the history.
*
* @return total number of characters to receive in the history.
*/
public int getMaxChars() {
return maxChars;
}
/**
* Returns the total number of messages to receive in the history.
*
* @return the total number of messages to receive in the history.
*/
public int getMaxStanzas() {
return maxStanzas;
}
/**
* Returns the number of seconds to use to filter the messages received during that time.
* In other words, only the messages received in the last "X" seconds will be included in
* the history.
*
* @return the number of seconds to use to filter the messages received during that time.
*/
public int getSeconds() {
return seconds;
}
/**
* Returns the since date to use to filter the messages received during that time.
* In other words, only the messages received since the datetime specified will be
* included in the history.
*
* @return the since date to use to filter the messages received during that time.
*/
public Date getSince() {
return since;
}
/**
* Sets the total number of characters to receive in the history.
*
* @param maxChars the total number of characters to receive in the history.
*/
public void setMaxChars(int maxChars) {
this.maxChars = maxChars;
}
/**
* Sets the total number of messages to receive in the history.
*
* @param maxStanzas the total number of messages to receive in the history.
*/
public void setMaxStanzas(int maxStanzas) {
this.maxStanzas = maxStanzas;
}
/**
* Sets the number of seconds to use to filter the messages received during that time.
* In other words, only the messages received in the last "X" seconds will be included in
* the history.
*
* @param seconds the number of seconds to use to filter the messages received during
* that time.
*/
public void setSeconds(int seconds) {
this.seconds = seconds;
}
/**
* Sets the since date to use to filter the messages received during that time.
* In other words, only the messages received since the datetime specified will be
* included in the history.
*
* @param since the since date to use to filter the messages received during that time.
*/
public void setSince(Date since) {
this.since = since;
}
/**
* Returns true if the history has been configured with some values.
*
* @return true if the history has been configured with some values.
*/
private boolean isConfigured() {
return maxChars > -1 || maxStanzas > -1 || seconds > -1 || since != null;
}
/**
* Returns the History that manages the amount of discussion history provided on entering a
* room.
*
* @return the History that manages the amount of discussion history provided on entering a
* room.
*/
MUCInitialPresence.History getMUCHistory() {
// Return null if the history was not properly configured
if (!isConfigured()) {
return null;
}
MUCInitialPresence.History mucHistory = new MUCInitialPresence.History();
if (maxChars > -1) {
mucHistory.setMaxChars(maxChars);
}
if (maxStanzas > -1) {
mucHistory.setMaxStanzas(maxStanzas);
}
if (seconds > -1) {
mucHistory.setSeconds(seconds);
}
if (since != null) {
mucHistory.setSince(since);
}
return mucHistory;
}
}

View file

@ -0,0 +1,62 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
/**
* Hosted rooms by a chat service may be discovered if they are configured to appear in the room
* directory . The information that may be discovered is the XMPP address of the room and the room
* name. The address of the room may be used for obtaining more detailed information
* {@link org.jivesoftware.smackx.muc.MultiUserChat#getRoomInfo(org.jivesoftware.smack.XMPPConnection, String)}
* or could be used for joining the room
* {@link org.jivesoftware.smackx.muc.MultiUserChat#MultiUserChat(org.jivesoftware.smack.XMPPConnection, String)}
* and {@link org.jivesoftware.smackx.muc.MultiUserChat#join(String)}.
*
* @author Gaston Dombiak
*/
public class HostedRoom {
private String jid;
private String name;
public HostedRoom(DiscoverItems.Item item) {
super();
jid = item.getEntityID();
name = item.getName();
}
/**
* Returns the XMPP address of the hosted room by the chat service. This address may be used
* when creating a <code>MultiUserChat</code> when joining a room.
*
* @return the XMPP address of the hosted room by the chat service.
*/
public String getJid() {
return jid;
}
/**
* Returns the name of the room.
*
* @return the name of the room.
*/
public String getName() {
return name;
}
}

View file

@ -0,0 +1,46 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message;
/**
* A listener that is fired anytime an invitation to join a MUC room is received.
*
* @author Gaston Dombiak
*/
public interface InvitationListener {
/**
* Called when the an invitation to join a MUC room is received.<p>
*
* If the room is password-protected, the invitee will receive a password to use to join
* the room. If the room is members-only, the the invitee may be added to the member list.
*
* @param conn the XMPPConnection that received the invitation.
* @param room the room that invitation refers to.
* @param inviter the inviter that sent the invitation. (e.g. crone1@shakespeare.lit).
* @param reason the reason why the inviter sent the invitation.
* @param password the password to use when joining the room.
* @param message the message used by the inviter to send the invitation.
*/
public abstract void invitationReceived(XMPPConnection conn, String room, String inviter, String reason,
String password, Message message);
}

View file

@ -0,0 +1,35 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
/**
* A listener that is fired anytime an invitee declines or rejects an invitation.
*
* @author Gaston Dombiak
*/
public interface InvitationRejectionListener {
/**
* Called when the invitee declines the invitation.
*
* @param invitee the invitee that declined the invitation. (e.g. hecate@shakespeare.lit).
* @param reason the reason why the invitee declined the invitation.
*/
public abstract void invitationDeclined(String invitee, String reason);
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,118 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import org.jivesoftware.smackx.muc.packet.MUCAdmin;
import org.jivesoftware.smackx.muc.packet.MUCUser;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils;
/**
* Represents the information about an occupant in a given room. The information will always have
* the affiliation and role of the occupant in the room. The full JID and nickname are optional.
*
* @author Gaston Dombiak
*/
public class Occupant {
// Fields that must have a value
private String affiliation;
private String role;
// Fields that may have a value
private String jid;
private String nick;
Occupant(MUCAdmin.Item item) {
super();
this.jid = item.getJid();
this.affiliation = item.getAffiliation();
this.role = item.getRole();
this.nick = item.getNick();
}
Occupant(Presence presence) {
super();
MUCUser mucUser = (MUCUser) presence.getExtension("x",
"http://jabber.org/protocol/muc#user");
MUCUser.Item item = mucUser.getItem();
this.jid = item.getJid();
this.affiliation = item.getAffiliation();
this.role = item.getRole();
// Get the nickname from the FROM attribute of the presence
this.nick = StringUtils.parseResource(presence.getFrom());
}
/**
* Returns the full JID of the occupant. If this information was extracted from a presence and
* the room is semi or full-anonymous then the answer will be null. On the other hand, if this
* information was obtained while maintaining the voice list or the moderator list then we will
* always have a full JID.
*
* @return the full JID of the occupant.
*/
public String getJid() {
return jid;
}
/**
* Returns the affiliation of the occupant. Possible affiliations are: "owner", "admin",
* "member", "outcast". This information will always be available.
*
* @return the affiliation of the occupant.
*/
public String getAffiliation() {
return affiliation;
}
/**
* Returns the current role of the occupant in the room. This information will always be
* available.
*
* @return the current role of the occupant in the room.
*/
public String getRole() {
return role;
}
/**
* Returns the current nickname of the occupant in the room. If this information was extracted
* from a presence then the answer will be null.
*
* @return the current nickname of the occupant in the room or null if this information was
* obtained from a presence.
*/
public String getNick() {
return nick;
}
public boolean equals(Object obj) {
if(!(obj instanceof Occupant)) {
return false;
}
Occupant occupant = (Occupant)obj;
return jid.equals(occupant.jid);
}
public int hashCode() {
int result;
result = affiliation.hashCode();
result = 17 * result + role.hashCode();
result = 17 * result + jid.hashCode();
result = 17 * result + (nick != null ? nick.hashCode() : 0);
return result;
}
}

View file

@ -0,0 +1,94 @@
/**
*
* Copyright 2003-2006 Jive Software.
*
* 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;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
/**
* The single <code>PacketListener</code> used by each {@link MultiUserChat}
* for all basic processing of presence, and message packets targeted to that chat.
*
* @author Larry Kirschner
*/
class PacketMultiplexListener implements PacketListener {
private static final PacketFilter MESSAGE_FILTER =
new MessageTypeFilter(Message.Type.groupchat);
private static final PacketFilter PRESENCE_FILTER = new PacketTypeFilter(Presence.class);
private static final PacketFilter SUBJECT_FILTER = new PacketFilter() {
public boolean accept(Packet packet) {
Message msg = (Message) packet;
return msg.getSubject() != null;
}
};
private static final PacketFilter DECLINES_FILTER =
new PacketExtensionFilter("x",
"http://jabber.org/protocol/muc#user");
private ConnectionDetachedPacketCollector messageCollector;
private PacketListener presenceListener;
private PacketListener subjectListener;
private PacketListener declinesListener;
public PacketMultiplexListener(
ConnectionDetachedPacketCollector messageCollector,
PacketListener presenceListener,
PacketListener subjectListener, PacketListener declinesListener) {
if (messageCollector == null) {
throw new IllegalArgumentException("MessageCollector is null");
}
if (presenceListener == null) {
throw new IllegalArgumentException("Presence listener is null");
}
if (subjectListener == null) {
throw new IllegalArgumentException("Subject listener is null");
}
if (declinesListener == null) {
throw new IllegalArgumentException("Declines listener is null");
}
this.messageCollector = messageCollector;
this.presenceListener = presenceListener;
this.subjectListener = subjectListener;
this.declinesListener = declinesListener;
}
public void processPacket(Packet p) throws NotConnectedException {
if (PRESENCE_FILTER.accept(p)) {
presenceListener.processPacket(p);
}
else if (MESSAGE_FILTER.accept(p)) {
messageCollector.processPacket(p);
if (SUBJECT_FILTER.accept(p)) {
subjectListener.processPacket(p);
}
}
else if (DECLINES_FILTER.accept(p)) {
declinesListener.processPacket(p);
}
}
}

View file

@ -0,0 +1,176 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
/**
* A listener that is fired anytime a participant's status in a room is changed, such as the
* user being kicked, banned, or granted admin permissions.
*
* @author Gaston Dombiak
*/
public interface ParticipantStatusListener {
/**
* Called when a new room occupant has joined the room. Note: Take in consideration that when
* you join a room you will receive the list of current occupants in the room. This message will
* be sent for each occupant.
*
* @param participant the participant that has just joined the room
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void joined(String participant);
/**
* Called when a room occupant has left the room on its own. This means that the occupant was
* neither kicked nor banned from the room.
*
* @param participant the participant that has left the room on its own.
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void left(String participant);
/**
* Called when a room participant has been kicked from the room. This means that the kicked
* participant is no longer participating in the room.
*
* @param participant the participant that was kicked from the room
* (e.g. room@conference.jabber.org/nick).
* @param actor the moderator that kicked the occupant from the room (e.g. user@host.org).
* @param reason the reason provided by the actor to kick the occupant from the room.
*/
public abstract void kicked(String participant, String actor, String reason);
/**
* Called when a moderator grants voice to a visitor. This means that the visitor
* can now participate in the moderated room sending messages to all occupants.
*
* @param participant the participant that was granted voice in the room
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void voiceGranted(String participant);
/**
* Called when a moderator revokes voice from a participant. This means that the participant
* in the room was able to speak and now is a visitor that can't send messages to the room
* occupants.
*
* @param participant the participant that was revoked voice from the room
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void voiceRevoked(String participant);
/**
* Called when an administrator or owner banned a participant from the room. This means that
* banned participant will no longer be able to join the room unless the ban has been removed.
*
* @param participant the participant that was banned from the room
* (e.g. room@conference.jabber.org/nick).
* @param actor the administrator that banned the occupant (e.g. user@host.org).
* @param reason the reason provided by the administrator to ban the occupant.
*/
public abstract void banned(String participant, String actor, String reason);
/**
* Called when an administrator grants a user membership to the room. This means that the user
* will be able to join the members-only room.
*
* @param participant the participant that was granted membership in the room
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void membershipGranted(String participant);
/**
* Called when an administrator revokes a user membership to the room. This means that the
* user will not be able to join the members-only room.
*
* @param participant the participant that was revoked membership from the room
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void membershipRevoked(String participant);
/**
* Called when an administrator grants moderator privileges to a user. This means that the user
* will be able to kick users, grant and revoke voice, invite other users, modify room's
* subject plus all the partcipants privileges.
*
* @param participant the participant that was granted moderator privileges in the room
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void moderatorGranted(String participant);
/**
* Called when an administrator revokes moderator privileges from a user. This means that the
* user will no longer be able to kick users, grant and revoke voice, invite other users,
* modify room's subject plus all the partcipants privileges.
*
* @param participant the participant that was revoked moderator privileges in the room
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void moderatorRevoked(String participant);
/**
* Called when an owner grants a user ownership on the room. This means that the user
* will be able to change defining room features as well as perform all administrative
* functions.
*
* @param participant the participant that was granted ownership on the room
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void ownershipGranted(String participant);
/**
* Called when an owner revokes a user ownership on the room. This means that the user
* will no longer be able to change defining room features as well as perform all
* administrative functions.
*
* @param participant the participant that was revoked ownership on the room
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void ownershipRevoked(String participant);
/**
* Called when an owner grants administrator privileges to a user. This means that the user
* will be able to perform administrative functions such as banning users and edit moderator
* list.
*
* @param participant the participant that was granted administrator privileges
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void adminGranted(String participant);
/**
* Called when an owner revokes administrator privileges from a user. This means that the user
* will no longer be able to perform administrative functions such as banning users and edit
* moderator list.
*
* @param participant the participant that was revoked administrator privileges
* (e.g. room@conference.jabber.org/nick).
*/
public abstract void adminRevoked(String participant);
/**
* Called when a participant changed his/her nickname in the room. The new participant's
* nickname will be informed with the next available presence.
*
* @param participant the participant that was revoked administrator privileges
* (e.g. room@conference.jabber.org/nick).
* @param newNickname the new nickname that the participant decided to use.
*/
public abstract void nicknameChanged(String participant, String newNickname);
}

View file

@ -0,0 +1,185 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
/**
* Represents the room information that was discovered using Service Discovery. It's possible to
* obtain information about a room before joining the room but only for rooms that are public (i.e.
* rooms that may be discovered).
*
* @author Gaston Dombiak
*/
public class RoomInfo {
/**
* JID of the room. The node of the JID is commonly used as the ID of the room or name.
*/
private String room;
/**
* Description of the room.
*/
private String description = "";
/**
* Last known subject of the room.
*/
private String subject = "";
/**
* Current number of occupants in the room.
*/
private int occupantsCount = -1;
/**
* A room is considered members-only if an invitation is required in order to enter the room.
* Any user that is not a member of the room won't be able to join the room unless the user
* decides to register with the room (thus becoming a member).
*/
private boolean membersOnly;
/**
* Moderated rooms enable only participants to speak. Users that join the room and aren't
* participants can't speak (they are just visitors).
*/
private boolean moderated;
/**
* Every presence packet can include the JID of every occupant unless the owner deactives this
* configuration.
*/
private boolean nonanonymous;
/**
* Indicates if users must supply a password to join the room.
*/
private boolean passwordProtected;
/**
* Persistent rooms are saved to the database to make sure that rooms configurations can be
* restored in case the server goes down.
*/
private boolean persistent;
RoomInfo(DiscoverInfo info) {
super();
this.room = info.getFrom();
// Get the information based on the discovered features
this.membersOnly = info.containsFeature("muc_membersonly");
this.moderated = info.containsFeature("muc_moderated");
this.nonanonymous = info.containsFeature("muc_nonanonymous");
this.passwordProtected = info.containsFeature("muc_passwordprotected");
this.persistent = info.containsFeature("muc_persistent");
// Get the information based on the discovered extended information
Form form = Form.getFormFrom(info);
if (form != null) {
FormField descField = form.getField("muc#roominfo_description");
this.description = ( descField == null || descField.getValues().isEmpty() ) ? "" : descField.getValues().get(0);
FormField subjField = form.getField("muc#roominfo_subject");
this.subject = ( subjField == null || subjField.getValues().isEmpty() ) ? "" : subjField.getValues().get(0);
FormField occCountField = form.getField("muc#roominfo_occupants");
this.occupantsCount = occCountField == null ? -1 : Integer.parseInt(occCountField.getValues()
.get(0));
}
}
/**
* Returns the JID of the room whose information was discovered.
*
* @return the JID of the room whose information was discovered.
*/
public String getRoom() {
return room;
}
/**
* Returns the discovered description of the room.
*
* @return the discovered description of the room.
*/
public String getDescription() {
return description;
}
/**
* Returns the discovered subject of the room. The subject may be empty if the room does not
* have a subject.
*
* @return the discovered subject of the room.
*/
public String getSubject() {
return subject;
}
/**
* Returns the discovered number of occupants that are currently in the room. If this
* information was not discovered (i.e. the server didn't send it) then a value of -1 will be
* returned.
*
* @return the number of occupants that are currently in the room or -1 if that information was
* not provided by the server.
*/
public int getOccupantsCount() {
return occupantsCount;
}
/**
* Returns true if the room has restricted the access so that only members may enter the room.
*
* @return true if the room has restricted the access so that only members may enter the room.
*/
public boolean isMembersOnly() {
return membersOnly;
}
/**
* Returns true if the room enabled only participants to speak. Occupants with a role of
* visitor won't be able to speak in the room.
*
* @return true if the room enabled only participants to speak.
*/
public boolean isModerated() {
return moderated;
}
/**
* Returns true if presence packets will include the JID of every occupant.
*
* @return true if presence packets will include the JID of every occupant.
*/
public boolean isNonanonymous() {
return nonanonymous;
}
/**
* Returns true if users musy provide a valid password in order to join the room.
*
* @return true if users musy provide a valid password in order to join the room.
*/
public boolean isPasswordProtected() {
return passwordProtected;
}
/**
* Returns true if the room will persist after the last occupant have left the room.
*
* @return true if the room will persist after the last occupant have left the room.
*/
public boolean isPersistent() {
return persistent;
}
}

View file

@ -0,0 +1,216 @@
/**
*
* Copyright 2003-2006 Jive Software.
*
* 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;
import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.StringUtils;
import java.lang.ref.WeakReference;
import java.util.Locale;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
/**
* A <code>RoomListenerMultiplexor</code> multiplexes incoming packets on
* a <code>XMPPConnection</code> using a single listener/filter pair.
* A single <code>RoomListenerMultiplexor</code> is created for each
* {@link org.jivesoftware.smack.XMPPConnection} that has joined MUC rooms
* within its session.
*
* @author Larry Kirschner
*/
class RoomListenerMultiplexor extends AbstractConnectionListener {
// We use a WeakHashMap so that the GC can collect the monitor when the
// connection is no longer referenced by any object.
private static final Map<XMPPConnection, WeakReference<RoomListenerMultiplexor>> monitors =
new WeakHashMap<XMPPConnection, WeakReference<RoomListenerMultiplexor>>();
private XMPPConnection connection;
private RoomMultiplexFilter filter;
private RoomMultiplexListener listener;
/**
* Returns a new or existing RoomListenerMultiplexor for a given connection.
*
* @param conn the connection to monitor for room invitations.
* @return a new or existing RoomListenerMultiplexor for a given connection.
*/
public static RoomListenerMultiplexor getRoomMultiplexor(XMPPConnection conn) {
synchronized (monitors) {
if (!monitors.containsKey(conn) || monitors.get(conn).get() == null) {
RoomListenerMultiplexor rm = new RoomListenerMultiplexor(conn, new RoomMultiplexFilter(),
new RoomMultiplexListener());
rm.init();
// We need to use a WeakReference because the monitor references the
// connection and this could prevent the GC from collecting the monitor
// when no other object references the monitor
monitors.put(conn, new WeakReference<RoomListenerMultiplexor>(rm));
}
// Return the InvitationsMonitor that monitors the connection
return monitors.get(conn).get();
}
}
/**
* All access should be through
* the static method {@link #getRoomMultiplexor(XMPPConnection)}.
*/
private RoomListenerMultiplexor(XMPPConnection connection, RoomMultiplexFilter filter,
RoomMultiplexListener listener) {
if (connection == null) {
throw new IllegalArgumentException("XMPPConnection is null");
}
if (filter == null) {
throw new IllegalArgumentException("Filter is null");
}
if (listener == null) {
throw new IllegalArgumentException("Listener is null");
}
this.connection = connection;
this.filter = filter;
this.listener = listener;
}
public void addRoom(String address, PacketMultiplexListener roomListener) {
filter.addRoom(address);
listener.addRoom(address, roomListener);
}
@Override
public void connectionClosed() {
cancel();
}
@Override
public void connectionClosedOnError(Exception e) {
cancel();
}
/**
* Initializes the listeners to detect received room invitations and to detect when the
* connection gets closed. As soon as a room invitation is received the invitations
* listeners will be fired. When the connection gets closed the monitor will remove
* his listeners on the connection.
*/
public void init() {
connection.addConnectionListener(this);
connection.addPacketListener(listener, filter);
}
public void removeRoom(String address) {
filter.removeRoom(address);
listener.removeRoom(address);
}
/**
* Cancels all the listeners that this InvitationsMonitor has added to the connection.
*/
private void cancel() {
connection.removeConnectionListener(this);
connection.removePacketListener(listener);
}
/**
* The single <code>XMPPConnection</code>-level <code>PacketFilter</code> used by a {@link RoomListenerMultiplexor}
* for all muc chat rooms on an <code>XMPPConnection</code>.
* Each time a muc chat room is added to/removed from an
* <code>XMPPConnection</code> the address for that chat room
* is added to/removed from that <code>XMPPConnection</code>'s
* <code>RoomMultiplexFilter</code>.
*/
private static class RoomMultiplexFilter implements PacketFilter {
private Map<String, String> roomAddressTable = new ConcurrentHashMap<String, String>();
public boolean accept(Packet p) {
String from = p.getFrom();
if (from == null) {
return false;
}
return roomAddressTable.containsKey(StringUtils.parseBareAddress(from).toLowerCase(Locale.US));
}
public void addRoom(String address) {
if (address == null) {
return;
}
roomAddressTable.put(address.toLowerCase(Locale.US), address);
}
public void removeRoom(String address) {
if (address == null) {
return;
}
roomAddressTable.remove(address.toLowerCase(Locale.US));
}
}
/**
* The single <code>XMPPConnection</code>-level <code>PacketListener</code>
* used by a {@link RoomListenerMultiplexor}
* for all muc chat rooms on an <code>XMPPConnection</code>.
* Each time a muc chat room is added to/removed from an
* <code>XMPPConnection</code> the address and listener for that chat room
* are added to/removed from that <code>XMPPConnection</code>'s
* <code>RoomMultiplexListener</code>.
*
* @author Larry Kirschner
*/
private static class RoomMultiplexListener implements PacketListener {
private Map<String, PacketMultiplexListener> roomListenersByAddress =
new ConcurrentHashMap<String, PacketMultiplexListener>();
public void processPacket(Packet p) throws NotConnectedException {
String from = p.getFrom();
if (from == null) {
return;
}
PacketMultiplexListener listener =
roomListenersByAddress.get(StringUtils.parseBareAddress(from).toLowerCase(Locale.US));
if (listener != null) {
listener.processPacket(p);
}
}
public void addRoom(String address, PacketMultiplexListener listener) {
if (address == null) {
return;
}
roomListenersByAddress.put(address.toLowerCase(Locale.US), listener);
}
public void removeRoom(String address) {
if (address == null) {
return;
}
roomListenersByAddress.remove(address.toLowerCase(Locale.US));
}
}
}

View file

@ -0,0 +1,35 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
/**
* A listener that is fired anytime a MUC room changes its subject.
*
* @author Gaston Dombiak
*/
public interface SubjectUpdatedListener {
/**
* Called when a MUC room has changed its subject.
*
* @param subject the new room's subject.
* @param from the user that changed the room's subject (e.g. room@conference.jabber.org/nick).
*/
public abstract void subjectUpdated(String subject, String from);
}

View file

@ -0,0 +1,124 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
/**
* A listener that is fired anytime your participant's status in a room is changed, such as the
* user being kicked, banned, or granted admin permissions.
*
* @author Gaston Dombiak
*/
public interface UserStatusListener {
/**
* Called when a moderator kicked your user from the room. This means that you are no longer
* participanting in the room.
*
* @param actor the moderator that kicked your user from the room (e.g. user@host.org).
* @param reason the reason provided by the actor to kick you from the room.
*/
public abstract void kicked(String actor, String reason);
/**
* Called when a moderator grants voice to your user. This means that you were a visitor in
* the moderated room before and now you can participate in the room by sending messages to
* all occupants.
*
*/
public abstract void voiceGranted();
/**
* Called when a moderator revokes voice from your user. This means that you were a
* participant in the room able to speak and now you are a visitor that can't send
* messages to the room occupants.
*
*/
public abstract void voiceRevoked();
/**
* Called when an administrator or owner banned your user from the room. This means that you
* will no longer be able to join the room unless the ban has been removed.
*
* @param actor the administrator that banned your user (e.g. user@host.org).
* @param reason the reason provided by the administrator to banned you.
*/
public abstract void banned(String actor, String reason);
/**
* Called when an administrator grants your user membership to the room. This means that you
* will be able to join the members-only room.
*
*/
public abstract void membershipGranted();
/**
* Called when an administrator revokes your user membership to the room. This means that you
* will not be able to join the members-only room.
*
*/
public abstract void membershipRevoked();
/**
* Called when an administrator grants moderator privileges to your user. This means that you
* will be able to kick users, grant and revoke voice, invite other users, modify room's
* subject plus all the partcipants privileges.
*
*/
public abstract void moderatorGranted();
/**
* Called when an administrator revokes moderator privileges from your user. This means that
* you will no longer be able to kick users, grant and revoke voice, invite other users,
* modify room's subject plus all the partcipants privileges.
*
*/
public abstract void moderatorRevoked();
/**
* Called when an owner grants to your user ownership on the room. This means that you
* will be able to change defining room features as well as perform all administrative
* functions.
*
*/
public abstract void ownershipGranted();
/**
* Called when an owner revokes from your user ownership on the room. This means that you
* will no longer be able to change defining room features as well as perform all
* administrative functions.
*
*/
public abstract void ownershipRevoked();
/**
* Called when an owner grants administrator privileges to your user. This means that you
* will be able to perform administrative functions such as banning users and edit moderator
* list.
*
*/
public abstract void adminGranted();
/**
* Called when an owner revokes administrator privileges from your user. This means that you
* will no longer be able to perform administrative functions such as banning users and edit
* moderator list.
*
*/
public abstract void adminRevoked();
}

View file

@ -0,0 +1 @@
<body>Classes and Interfaces that implement Multi-User Chat (MUC).</body>

View file

@ -0,0 +1,112 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.xmlpull.v1.XmlPullParser;
/**
* A group chat invitation packet extension, which is used to invite other
* users to a group chat room. To invite a user to a group chat room, address
* a new message to the user and set the room name appropriately, as in the
* following code example:
*
* <pre>
* Message message = new Message("user@chat.example.com");
* message.setBody("Join me for a group chat!");
* message.addExtension(new GroupChatInvitation("room@chat.example.com"););
* con.sendPacket(message);
* </pre>
*
* To listen for group chat invitations, use a PacketExtensionFilter for the
* <tt>x</tt> element name and <tt>jabber:x:conference</tt> namespace, as in the
* following code example:
*
* <pre>
* PacketFilter filter = new PacketExtensionFilter("x", "jabber:x:conference");
* // Create a packet collector or packet listeners using the filter...
* </pre>
*
* <b>Note</b>: this protocol is outdated now that the Multi-User Chat (MUC) JEP is available
* (<a href="http://www.jabber.org/jeps/jep-0045.html">JEP-45</a>). However, most
* existing clients still use this older protocol. Once MUC support becomes more
* widespread, this API may be deprecated.
*
* @author Matt Tucker
*/
public class GroupChatInvitation implements PacketExtension {
/**
* Element name of the packet extension.
*/
public static final String ELEMENT_NAME = "x";
/**
* Namespace of the packet extension.
*/
public static final String NAMESPACE = "jabber:x:conference";
private String roomAddress;
/**
* Creates a new group chat invitation to the specified room address.
* GroupChat room addresses are in the form <tt>room@service</tt>,
* where <tt>service</tt> is the name of groupchat server, such as
* <tt>chat.example.com</tt>.
*
* @param roomAddress the address of the group chat room.
*/
public GroupChatInvitation(String roomAddress) {
this.roomAddress = roomAddress;
}
/**
* Returns the address of the group chat room. GroupChat room addresses
* are in the form <tt>room@service</tt>, where <tt>service</tt> is
* the name of groupchat server, such as <tt>chat.example.com</tt>.
*
* @return the address of the group chat room.
*/
public String getRoomAddress() {
return roomAddress;
}
public String getElementName() {
return ELEMENT_NAME;
}
public String getNamespace() {
return NAMESPACE;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<x xmlns=\"jabber:x:conference\" jid=\"").append(roomAddress).append("\"/>");
return buf.toString();
}
public static class Provider implements PacketExtensionProvider {
public PacketExtension parseExtension (XmlPullParser parser) throws Exception {
String roomAddress = parser.getAttributeValue("", "jid");
// Advance to end of extension.
parser.next();
return new GroupChatInvitation(roomAddress);
}
}
}

View file

@ -0,0 +1,233 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jivesoftware.smack.packet.IQ;
/**
* 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 {
private List<Item> items = new ArrayList<Item>();
/**
* Returns a List of item childs that holds information about roles, affiliation,
* jids and nicks.
*
* @return a List of item childs that holds information about roles, affiliation,
* jids and nicks.
*/
public List<Item> getItems() {
synchronized (items) {
return Collections.unmodifiableList(new ArrayList<Item>(items));
}
}
/**
* 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() {
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"http://jabber.org/protocol/muc#admin\">");
synchronized (items) {
for (int i = 0; i < items.size(); i++) {
Item item = items.get(i);
buf.append(item.toXML());
}
}
// Add packet extensions, if any are defined.
buf.append(getExtensionsXML());
buf.append("</query>");
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 <room@service/nick> 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 <room@service/nick> 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() {
StringBuilder buf = new StringBuilder();
buf.append("<item");
if (getAffiliation() != null) {
buf.append(" affiliation=\"").append(getAffiliation()).append("\"");
}
if (getJid() != null) {
buf.append(" jid=\"").append(getJid()).append("\"");
}
if (getNick() != null) {
buf.append(" nick=\"").append(getNick()).append("\"");
}
if (getRole() != null) {
buf.append(" role=\"").append(getRole()).append("\"");
}
if (getReason() == null && getActor() == null) {
buf.append("/>");
}
else {
buf.append(">");
if (getReason() != null) {
buf.append("<reason>").append(getReason()).append("</reason>");
}
if (getActor() != null) {
buf.append("<actor jid=\"").append(getActor()).append("\"/>");
}
buf.append("</item>");
}
return buf.toString();
}
};
}

View file

@ -0,0 +1,220 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import org.jivesoftware.smack.packet.PacketExtension;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* Represents extended presence information whose sole purpose is to signal the ability of
* the occupant to speak the MUC protocol when joining a room. If the room requires a password
* then the MUCInitialPresence should include one.
* <p>
* The amount of discussion history provided on entering a room (perhaps because the
* user is on a low-bandwidth connection or is using a small-footprint client) could be managed by
* setting a configured History instance to the MUCInitialPresence instance.
*
* @author Gaston Dombiak
* @see MUCInitialPresence#setHistory(MUCInitialPresence.History)
*/
public class MUCInitialPresence implements PacketExtension {
private String password;
private History history;
public String getElementName() {
return "x";
}
public String getNamespace() {
return "http://jabber.org/protocol/muc";
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\">");
if (getPassword() != null) {
buf.append("<password>").append(getPassword()).append("</password>");
}
if (getHistory() != null) {
buf.append(getHistory().toXML());
}
buf.append("</").append(getElementName()).append(">");
return buf.toString();
}
/**
* Returns the history that manages the amount of discussion history provided on
* entering a room.
*
* @return the history that manages the amount of discussion history provided on
* entering a room.
*/
public History getHistory() {
return history;
}
/**
* Returns the password to use when the room requires a password.
*
* @return the password to use when the room requires a password.
*/
public String getPassword() {
return password;
}
/**
* Sets the History that manages the amount of discussion history provided on
* entering a room.
*
* @param history that manages the amount of discussion history provided on
* entering a room.
*/
public void setHistory(History history) {
this.history = history;
}
/**
* Sets the password to use when the room requires a password.
*
* @param password the password to use when the room requires a password.
*/
public void setPassword(String password) {
this.password = password;
}
/**
* The History class controls the number of characters or messages to receive
* when entering a room.
*
* @author Gaston Dombiak
*/
public static class History {
private int maxChars = -1;
private int maxStanzas = -1;
private int seconds = -1;
private Date since;
/**
* Returns the total number of characters to receive in the history.
*
* @return total number of characters to receive in the history.
*/
public int getMaxChars() {
return maxChars;
}
/**
* Returns the total number of messages to receive in the history.
*
* @return the total number of messages to receive in the history.
*/
public int getMaxStanzas() {
return maxStanzas;
}
/**
* Returns the number of seconds to use to filter the messages received during that time.
* In other words, only the messages received in the last "X" seconds will be included in
* the history.
*
* @return the number of seconds to use to filter the messages received during that time.
*/
public int getSeconds() {
return seconds;
}
/**
* Returns the since date to use to filter the messages received during that time.
* In other words, only the messages received since the datetime specified will be
* included in the history.
*
* @return the since date to use to filter the messages received during that time.
*/
public Date getSince() {
return since;
}
/**
* Sets the total number of characters to receive in the history.
*
* @param maxChars the total number of characters to receive in the history.
*/
public void setMaxChars(int maxChars) {
this.maxChars = maxChars;
}
/**
* Sets the total number of messages to receive in the history.
*
* @param maxStanzas the total number of messages to receive in the history.
*/
public void setMaxStanzas(int maxStanzas) {
this.maxStanzas = maxStanzas;
}
/**
* Sets the number of seconds to use to filter the messages received during that time.
* In other words, only the messages received in the last "X" seconds will be included in
* the history.
*
* @param seconds the number of seconds to use to filter the messages received during
* that time.
*/
public void setSeconds(int seconds) {
this.seconds = seconds;
}
/**
* Sets the since date to use to filter the messages received during that time.
* In other words, only the messages received since the datetime specified will be
* included in the history.
*
* @param since the since date to use to filter the messages received during that time.
*/
public void setSince(Date since) {
this.since = since;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<history");
if (getMaxChars() != -1) {
buf.append(" maxchars=\"").append(getMaxChars()).append("\"");
}
if (getMaxStanzas() != -1) {
buf.append(" maxstanzas=\"").append(getMaxStanzas()).append("\"");
}
if (getSeconds() != -1) {
buf.append(" seconds=\"").append(getSeconds()).append("\"");
}
if (getSince() != null) {
SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
buf.append(" since=\"").append(utcFormat.format(getSince())).append("\"");
}
buf.append("/>");
return buf.toString();
}
}
}

View file

@ -0,0 +1,338 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import org.jivesoftware.smack.packet.IQ;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* IQ packet that serves for granting and revoking ownership privileges, granting
* and revoking administrative privileges and destroying a room. All these operations
* are scoped by the 'http://jabber.org/protocol/muc#owner' namespace.
*
* @author Gaston Dombiak
*/
public class MUCOwner extends IQ {
private List<Item> items = new ArrayList<Item>();
private Destroy destroy;
/**
* Returns a List of item childs that holds information about affiliation,
* jids and nicks.
*
* @return a List of item childs that holds information about affiliation,
* jids and nicks.
*/
public List<Item> getItems() {
synchronized (items) {
return Collections.unmodifiableList(new ArrayList<Item>(items));
}
}
/**
* Returns a request to the server to destroy a room. The sender of the request
* should be the room's owner. If the sender of the destroy request is not the room's owner
* then the server will answer a "Forbidden" error.
*
* @return a request to the server to destroy a room.
*/
public Destroy getDestroy() {
return destroy;
}
/**
* Sets a request to the server to destroy a room. The sender of the request
* should be the room's owner. If the sender of the destroy request is not the room's owner
* then the server will answer a "Forbidden" error.
*
* @param destroy the request to the server to destroy a room.
*/
public void setDestroy(Destroy destroy) {
this.destroy = destroy;
}
/**
* Adds an item child that holds information about affiliation, jids and nicks.
*
* @param item the item child that holds information about affiliation, jids and nicks.
*/
public void addItem(Item item) {
synchronized (items) {
items.add(item);
}
}
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"http://jabber.org/protocol/muc#owner\">");
synchronized (items) {
for (int i = 0; i < items.size(); i++) {
Item item = (Item) items.get(i);
buf.append(item.toXML());
}
}
if (getDestroy() != null) {
buf.append(getDestroy().toXML());
}
// Add packet extensions, if any are defined.
buf.append(getExtensionsXML());
buf.append("</query>");
return buf.toString();
}
/**
* Item child that holds information about 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
*/
public Item(String affiliation) {
this.affiliation = affiliation;
}
/**
* 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 <room@service/nick> 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 <room@service/nick> 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;
}
/**
* Sets 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.
*
* @param role the new privilege level of an occupant within a room.
*/
public void setRole(String role) {
this.role = role;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<item");
if (getAffiliation() != null) {
buf.append(" affiliation=\"").append(getAffiliation()).append("\"");
}
if (getJid() != null) {
buf.append(" jid=\"").append(getJid()).append("\"");
}
if (getNick() != null) {
buf.append(" nick=\"").append(getNick()).append("\"");
}
if (getRole() != null) {
buf.append(" role=\"").append(getRole()).append("\"");
}
if (getReason() == null && getActor() == null) {
buf.append("/>");
}
else {
buf.append(">");
if (getReason() != null) {
buf.append("<reason>").append(getReason()).append("</reason>");
}
if (getActor() != null) {
buf.append("<actor jid=\"").append(getActor()).append("\"/>");
}
buf.append("</item>");
}
return buf.toString();
}
};
/**
* Represents a request to the server to destroy a room. The sender of the request
* should be the room's owner. If the sender of the destroy request is not the room's owner
* then the server will answer a "Forbidden" error.
*
* @author Gaston Dombiak
*/
public static class Destroy {
private String reason;
private String jid;
/**
* Returns the JID of an alternate location since the current room is being destroyed.
*
* @return the JID of an alternate location.
*/
public String getJid() {
return jid;
}
/**
* Returns the reason for the room destruction.
*
* @return the reason for the room destruction.
*/
public String getReason() {
return reason;
}
/**
* Sets the JID of an alternate location since the current room is being destroyed.
*
* @param jid the JID of an alternate location.
*/
public void setJid(String jid) {
this.jid = jid;
}
/**
* Sets the reason for the room destruction.
*
* @param reason the reason for the room destruction.
*/
public void setReason(String reason) {
this.reason = reason;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<destroy");
if (getJid() != null) {
buf.append(" jid=\"").append(getJid()).append("\"");
}
if (getReason() == null) {
buf.append("/>");
}
else {
buf.append(">");
if (getReason() != null) {
buf.append("<reason>").append(getReason()).append("</reason>");
}
buf.append("</destroy>");
}
return buf.toString();
}
}
}

View file

@ -0,0 +1,624 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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;
import org.jivesoftware.smack.packet.PacketExtension;
/**
* Represents extended presence information about roles, affiliations, full JIDs,
* or status codes scoped by the 'http://jabber.org/protocol/muc#user' namespace.
*
* @author Gaston Dombiak
*/
public class MUCUser implements PacketExtension {
private Invite invite;
private Decline decline;
private Item item;
private String password;
private Status status;
private Destroy destroy;
public String getElementName() {
return "x";
}
public String getNamespace() {
return "http://jabber.org/protocol/muc#user";
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\">");
if (getInvite() != null) {
buf.append(getInvite().toXML());
}
if (getDecline() != null) {
buf.append(getDecline().toXML());
}
if (getItem() != null) {
buf.append(getItem().toXML());
}
if (getPassword() != null) {
buf.append("<password>").append(getPassword()).append("</password>");
}
if (getStatus() != null) {
buf.append(getStatus().toXML());
}
if (getDestroy() != null) {
buf.append(getDestroy().toXML());
}
buf.append("</").append(getElementName()).append(">");
return buf.toString();
}
/**
* Returns the invitation for another user to a room. The sender of the invitation
* must be an occupant of the room. The invitation will be sent to the room which in turn
* will forward the invitation to the invitee.
*
* @return an invitation for another user to a room.
*/
public Invite getInvite() {
return invite;
}
/**
* Returns the rejection to an invitation from another user to a room. The rejection will be
* sent to the room which in turn will forward the refusal to the inviter.
*
* @return a rejection to an invitation from another user to a room.
*/
public Decline getDecline() {
return decline;
}
/**
* Returns the item child that holds information about roles, affiliation, jids and nicks.
*
* @return an item child that holds information about roles, affiliation, jids and nicks.
*/
public Item getItem() {
return item;
}
/**
* Returns the password to use to enter Password-Protected Room. A Password-Protected Room is
* a room that a user cannot enter without first providing the correct password.
*
* @return the password to use to enter Password-Protected Room.
*/
public String getPassword() {
return password;
}
/**
* Returns the status which holds a code that assists in presenting notification messages.
*
* @return the status which holds a code that assists in presenting notification messages.
*/
public Status getStatus() {
return status;
}
/**
* Returns the notification that the room has been destroyed. After a room has been destroyed,
* the room occupants will receive a Presence packet of type 'unavailable' with the reason for
* the room destruction if provided by the room owner.
*
* @return a notification that the room has been destroyed.
*/
public Destroy getDestroy() {
return destroy;
}
/**
* Sets the invitation for another user to a room. The sender of the invitation
* must be an occupant of the room. The invitation will be sent to the room which in turn
* will forward the invitation to the invitee.
*
* @param invite the invitation for another user to a room.
*/
public void setInvite(Invite invite) {
this.invite = invite;
}
/**
* Sets the rejection to an invitation from another user to a room. The rejection will be
* sent to the room which in turn will forward the refusal to the inviter.
*
* @param decline the rejection to an invitation from another user to a room.
*/
public void setDecline(Decline decline) {
this.decline = decline;
}
/**
* Sets the 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 setItem(Item item) {
this.item = item;
}
/**
* Sets the password to use to enter Password-Protected Room. A Password-Protected Room is
* a room that a user cannot enter without first providing the correct password.
*
* @param string the password to use to enter Password-Protected Room.
*/
public void setPassword(String string) {
password = string;
}
/**
* Sets the status which holds a code that assists in presenting notification messages.
*
* @param status the status which holds a code that assists in presenting notification
* messages.
*/
public void setStatus(Status status) {
this.status = status;
}
/**
* Sets the notification that the room has been destroyed. After a room has been destroyed,
* the room occupants will receive a Presence packet of type 'unavailable' with the reason for
* the room destruction if provided by the room owner.
*
* @param destroy the notification that the room has been destroyed.
*/
public void setDestroy(Destroy destroy) {
this.destroy = destroy;
}
/**
* Represents an invitation for another user to a room. The sender of the invitation
* must be an occupant of the room. The invitation will be sent to the room which in turn
* will forward the invitation to the invitee.
*
* @author Gaston Dombiak
*/
public static class Invite {
private String reason;
private String from;
private String to;
/**
* Returns the bare JID of the inviter or, optionally, the room JID. (e.g.
* 'crone1@shakespeare.lit/desktop').
*
* @return the room's occupant that sent the invitation.
*/
public String getFrom() {
return from;
}
/**
* Returns the message explaining the invitation.
*
* @return the message explaining the invitation.
*/
public String getReason() {
return reason;
}
/**
* Returns the bare JID of the invitee. (e.g. 'hecate@shakespeare.lit')
*
* @return the bare JID of the invitee.
*/
public String getTo() {
return to;
}
/**
* Sets the bare JID of the inviter or, optionally, the room JID. (e.g.
* 'crone1@shakespeare.lit/desktop')
*
* @param from the bare JID of the inviter or, optionally, the room JID.
*/
public void setFrom(String from) {
this.from = from;
}
/**
* Sets the message explaining the invitation.
*
* @param reason the message explaining the invitation.
*/
public void setReason(String reason) {
this.reason = reason;
}
/**
* Sets the bare JID of the invitee. (e.g. 'hecate@shakespeare.lit')
*
* @param to the bare JID of the invitee.
*/
public void setTo(String to) {
this.to = to;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<invite ");
if (getTo() != null) {
buf.append(" to=\"").append(getTo()).append("\"");
}
if (getFrom() != null) {
buf.append(" from=\"").append(getFrom()).append("\"");
}
buf.append(">");
if (getReason() != null) {
buf.append("<reason>").append(getReason()).append("</reason>");
}
buf.append("</invite>");
return buf.toString();
}
}
/**
* Represents a rejection to an invitation from another user to a room. The rejection will be
* sent to the room which in turn will forward the refusal to the inviter.
*
* @author Gaston Dombiak
*/
public static class Decline {
private String reason;
private String from;
private String to;
/**
* Returns the bare JID of the invitee that rejected the invitation. (e.g.
* 'crone1@shakespeare.lit/desktop').
*
* @return the bare JID of the invitee that rejected the invitation.
*/
public String getFrom() {
return from;
}
/**
* Returns the message explaining why the invitation was rejected.
*
* @return the message explaining the reason for the rejection.
*/
public String getReason() {
return reason;
}
/**
* Returns the bare JID of the inviter. (e.g. 'hecate@shakespeare.lit')
*
* @return the bare JID of the inviter.
*/
public String getTo() {
return to;
}
/**
* Sets the bare JID of the invitee that rejected the invitation. (e.g.
* 'crone1@shakespeare.lit/desktop').
*
* @param from the bare JID of the invitee that rejected the invitation.
*/
public void setFrom(String from) {
this.from = from;
}
/**
* Sets the message explaining why the invitation was rejected.
*
* @param reason the message explaining the reason for the rejection.
*/
public void setReason(String reason) {
this.reason = reason;
}
/**
* Sets the bare JID of the inviter. (e.g. 'hecate@shakespeare.lit')
*
* @param to the bare JID of the inviter.
*/
public void setTo(String to) {
this.to = to;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<decline ");
if (getTo() != null) {
buf.append(" to=\"").append(getTo()).append("\"");
}
if (getFrom() != null) {
buf.append(" from=\"").append(getFrom()).append("\"");
}
buf.append(">");
if (getReason() != null) {
buf.append("<reason>").append(getReason()).append("</reason>");
}
buf.append("</decline>");
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 == null ? "" : 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 == null ? "" : 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 <room@service/nick> 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 <room@service/nick> 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() {
StringBuilder buf = new StringBuilder();
buf.append("<item");
if (getAffiliation() != null) {
buf.append(" affiliation=\"").append(getAffiliation()).append("\"");
}
if (getJid() != null) {
buf.append(" jid=\"").append(getJid()).append("\"");
}
if (getNick() != null) {
buf.append(" nick=\"").append(getNick()).append("\"");
}
if (getRole() != null) {
buf.append(" role=\"").append(getRole()).append("\"");
}
if (getReason() == null && getActor() == null) {
buf.append("/>");
}
else {
buf.append(">");
if (getReason() != null) {
buf.append("<reason>").append(getReason()).append("</reason>");
}
if (getActor() != null) {
buf.append("<actor jid=\"").append(getActor()).append("\"/>");
}
buf.append("</item>");
}
return buf.toString();
}
}
/**
* Status code assists in presenting notification messages. The following link provides the
* list of existing error codes (@link http://www.jabber.org/jeps/jep-0045.html#errorstatus).
*
* @author Gaston Dombiak
*/
public static class Status {
private String code;
/**
* Creates a new instance of Status with the specified code.
*
* @param code the code that uniquely identifies the reason of the error.
*/
public Status(String code) {
this.code = code;
}
/**
* Returns the code that uniquely identifies the reason of the error. The code
* assists in presenting notification messages.
*
* @return the code that uniquely identifies the reason of the error.
*/
public String getCode() {
return code;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<status code=\"").append(getCode()).append("\"/>");
return buf.toString();
}
}
/**
* Represents a notification that the room has been destroyed. After a room has been destroyed,
* the room occupants will receive a Presence packet of type 'unavailable' with the reason for
* the room destruction if provided by the room owner.
*
* @author Gaston Dombiak
*/
public static class Destroy {
private String reason;
private String jid;
/**
* Returns the JID of an alternate location since the current room is being destroyed.
*
* @return the JID of an alternate location.
*/
public String getJid() {
return jid;
}
/**
* Returns the reason for the room destruction.
*
* @return the reason for the room destruction.
*/
public String getReason() {
return reason;
}
/**
* Sets the JID of an alternate location since the current room is being destroyed.
*
* @param jid the JID of an alternate location.
*/
public void setJid(String jid) {
this.jid = jid;
}
/**
* Sets the reason for the room destruction.
*
* @param reason the reason for the room destruction.
*/
public void setReason(String reason) {
this.reason = reason;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<destroy");
if (getJid() != null) {
buf.append(" jid=\"").append(getJid()).append("\"");
}
if (getReason() == null) {
buf.append("/>");
}
else {
buf.append(">");
if (getReason() != null) {
buf.append("<reason>").append(getReason()).append("</reason>");
}
buf.append("</destroy>");
}
return buf.toString();
}
}
}

View file

@ -0,0 +1,78 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.muc.packet.MUCAdmin;
import org.xmlpull.v1.XmlPullParser;
/**
* The MUCAdminProvider parses MUCAdmin packets. (@see MUCAdmin)
*
* @author Gaston Dombiak
*/
public class MUCAdminProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception {
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;
}
}

View file

@ -0,0 +1,105 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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.provider;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.provider.*;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muc.packet.MUCOwner;
import org.xmlpull.v1.XmlPullParser;
/**
* The MUCOwnerProvider parses MUCOwner packets. (@see MUCOwner)
*
* @author Gaston Dombiak
*/
public class MUCOwnerProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception {
MUCOwner mucOwner = new MUCOwner();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
mucOwner.addItem(parseItem(parser));
}
else if (parser.getName().equals("destroy")) {
mucOwner.setDestroy(parseDestroy(parser));
}
// Otherwise, it must be a packet extension.
else {
mucOwner.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(),
parser.getNamespace(), parser));
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("query")) {
done = true;
}
}
}
return mucOwner;
}
private MUCOwner.Item parseItem(XmlPullParser parser) throws Exception {
boolean done = false;
MUCOwner.Item item = new MUCOwner.Item(parser.getAttributeValue("", "affiliation"));
item.setNick(parser.getAttributeValue("", "nick"));
item.setRole(parser.getAttributeValue("", "role"));
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;
}
private MUCOwner.Destroy parseDestroy(XmlPullParser parser) throws Exception {
boolean done = false;
MUCOwner.Destroy destroy = new MUCOwner.Destroy();
destroy.setJid(parser.getAttributeValue("", "jid"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("reason")) {
destroy.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("destroy")) {
done = true;
}
}
}
return destroy;
}
}

View file

@ -0,0 +1,172 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.muc.packet.MUCUser;
import org.xmlpull.v1.XmlPullParser;
/**
* The MUCUserProvider parses packets with extended presence information about
* roles and affiliations.
*
* @author Gaston Dombiak
*/
public class MUCUserProvider implements PacketExtensionProvider {
/**
* Creates a new MUCUserProvider.
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument
* constructor
*/
public MUCUserProvider() {
}
/**
* Parses a MUCUser packet (extension sub-packet).
*
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @throws Exception if a parsing error occurs.
*/
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
MUCUser mucUser = new MUCUser();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("invite")) {
mucUser.setInvite(parseInvite(parser));
}
if (parser.getName().equals("item")) {
mucUser.setItem(parseItem(parser));
}
if (parser.getName().equals("password")) {
mucUser.setPassword(parser.nextText());
}
if (parser.getName().equals("status")) {
mucUser.setStatus(new MUCUser.Status(parser.getAttributeValue("", "code")));
}
if (parser.getName().equals("decline")) {
mucUser.setDecline(parseDecline(parser));
}
if (parser.getName().equals("destroy")) {
mucUser.setDestroy(parseDestroy(parser));
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("x")) {
done = true;
}
}
}
return mucUser;
}
private MUCUser.Item parseItem(XmlPullParser parser) throws Exception {
boolean done = false;
MUCUser.Item item =
new MUCUser.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;
}
private MUCUser.Invite parseInvite(XmlPullParser parser) throws Exception {
boolean done = false;
MUCUser.Invite invite = new MUCUser.Invite();
invite.setFrom(parser.getAttributeValue("", "from"));
invite.setTo(parser.getAttributeValue("", "to"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("reason")) {
invite.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("invite")) {
done = true;
}
}
}
return invite;
}
private MUCUser.Decline parseDecline(XmlPullParser parser) throws Exception {
boolean done = false;
MUCUser.Decline decline = new MUCUser.Decline();
decline.setFrom(parser.getAttributeValue("", "from"));
decline.setTo(parser.getAttributeValue("", "to"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("reason")) {
decline.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("decline")) {
done = true;
}
}
}
return decline;
}
private MUCUser.Destroy parseDestroy(XmlPullParser parser) throws Exception {
boolean done = false;
MUCUser.Destroy destroy = new MUCUser.Destroy();
destroy.setJid(parser.getAttributeValue("", "jid"));
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("reason")) {
destroy.setReason(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("destroy")) {
done = true;
}
}
}
return destroy;
}
}