1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Add support Multi-User Chat Light

Fixes SMACK-740
This commit is contained in:
Fernando Ramirez 2016-11-02 12:10:56 -03:00 committed by Florian Schmaus
parent eb9242768c
commit 5372c1bcf4
39 changed files with 4053 additions and 0 deletions

View file

@ -87,6 +87,7 @@ Experimental Smack Extensions and currently supported XEPs of smack-experimental
| [Internet of Things - Discovery](iot.md) | [XEP-0347](http://xmpp.org/extensions/xep-0347.html) | Describes how Things can be installed and discovered by their owners. |
| Client State Indication | [XEP-0352](http://xmpp.org/extensions/xep-0352.html) | A way for the client to indicate its active/inactive state. |
| [Push Notifications](pushnotifications.md) | [XEP-0357](http://xmpp.org/extensions/xep-0357.html) | Defines a way to manage push notifications from an XMPP Server. |
| [Multi-User Chat Light](muclight.md) | [XEP-xxxx](http://mongooseim.readthedocs.io/en/latest/open-extensions/xeps/xep-muc-light.html) | Multi-User Chats for mobile XMPP applications and specific enviroment. |
| Google GCM JSON payload | n/a | Semantically the same as XEP-0335: JSON Containers |

View file

@ -0,0 +1,356 @@
Multi-User Chat Light
=====================
Allows configuration of, participation in, and administration of presence­less Multi­-User Chats.
Its feature set is a response to mobile XMPP applications needs and specific environment.
* Obtain the MUC Light Manager
* Obtain a MUC Light
* Create a new Room
* Destroy a room
* Leave a room
* Change room name
* Change room subject
* Set room configurations
* Manage changes on room name, subject and other configurations
* Get room information
* Manage room occupants
* Manage occupants modifications
* Discover MUC Light support
* Get occupied rooms
* Start a private chat
* Send message to a room
* Manage blocking list
**XEP related:** [XEP-xxxx](http://mongooseim.readthedocs.io/en/latest/open-extensions/xeps/xep-muc-light.html)
Obtain the MUC Light Manager
----------------------------
```
MultiUserChatLightManager multiUserChatLightManager = MultiUserChatLightManager.getInstanceFor(connection);
```
Obtain a MUC Light
------------------
```
MultiUserChatLight multiUserChatLight = multiUserChatLightManager.getMultiUserChatLight(roomJid);
```
`roomJid` is a EntityBareJid
Create a new room
-----------------
```
multiUserChatLight.create(roomName, occupants);
```
or
```
multiUserChatLight.create(roomName, subject, customConfigs, occupants);
```
*roomName* is a `String`
*subject* is a `String`
*customConfigs* is a `HashMap<String, String>`
*occupants* is a `List<Jid>`
Destroy a room
---------------
```
multiUserChatLight.destroy();
```
Leave a room
-------------
```
multiUserChatLight.leave();
```
Change room name
----------------
```
multiUserChatLight.changeRoomName(roomName);
```
*roomName* is a `String`
Change subject
--------------
```
multiUserChatLight.changeSubject(subject);
```
*subject* is a `String`
Set room configurations
-----------------------
```
multiUserChatLight.setRoomConfigs(customConfigs);
```
or
```
multiUserChatLight.setRoomConfigs(roomName, customConfigs);
```
*customConfigs* is a `HashMap<String, String>` (which means [property name, value])
*roomName* is a `String`
Manage changes on room name, subject and other configurations
-------------------------------------------------------------
```
// check if the message is because of a configurations change
if (message.hasExtension(MUCLightElements.ConfigurationsChangeExtension.ELEMENT, MUCLightElements.ConfigurationsChangeExtension.NAMESPACE)) {
// Get the configurations extension
MUCLightElements.ConfigurationsChangeExtension configurationsChangeExtension = MUCLightElements.ConfigurationsChangeExtension.from(message);
// Get new room name
String roomName = configurationsChangeExtension.getRoomName();
// Get new subject
String subject = configurationsChangeExtension.getSubject();
// Get new custom configurations
HashMap<String, String> customConfigs = configurationsChangeExtension.getCustomConfigs();
}
```
Get room information
--------------------
**Get configurations**
```
MUCLightRoomConfiguration configuration = multiUserChatLight.getConfiguration(version);
```
*version* is a `String`
or
```
MUCLightRoomConfiguration configuration = multiUserChatLight.getConfiguration();
```
```
// Get room name
String roomName = configuration.getRoomName();
// Get subject
String subject = configuration.getSubject();
// Get custom configurations
HashMap<String, String> customConfigs = configuration.getCustomConfigs();
```
**Get affiliations**
```
HashMap<Jid, MUCLightAffiliation> affiliations = multiUserChatLight.getAffiliations(version);
```
*version* is a `String`
or
```
HashMap<Jid, MUCLightAffiliation> affiliations = multiUserChatLight.getAffiliations();
```
**Get full information**
```
MUCLightRoomInfo info = multiUserChatLight.getFullInfo(version);
```
*version* is a `String`
or
```
MUCLightRoomInfo info = multiUserChatLight.getFullInfo();
```
```
// Get version
String version = info.getVersion();
// Get room
Jid room = info.getRoom();
// Get configurations
MUCLightRoomConfiguration configuration = info.getConfiguration();
// Get occupants
HashMap<Jid, MUCLightAffiliation> occupants = info.getOccupants();
```
Manage room occupants
---------------------
To change room occupants:
```
multiUserChatLight.changeAffiliations(affiliations);
```
*affiliations* is a `HashMap<Jid, MUCLightAffiliation>`
Manage occupants modifications
------------------------------
```
// check if the message is because of an affiliations change
if (message.hasExtension(MUCLightElements.AffiliationsChangeExtension.ELEMENT, MUCLightElements.AffiliationsChangeExtension.NAMESPACE)) {
// Get the affiliations change extension
MUCLightElements.AffiliationsChangeExtension affiliationsChangeExtension = MUCLightElements.AffiliationsChangeExtension.from(message);
// Get the new affiliations
HashMap<EntityJid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
}
```
Discover MUC Light support
--------------------------
**Check if MUC Light feature is supported by the server**
```
boolean isSupported = multiUserChatLightManager.isFeatureSupported(mucLightService);
```
*mucLightService* is a `DomainBareJid`
**Get MUC Light services domains**
```
List<DomainBareJid> domains = multiUserChatLightManager.getLocalServices();
```
Get occupied rooms
------------------
```
List<Jid> occupiedRooms = multiUserChatLightManager.getOccupiedRooms(mucLightService);
```
*mucLightService* is a `DomainBareJid`
Start a private chat
--------------------
```
Chat chat = multiUserChatLight.createPrivateChat(occupant, listener);
```
*occupant* is a `EntityJid`
*listener* is a `ChatMessageListener`
Send message to a room
----------------------
**Create message for an specific MUC Light**
```
Message message = multiUserChatLight.createMessage();
```
**Send a message to an specific MUC Light**
```
multiUserChatLight.sendMessage(message);
```
*message* is a `Message`
Manage blocking list
--------------------
**Get blocked list**
```
// Get users and rooms blocked
List<Jid> jids = multiUserChatLightManager.getUsersAndRoomsBlocked(mucLightService);
// Get rooms blocked
List<Jid> jids = multiUserChatLightManager.getRoomsBlocked(mucLightService);
// Get users blocked
List<Jid> jids = multiUserChatLightManager.getUsersBlocked(mucLightService);
```
*mucLightService* is a `DomainBareJid`
**Block rooms**
```
// Block one room
multiUserChatLightManager.blockRoom(mucLightService, roomJid);
// Block several rooms
multiUserChatLightManager.blockRooms(mucLightService, roomsJids);
```
*mucLightService* is a `DomainBareJid`
*roomJid* is a `Jid`
*roomsJids* is a `List<Jid>`
**Block users**
```
// Block one user
multiUserChatLightManager.blockUser(mucLightService, userJid);
// Block several users
multiUserChatLightManager.blockUsers(mucLightService, usersJids);
```
*mucLightService* is a `DomainBareJid`
*userJid* is a `Jid`
*usersJids* is a `List<Jid>`
**Unblock rooms**
```
// Unblock one room
multiUserChatLightManager.unblockRoom(mucLightService, roomJid);
// Unblock several rooms
multiUserChatLightManager.unblockRooms(mucLightService, roomsJids);
```
*mucLightService* is a `DomainBareJid`
*roomJid* is a `Jid`
*roomsJids* is a `List<Jid>`
**Unblock users**
```
// Unblock one user
multiUserChatLightManager.unblockUser(mucLightService, userJid);
// Unblock several users
multiUserChatLightManager.unblockUsers(mucLightService, usersJids);
```
*mucLightService* is a `DomainBareJid`
*userJid* is a `Jid`
*usersJids* is a `List<Jid>`

View file

@ -0,0 +1,40 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.Locale;
/**
* MUCLight affiliations enum.
*
* @author Fernando Ramirez
*
*/
public enum MUCLightAffiliation {
owner,
member,
none;
public static MUCLightAffiliation fromString(String string) {
if (string == null) {
return null;
}
return MUCLightAffiliation.valueOf(string.toLowerCase(Locale.US));
}
}

View file

@ -0,0 +1,73 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
/**
* MUC Light room configuration class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightRoomConfiguration {
private final String roomName;
private final String subject;
private final HashMap<String, String> customConfigs;
/**
* MUC Light room configuration model constructor.
*
* @param roomName
* @param subject
* @param customConfigs
*/
public MUCLightRoomConfiguration(String roomName, String subject, HashMap<String, String> customConfigs) {
this.roomName = roomName;
this.subject = subject;
this.customConfigs = customConfigs;
}
/**
* Returns the room name.
*
* @return the name of the room.
*/
public String getRoomName() {
return roomName;
}
/**
* Returns the room subject.
*
* @return the subject of the room.
*/
public String getSubject() {
return subject;
}
/**
* Returns the room custom configurations.
*
* @return the custom configurations of the room.
*/
public HashMap<String, String> getCustomConfigs() {
return customConfigs;
}
}

View file

@ -0,0 +1,86 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jxmpp.jid.Jid;
/**
* MUC Light room info class.
*
* @author Fernando Ramirez
*/
public class MUCLightRoomInfo {
private final String version;
private final Jid room;
private final MUCLightRoomConfiguration configuration;
private final HashMap<Jid, MUCLightAffiliation> occupants;
/**
* MUC Light room info model constructor.
*
* @param version
* @param roomJid
* @param configuration
* @param occupants
*/
public MUCLightRoomInfo(String version, Jid roomJid, MUCLightRoomConfiguration configuration,
HashMap<Jid, MUCLightAffiliation> occupants) {
this.version = version;
this.room = roomJid;
this.configuration = configuration;
this.occupants = occupants;
}
/**
* Returns the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
/**
* Returns the JID of the room whose information was discovered.
*
* @return the JID of the room whose information was discovered.
*/
public Jid getRoom() {
return room;
}
/**
* Returns the configuration.
*
* @return the room configuration
*/
public MUCLightRoomConfiguration getConfiguration() {
return configuration;
}
/**
* Returns the room occupants.
*
* @return the occupants of the room.
*/
public HashMap<Jid, MUCLightAffiliation> getOccupants() {
return occupants;
}
}

View file

@ -0,0 +1,502 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.chat.ChatManager;
import org.jivesoftware.smack.chat.ChatMessageListener;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.muclight.element.MUCLightAffiliationsIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightChangeAffiliationsIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightConfigurationIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightCreateIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightDestroyIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightGetAffiliationsIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightGetConfigsIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightGetInfoIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightInfoIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightSetConfigsIQ;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.Jid;
/**
* MUCLight class.
*
* @author Fernando Ramirez
*/
public class MultiUserChatLight {
public static final String NAMESPACE = "urn:xmpp:muclight:0";
public static final String AFFILIATIONS = "#affiliations";
public static final String INFO = "#info";
public static final String CONFIGURATION = "#configuration";
public static final String CREATE = "#create";
public static final String DESTROY = "#destroy";
public static final String BLOCKING = "#blocking";
private final XMPPConnection connection;
private final EntityJid room;
private final Set<MessageListener> messageListeners = new CopyOnWriteArraySet<MessageListener>();
/**
* This filter will match all stanzas send from the groupchat or from one if
* the groupchat occupants.
*/
private final StanzaFilter fromRoomFilter;
/**
* Same as {@link #fromRoomFilter} together with
* {@link MessageTypeFilter#GROUPCHAT}.
*/
private final StanzaFilter fromRoomGroupchatFilter;
private final StanzaListener messageListener;
private PacketCollector messageCollector;
MultiUserChatLight(XMPPConnection connection, EntityJid room) {
this.connection = connection;
this.room = room;
fromRoomFilter = FromMatchesFilter.create(room);
fromRoomGroupchatFilter = new AndFilter(fromRoomFilter, MessageTypeFilter.GROUPCHAT);
messageListener = new StanzaListener() {
@Override
public void processPacket(Stanza packet) throws NotConnectedException {
Message message = (Message) packet;
for (MessageListener listener : messageListeners) {
listener.processMessage(message);
}
}
};
connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
}
/**
* Returns the JID of the room.
*
* @return the MUCLight room JID.
*/
public EntityJid getRoom() {
return room;
}
/**
* Sends a message to the chat room.
*
* @param text
* the text of the message to send.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendMessage(String text) throws NotConnectedException, InterruptedException {
Message message = createMessage();
message.setBody(text);
connection.sendStanza(message);
}
/**
* Returns a new Chat for sending private messages to a given room occupant.
* The Chat's occupant address is the room's JID (i.e.
* roomName@service/nick). The server service will change the 'from' address
* to the sender's room JID and delivering the message to the intended
* recipient's full JID.
*
* @param occupant
* occupant unique room JID (e.g.
* 'darkcave@macbeth.shakespeare.lit/Paul').
* @param listener
* the listener is a message listener that will handle messages
* for the newly created chat.
* @return new Chat for sending private messages to a given room occupant.
*/
public Chat createPrivateChat(EntityJid occupant, ChatMessageListener listener) {
return ChatManager.getInstanceFor(connection).createChat(occupant, listener);
}
/**
* Creates a new Message to send to the chat room.
*
* @return a new Message addressed to the chat room.
*/
public Message createMessage() {
return new Message(room, Message.Type.groupchat);
}
/**
* Sends a Message to the chat room.
*
* @param message
* the message.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendMessage(Message message) throws NotConnectedException, InterruptedException {
message.setTo(room);
message.setType(Message.Type.groupchat);
connection.sendStanza(message);
}
/**
* Polls for and returns the next message.
*
* @return the next message if one is immediately available
*/
public Message pollMessage() {
return messageCollector.pollResult();
}
/**
* Returns the next available message in the chat. The method call will
* block (not return) until a message is available.
*
* @return the next message.
* @throws InterruptedException
*/
public Message nextMessage() throws InterruptedException {
return messageCollector.nextResult();
}
/**
* Returns the next available message in the chat.
*
* @param timeout
* the maximum amount of time to wait for the next message.
* @return the next message, or null if the timeout elapses without a
* message becoming available.
* @throws InterruptedException
*/
public Message nextMessage(long timeout) throws InterruptedException {
return messageCollector.nextResult(timeout);
}
/**
* Adds a stanza(/packet) listener that will be notified of any new messages
* in the group chat. Only "group chat" messages addressed to this group
* chat will be delivered to the listener.
*
* @param listener
* a stanza(/packet) listener.
* @return true if the listener was not already added.
*/
public boolean addMessageListener(MessageListener listener) {
return messageListeners.add(listener);
}
/**
* Removes a stanza(/packet) listener that was being notified of any new
* messages in the MUCLight. Only "group chat" messages addressed to this
* MUCLight were being delivered to the listener.
*
* @param listener
* a stanza(/packet) listener.
* @return true if the listener was removed, otherwise the listener was not
* added previously.
*/
public boolean removeMessageListener(MessageListener listener) {
return messageListeners.remove(listener);
}
/**
* Remove the connection callbacks used by this MUC Light from the
* connection.
*/
private void removeConnectionCallbacks() {
connection.removeSyncStanzaListener(messageListener);
if (messageCollector != null) {
messageCollector.cancel();
messageCollector = null;
}
}
@Override
public String toString() {
return "MUC Light: " + room + "(" + connection.getUser() + ")";
}
/**
* Create new MUCLight.
*
* @param roomName
* @param subject
* @param customConfigs
* @param occupants
* @throws Exception
*/
public void create(String roomName, String subject, HashMap<String, String> customConfigs, List<Jid> occupants)
throws Exception {
MUCLightCreateIQ createMUCLightIQ = new MUCLightCreateIQ(room, roomName, occupants);
messageCollector = connection.createPacketCollector(fromRoomGroupchatFilter);
try {
connection.createPacketCollectorAndSend(createMUCLightIQ).nextResultOrThrow();
} catch (InterruptedException | NoResponseException | XMPPErrorException e) {
removeConnectionCallbacks();
throw e;
}
}
/**
* Create new MUCLight.
*
* @param roomName
* @param occupants
* @throws Exception
*/
public void create(String roomName, List<Jid> occupants) throws Exception {
create(roomName, null, null, occupants);
}
/**
* Leave the MUCLight.
*
* @throws NotConnectedException
* @throws InterruptedException
* @throws NoResponseException
* @throws XMPPErrorException
*/
public void leave() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>();
affiliations.put(connection.getUser(), MUCLightAffiliation.none);
MUCLightChangeAffiliationsIQ changeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(room, affiliations);
IQ responseIq = connection.createPacketCollectorAndSend(changeAffiliationsIQ).nextResultOrThrow();
boolean roomLeft = responseIq.getType().equals(IQ.Type.result);
if (roomLeft) {
removeConnectionCallbacks();
}
}
/**
* Get the MUC Light info.
*
* @param version
* @return the room info
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public MUCLightRoomInfo getFullInfo(String version)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightGetInfoIQ mucLightGetInfoIQ = new MUCLightGetInfoIQ(room, version);
IQ responseIq = connection.createPacketCollectorAndSend(mucLightGetInfoIQ).nextResultOrThrow();
MUCLightInfoIQ mucLightInfoResponseIQ = (MUCLightInfoIQ) responseIq;
return new MUCLightRoomInfo(mucLightInfoResponseIQ.getVersion(), room,
mucLightInfoResponseIQ.getConfiguration(), mucLightInfoResponseIQ.getOccupants());
}
/**
* Get the MUC Light info.
*
* @return the room info
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public MUCLightRoomInfo getFullInfo()
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return getFullInfo(null);
}
/**
* Get the MUC Light configuration.
*
* @param version
* @return the room configuration
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public MUCLightRoomConfiguration getConfiguration(String version)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightGetConfigsIQ mucLightGetConfigsIQ = new MUCLightGetConfigsIQ(room, version);
IQ responseIq = connection.createPacketCollectorAndSend(mucLightGetConfigsIQ).nextResultOrThrow();
MUCLightConfigurationIQ mucLightConfigurationIQ = (MUCLightConfigurationIQ) responseIq;
return mucLightConfigurationIQ.getConfiguration();
}
/**
* Get the MUC Light configuration.
*
* @return the room configuration
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public MUCLightRoomConfiguration getConfiguration()
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return getConfiguration(null);
}
/**
* Get the MUC Light affiliations.
*
* @param version
* @return the room affiliations
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public HashMap<Jid, MUCLightAffiliation> getAffiliations(String version)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightGetAffiliationsIQ mucLightGetAffiliationsIQ = new MUCLightGetAffiliationsIQ(room, version);
IQ responseIq = connection.createPacketCollectorAndSend(mucLightGetAffiliationsIQ).nextResultOrThrow();
MUCLightAffiliationsIQ mucLightAffiliationsIQ = (MUCLightAffiliationsIQ) responseIq;
return mucLightAffiliationsIQ.getAffiliations();
}
/**
* Get the MUC Light affiliations.
*
* @return the room affiliations
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public HashMap<Jid, MUCLightAffiliation> getAffiliations()
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return getAffiliations(null);
}
/**
* Change the MUC Light affiliations.
*
* @param affiliations
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void changeAffiliations(HashMap<Jid, MUCLightAffiliation> affiliations)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightChangeAffiliationsIQ changeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(room, affiliations);
connection.createPacketCollectorAndSend(changeAffiliationsIQ).nextResultOrThrow();
}
/**
* Destroy the MUC Light. Only will work if it is requested by the owner.
*
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void destroy() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightDestroyIQ mucLightDestroyIQ = new MUCLightDestroyIQ(room);
IQ responseIq = connection.createPacketCollectorAndSend(mucLightDestroyIQ).nextResultOrThrow();
boolean roomDestroyed = responseIq.getType().equals(IQ.Type.result);
if (roomDestroyed) {
removeConnectionCallbacks();
}
}
/**
* Change the subject of the MUC Light.
*
* @param subject
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void changeSubject(String subject)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, null, subject, null);
connection.createPacketCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow();
}
/**
* Change the name of the room.
*
* @param roomName
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void changeRoomName(String roomName)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, roomName, null);
connection.createPacketCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow();
}
/**
* Set the room configurations.
*
* @param customConfigs
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void setRoomConfigs(HashMap<String, String> customConfigs)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
setRoomConfigs(null, customConfigs);
}
/**
* Set the room configurations.
*
* @param roomName
* @param customConfigs
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void setRoomConfigs(String roomName, HashMap<String, String> customConfigs)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, roomName, customConfigs);
connection.createPacketCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow();
}
}

View file

@ -0,0 +1,416 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.Jid;
/**
* Multi-User Chat Light manager class.
*
* @author Fernando Ramirez
*
*/
public final class MultiUserChatLightManager extends Manager {
private static final Map<XMPPConnection, MultiUserChatLightManager> INSTANCES = new WeakHashMap<XMPPConnection, MultiUserChatLightManager>();
/**
* Get a instance of a MUC Light manager for the given connection.
*
* @param connection
* @return a MUCLight manager.
*/
public static synchronized MultiUserChatLightManager getInstanceFor(XMPPConnection connection) {
MultiUserChatLightManager multiUserChatLightManager = INSTANCES.get(connection);
if (multiUserChatLightManager == null) {
multiUserChatLightManager = new MultiUserChatLightManager(connection);
INSTANCES.put(connection, multiUserChatLightManager);
}
return multiUserChatLightManager;
}
/**
* A Map of MUC Light JIDs to instances. We use weak references for the
* values in order to allow those instances to get garbage collected.
*/
private final Map<EntityBareJid, WeakReference<MultiUserChatLight>> multiUserChatLights = new HashMap<>();
private MultiUserChatLightManager(XMPPConnection connection) {
super(connection);
}
/**
* Obtain the MUC Light.
*
* @param jid
* @return the MUCLight.
*/
public synchronized MultiUserChatLight getMultiUserChatLight(EntityBareJid jid) {
WeakReference<MultiUserChatLight> weakRefMultiUserChat = multiUserChatLights.get(jid);
if (weakRefMultiUserChat == null) {
return createNewMucLightAndAddToMap(jid);
}
MultiUserChatLight multiUserChatLight = weakRefMultiUserChat.get();
if (multiUserChatLight == null) {
return createNewMucLightAndAddToMap(jid);
}
return multiUserChatLight;
}
private MultiUserChatLight createNewMucLightAndAddToMap(EntityBareJid jid) {
MultiUserChatLight multiUserChatLight = new MultiUserChatLight(connection(), jid);
multiUserChatLights.put(jid, new WeakReference<MultiUserChatLight>(multiUserChatLight));
return multiUserChatLight;
}
/**
* Returns true if Multi-User Chat Light feature is supported by the server.
*
* @param mucLightService
* @return true if Multi-User Chat Light feature is supported by the server.
* @throws NotConnectedException
* @throws XMPPErrorException
* @throws NoResponseException
* @throws InterruptedException
*/
public boolean isFeatureSupported(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).discoverInfo(mucLightService)
.containsFeature(MultiUserChatLight.NAMESPACE);
}
/**
* Returns a List of the rooms the user occupies.
*
* @param mucLightService
* @return a List of the rooms the user occupies.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Jid> getOccupiedRooms(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(mucLightService);
List<DiscoverItems.Item> items = result.getItems();
List<Jid> answer = new ArrayList<>(items.size());
for (DiscoverItems.Item item : items) {
Jid mucLight = item.getEntityID();
answer.add(mucLight);
}
return answer;
}
/**
* Returns a collection with the XMPP addresses of the MUC Light services.
*
* @return a collection with the XMPP addresses of the MUC Light services.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<DomainBareJid> getLocalServices()
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection());
return sdm.findServices(MultiUserChatLight.NAMESPACE, false, false);
}
/**
* Get users and rooms blocked.
*
* @param mucLightService
* @return the list of users and rooms blocked
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Jid> getUsersAndRoomsBlocked(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightBlockingIQ muclIghtBlockingIQResult = getBlockingList(mucLightService);
List<Jid> jids = new ArrayList<>();
if (muclIghtBlockingIQResult.getRooms() != null) {
jids.addAll(muclIghtBlockingIQResult.getRooms().keySet());
}
if (muclIghtBlockingIQResult.getUsers() != null) {
jids.addAll(muclIghtBlockingIQResult.getUsers().keySet());
}
return jids;
}
/**
* Get rooms blocked.
*
* @param mucLightService
* @return the list of rooms blocked
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Jid> getRoomsBlocked(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightBlockingIQ muclIghtBlockingIQResult = getBlockingList(mucLightService);
List<Jid> jids = new ArrayList<>();
if (muclIghtBlockingIQResult.getRooms() != null) {
jids.addAll(muclIghtBlockingIQResult.getRooms().keySet());
}
return jids;
}
/**
* Get users blocked.
*
* @param mucLightService
* @return the list of users blocked
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Jid> getUsersBlocked(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightBlockingIQ muclIghtBlockingIQResult = getBlockingList(mucLightService);
List<Jid> jids = new ArrayList<>();
if (muclIghtBlockingIQResult.getUsers() != null) {
jids.addAll(muclIghtBlockingIQResult.getUsers().keySet());
}
return jids;
}
private MUCLightBlockingIQ getBlockingList(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, null);
mucLightBlockingIQ.setType(Type.get);
mucLightBlockingIQ.setTo(mucLightService);
StanzaFilter responseFilter = new IQReplyFilter(mucLightBlockingIQ, connection());
IQ responseIq = connection().createPacketCollectorAndSend(responseFilter, mucLightBlockingIQ)
.nextResultOrThrow();
MUCLightBlockingIQ muclIghtBlockingIQResult = (MUCLightBlockingIQ) responseIq;
return muclIghtBlockingIQResult;
}
/**
* Block a room.
*
* @param mucLightService
* @param roomJid
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void blockRoom(DomainBareJid mucLightService, Jid roomJid)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> rooms = new HashMap<>();
rooms.put(roomJid, false);
sendBlockRooms(mucLightService, rooms);
}
/**
* Block rooms.
*
* @param mucLightService
* @param roomsJids
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void blockRooms(DomainBareJid mucLightService, List<Jid> roomsJids)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> rooms = new HashMap<>();
for (Jid jid : roomsJids) {
rooms.put(jid, false);
}
sendBlockRooms(mucLightService, rooms);
}
private void sendBlockRooms(DomainBareJid mucLightService, HashMap<Jid, Boolean> rooms)
throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createPacketCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
}
/**
* Block a user.
*
* @param mucLightService
* @param userJid
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void blockUser(DomainBareJid mucLightService, Jid userJid)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> users = new HashMap<>();
users.put(userJid, false);
sendBlockUsers(mucLightService, users);
}
/**
* Block users.
*
* @param mucLightService
* @param usersJids
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void blockUsers(DomainBareJid mucLightService, List<Jid> usersJids)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> users = new HashMap<>();
for (Jid jid : usersJids) {
users.put(jid, false);
}
sendBlockUsers(mucLightService, users);
}
private void sendBlockUsers(DomainBareJid mucLightService, HashMap<Jid, Boolean> users)
throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createPacketCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
}
/**
* Unblock a room.
*
* @param mucLightService
* @param roomJid
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unblockRoom(DomainBareJid mucLightService, Jid roomJid)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> rooms = new HashMap<>();
rooms.put(roomJid, true);
sendUnblockRooms(mucLightService, rooms);
}
/**
* Unblock rooms.
*
* @param mucLightService
* @param roomsJids
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unblockRooms(DomainBareJid mucLightService, List<Jid> roomsJids)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> rooms = new HashMap<>();
for (Jid jid : roomsJids) {
rooms.put(jid, true);
}
sendUnblockRooms(mucLightService, rooms);
}
private void sendUnblockRooms(DomainBareJid mucLightService, HashMap<Jid, Boolean> rooms)
throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createPacketCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
}
/**
* Unblock a user.
*
* @param mucLightService
* @param userJid
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unblockUser(DomainBareJid mucLightService, Jid userJid)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> users = new HashMap<>();
users.put(userJid, true);
sendUnblockUsers(mucLightService, users);
}
/**
* Unblock users.
*
* @param mucLightService
* @param usersJids
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unblockUsers(DomainBareJid mucLightService, List<Jid> usersJids)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> users = new HashMap<>();
for (Jid jid : usersJids) {
users.put(jid, true);
}
sendUnblockUsers(mucLightService, users);
}
private void sendUnblockUsers(DomainBareJid mucLightService, HashMap<Jid, Boolean> users)
throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createPacketCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
}
}

View file

@ -0,0 +1,87 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.UserWithAffiliationElement;
import org.jxmpp.jid.Jid;
/**
* MUC Light affiliations response IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightAffiliationsIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;
private final String version;
private HashMap<Jid, MUCLightAffiliation> affiliations;
/**
* MUC Light affiliations response IQ constructor.
*
* @param version
* @param affiliations
*/
public MUCLightAffiliationsIQ(String version, HashMap<Jid, MUCLightAffiliation> affiliations) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.affiliations = affiliations;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = affiliations.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
xml.element(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
}
return xml;
}
/**
* Returns the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
/**
* Returns the room affiliations.
*
* @return the affiliations of the room
*/
public HashMap<Jid, MUCLightAffiliation> getAffiliations() {
return affiliations;
}
}

View file

@ -0,0 +1,95 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.BlockingElement;
import org.jxmpp.jid.Jid;
/**
* MUC Light blocking IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightBlockingIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.BLOCKING;
private final HashMap<Jid, Boolean> rooms;
private final HashMap<Jid, Boolean> users;
/**
* MUC Light blocking IQ constructor.
*
* @param rooms
* @param users
*/
public MUCLightBlockingIQ(HashMap<Jid, Boolean> rooms, HashMap<Jid, Boolean> users) {
super(ELEMENT, NAMESPACE);
this.rooms = rooms;
this.users = users;
}
/**
* Get rooms JIDs with booleans (true if allow, false if deny).
*
* @return the rooms JIDs with booleans (true if allow, false if deny)
*/
public HashMap<Jid, Boolean> getRooms() {
return rooms;
}
/**
* Get users JIDs with booleans (true if allow, false if deny).
*
* @return the users JIDs with booleans (true if allow, false if deny)
*/
public HashMap<Jid, Boolean> getUsers() {
return users;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
if (rooms != null) {
parseBlocking(xml, rooms, true);
}
if (users != null) {
parseBlocking(xml, users, false);
}
return xml;
}
private void parseBlocking(IQChildElementXmlStringBuilder xml, HashMap<Jid, Boolean> map, boolean isRoom) {
Iterator<Map.Entry<Jid, Boolean>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Jid, Boolean> pair = it.next();
xml.element(new BlockingElement(pair.getKey(), pair.getValue(), isRoom));
}
}
}

View file

@ -0,0 +1,79 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.UserWithAffiliationElement;
import org.jxmpp.jid.Jid;
/**
* MUCLight change affiliations IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightChangeAffiliationsIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;
private HashMap<Jid, MUCLightAffiliation> affiliations;
/**
* MUCLight change affiliations IQ constructor.
*
* @param room
* @param affiliations
*/
public MUCLightChangeAffiliationsIQ(Jid room, HashMap<Jid, MUCLightAffiliation> affiliations) {
super(ELEMENT, NAMESPACE);
this.setType(Type.set);
this.setTo(room);
this.affiliations = affiliations;
}
/**
* Get the affiliations.
*
* @return the affiliations
*/
public HashMap<Jid, MUCLightAffiliation> getAffiliations() {
return affiliations;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
if (affiliations != null) {
Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = affiliations.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
xml.element(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
}
}
return xml;
}
}

View file

@ -0,0 +1,76 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationElement;
/**
* MUC Light configuration response IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightConfigurationIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;
private final String version;
private final MUCLightRoomConfiguration configuration;
/**
* MUC Light configuration response IQ constructor.
*
* @param version
* @param configuration
*/
public MUCLightConfigurationIQ(String version, MUCLightRoomConfiguration configuration) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.configuration = configuration;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
xml.element(new ConfigurationElement(configuration));
return xml;
}
/**
* Returns the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
/**
* Returns the room configuration.
*
* @return the configuration of the room
*/
public MUCLightRoomConfiguration getConfiguration() {
return configuration;
}
}

View file

@ -0,0 +1,109 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import java.util.HashMap;
import java.util.List;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationElement;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.OccupantsElement;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.Jid;
/**
* MUCLight create IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightCreateIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CREATE;
private MUCLightRoomConfiguration configuration;
private final HashMap<Jid, MUCLightAffiliation> occupants;
/**
* MUCLight create IQ constructor.
*
* @param room
* @param roomName
* @param subject
* @param customConfigs
* @param occupants
*/
public MUCLightCreateIQ(EntityJid room, String roomName, String subject, HashMap<String, String> customConfigs,
List<Jid> occupants) {
super(ELEMENT, NAMESPACE);
this.configuration = new MUCLightRoomConfiguration(roomName, subject, customConfigs);
this.occupants = new HashMap<>();
for (Jid occupant : occupants) {
this.occupants.put(occupant, MUCLightAffiliation.member);
}
this.setType(Type.set);
this.setTo(room);
}
/**
* MUCLight create IQ constructor.
*
* @param room
* @param roomName
* @param occupants
*/
public MUCLightCreateIQ(EntityJid room, String roomName, List<Jid> occupants) {
this(room, roomName, null, null, occupants);
}
/**
* Get the room configuration.
*
* @return the room configuration
*/
public MUCLightRoomConfiguration getConfiguration() {
return configuration;
}
/**
* Get the room occupants.
*
* @return the room occupants
*/
public HashMap<Jid, MUCLightAffiliation> getOccupants() {
return occupants;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.element(new ConfigurationElement(configuration));
if (!occupants.isEmpty()) {
xml.element(new OccupantsElement(occupants));
}
return xml;
}
}

View file

@ -0,0 +1,51 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jxmpp.jid.Jid;
/**
* MUC Light destroy IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightDestroyIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.DESTROY;
/**
* MUC Light destroy IQ constructor.
*
* @param roomJid
*/
public MUCLightDestroyIQ(Jid roomJid) {
super(ELEMENT, NAMESPACE);
this.setType(Type.set);
this.setTo(roomJid);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.setEmptyElement();
return xml;
}
}

View file

@ -0,0 +1,392 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jxmpp.jid.Jid;
public abstract class MUCLightElements {
/**
* Affiliations change extension element class.
*
* @author Fernando Ramirez
*
*/
public static class AffiliationsChangeExtension implements ExtensionElement {
public static final String ELEMENT = DataForm.ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;
private final HashMap<Jid, MUCLightAffiliation> affiliations;
private final String prevVersion;
private final String version;
public AffiliationsChangeExtension(HashMap<Jid, MUCLightAffiliation> affiliations, String prevVersion,
String version) {
this.affiliations = affiliations;
this.prevVersion = prevVersion;
this.version = version;
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
/**
* Get the affiliations.
*
* @return the affiliations
*/
public HashMap<Jid, MUCLightAffiliation> getAffiliations() {
return affiliations;
}
/**
* Get the previous version.
*
* @return the previous version
*/
public String getPrevVersion() {
return prevVersion;
}
/**
* Get the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.rightAngleBracket();
xml.optElement("prev-version", prevVersion);
xml.optElement("version", version);
Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = affiliations.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
xml.element(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
}
xml.closeElement(this);
return xml;
}
public static AffiliationsChangeExtension from(Message message) {
return message.getExtension(AffiliationsChangeExtension.ELEMENT, AffiliationsChangeExtension.NAMESPACE);
}
}
/**
* Configurations change extension element class.
*
* @author Fernando Ramirez
*
*/
public static class ConfigurationsChangeExtension implements ExtensionElement {
public static final String ELEMENT = DataForm.ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;
private final String prevVersion;
private final String version;
private final String roomName;
private final String subject;
private final HashMap<String, String> customConfigs;
/**
* Configurations change extension constructor.
*
* @param prevVersion
* @param version
* @param roomName
* @param subject
* @param customConfigs
*/
public ConfigurationsChangeExtension(String prevVersion, String version, String roomName, String subject,
HashMap<String, String> customConfigs) {
this.prevVersion = prevVersion;
this.version = version;
this.roomName = roomName;
this.subject = subject;
this.customConfigs = customConfigs;
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
/**
* Get the previous version.
*
* @return the previous version
*/
public String getPrevVersion() {
return prevVersion;
}
/**
* Get the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
/**
* Get the room name.
*
* @return the room name
*/
public String getRoomName() {
return roomName;
}
/**
* Get the room subject.
*
* @return the room subject
*/
public String getSubject() {
return subject;
}
/**
* Get the room custom configurations.
*
* @return the room custom configurations
*/
public HashMap<String, String> getCustomConfigs() {
return customConfigs;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.rightAngleBracket();
xml.optElement("prev-version", prevVersion);
xml.optElement("version", version);
xml.optElement("roomname", roomName);
xml.optElement("subject", subject);
if (customConfigs != null) {
Iterator<Map.Entry<String, String>> it = customConfigs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
xml.element(pair.getKey(), pair.getValue());
}
}
xml.closeElement(this);
return xml;
}
public static ConfigurationsChangeExtension from(Message message) {
return message.getExtension(ConfigurationsChangeExtension.ELEMENT, ConfigurationsChangeExtension.NAMESPACE);
}
}
/**
* Configuration element class.
*
* @author Fernando Ramirez
*
*/
public static class ConfigurationElement implements Element {
private MUCLightRoomConfiguration configuration;
/**
* Configuration element constructor.
*
* @param configuration
*/
public ConfigurationElement(MUCLightRoomConfiguration configuration) {
this.configuration = configuration;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.openElement("configuration");
xml.element("roomname", configuration.getRoomName());
xml.optElement("subject", configuration.getSubject());
if (configuration.getCustomConfigs() != null) {
Iterator<Map.Entry<String, String>> it = configuration.getCustomConfigs().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
xml.element(pair.getKey(), pair.getValue());
}
}
xml.closeElement("configuration");
return xml;
}
}
/**
* Occupants element class.
*
* @author Fernando Ramirez
*
*/
public static class OccupantsElement implements Element {
private HashMap<Jid, MUCLightAffiliation> occupants;
/**
* Occupants element constructor.
*
* @param occupants
*/
public OccupantsElement(HashMap<Jid, MUCLightAffiliation> occupants) {
this.occupants = occupants;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.openElement("occupants");
Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = occupants.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
xml.element(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
}
xml.closeElement("occupants");
return xml;
}
}
/**
* User with affiliation element class.
*
* @author Fernando Ramirez
*
*/
public static class UserWithAffiliationElement implements Element {
private Jid user;
private MUCLightAffiliation affiliation;
/**
* User with affiliations element constructor.
*
* @param user
* @param affiliation
*/
public UserWithAffiliationElement(Jid user, MUCLightAffiliation affiliation) {
this.user = user;
this.affiliation = affiliation;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement("user");
xml.attribute("affiliation", affiliation);
xml.rightAngleBracket();
xml.escape(user);
xml.closeElement("user");
return xml;
}
}
/**
* Blocking element class.
*
* @author Fernando Ramirez
*
*/
public static class BlockingElement implements Element {
private Jid jid;
private Boolean allow;
private Boolean isRoom;
/**
* Blocking element constructor.
*
* @param jid
* @param allow
* @param isRoom
*/
public BlockingElement(Jid jid, Boolean allow, Boolean isRoom) {
this.jid = jid;
this.allow = allow;
this.isRoom = isRoom;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
String tag = isRoom ? "room" : "user";
xml.halfOpenElement(tag);
String action = allow ? "allow" : "deny";
xml.attribute("action", action);
xml.rightAngleBracket();
xml.escape(jid);
xml.closeElement(tag);
return xml;
}
}
}

View file

@ -0,0 +1,65 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jxmpp.jid.Jid;
/**
* MUC Light get affiliations IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightGetAffiliationsIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;
private String version;
/**
* MUC Light get affiliations IQ constructor.
*
* @param roomJid
* @param version
*/
public MUCLightGetAffiliationsIQ(Jid roomJid, String version) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.setType(Type.get);
this.setTo(roomJid);
}
/**
* MUC Light get affiliations IQ constructor.
*
* @param roomJid
*/
public MUCLightGetAffiliationsIQ(Jid roomJid) {
this(roomJid, null);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
return xml;
}
}

View file

@ -0,0 +1,65 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jxmpp.jid.Jid;
/**
* MUC Light get configurations IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightGetConfigsIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;
private String version;
/**
* MUC Light get configurations IQ constructor.
*
* @param roomJid
* @param version
*/
public MUCLightGetConfigsIQ(Jid roomJid, String version) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.setType(Type.get);
this.setTo(roomJid);
}
/**
* MUC Light get configurations IQ constructor.
*
* @param roomJid
*/
public MUCLightGetConfigsIQ(Jid roomJid) {
this(roomJid, null);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
return xml;
}
}

View file

@ -0,0 +1,65 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jxmpp.jid.Jid;
/**
* MUC Light get info IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightGetInfoIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.INFO;
private String version;
/**
* MUC Light get info IQ constructor.
*
* @param roomJid
* @param version
*/
public MUCLightGetInfoIQ(Jid roomJid, String version) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.setType(Type.get);
this.setTo(roomJid);
}
/**
* MUC Light get info IQ constructor.
*
* @param roomJid
*/
public MUCLightGetInfoIQ(Jid roomJid) {
this(roomJid, null);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
return xml;
}
}

View file

@ -0,0 +1,95 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationElement;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.OccupantsElement;
import org.jxmpp.jid.Jid;
/**
* MUC Light info response IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightInfoIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.INFO;
private final String version;
private final MUCLightRoomConfiguration configuration;
private final HashMap<Jid, MUCLightAffiliation> occupants;
/**
* MUCLight info response IQ constructor.
*
* @param version
* @param configuration
* @param occupants
*/
public MUCLightInfoIQ(String version, MUCLightRoomConfiguration configuration,
HashMap<Jid, MUCLightAffiliation> occupants) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.configuration = configuration;
this.occupants = occupants;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
xml.element(new ConfigurationElement(configuration));
xml.element(new OccupantsElement(occupants));
return xml;
}
/**
* Returns the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
/**
* Returns the room configuration.
*
* @return the configuration of the room
*/
public MUCLightRoomConfiguration getConfiguration() {
return configuration;
}
/**
* Returns the room occupants.
*
* @return the occupants of the room
*/
public HashMap<Jid, MUCLightAffiliation> getOccupants() {
return occupants;
}
}

View file

@ -0,0 +1,87 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.element;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jxmpp.jid.Jid;
/**
* MUC Light set configurations IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightSetConfigsIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;
private String roomName;
private String subject;
private HashMap<String, String> customConfigs;
/**
* MUC Light set configuration IQ constructor.
*
* @param roomJid
* @param roomName
* @param subject
* @param customConfigs
*/
public MUCLightSetConfigsIQ(Jid roomJid, String roomName, String subject, HashMap<String, String> customConfigs) {
super(ELEMENT, NAMESPACE);
this.roomName = roomName;
this.subject = subject;
this.customConfigs = customConfigs;
this.setType(Type.set);
this.setTo(roomJid);
}
/**
* MUC Light set configuration IQ constructor.
*
* @param roomJid
* @param roomName
* @param customConfigs
*/
public MUCLightSetConfigsIQ(Jid roomJid, String roomName, HashMap<String, String> customConfigs) {
this(roomJid, roomName, null, customConfigs);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("roomname", roomName);
xml.optElement("subject", subject);
if (customConfigs != null) {
Iterator<Map.Entry<String, String>> it = customConfigs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
xml.element(pair.getKey(), pair.getValue());
}
}
return xml;
}
}

View file

@ -0,0 +1,25 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.
*/
/**
* Multi-User Chat Light (MUC Light) elements.
*
* @see <a href=
* "http://mongooseim.readthedocs.io/en/latest/open-extensions/xeps/xep-muc-light.html">
* XEP-xxxx: Multi-User Chat Light</a>
*
*/
package org.jivesoftware.smackx.muclight.element;

View file

@ -0,0 +1,25 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.
*/
/**
* Classes and Interfaces that implement Multi-User Chat Light (MUC Light).
*
* @see <a href=
* "http://mongooseim.readthedocs.io/en/latest/open-extensions/xeps/xep-muc-light.html">
* XEP-xxxx: Multi-User Chat Light</a>
*
*/
package org.jivesoftware.smackx.muclight;

View file

@ -0,0 +1,72 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.provider;
import java.util.HashMap;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.AffiliationsChangeExtension;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParser;
/**
* MUC Light Affiliations Change Provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightAffiliationsChangeProvider extends ExtensionElementProvider<AffiliationsChangeExtension> {
@Override
public AffiliationsChangeExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>();
String prevVersion = null;
String version = null;
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("prev-version")) {
prevVersion = parser.nextText();
}
if (parser.getName().equals("version")) {
version = parser.nextText();
}
if (parser.getName().equals("user")) {
MUCLightAffiliation mucLightAffiliation = MUCLightAffiliation
.fromString(parser.getAttributeValue("", "affiliation"));
Jid jid = JidCreate.from(parser.nextText());
affiliations.put(jid, mucLightAffiliation);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
return new AffiliationsChangeExtension(affiliations, prevVersion, version);
}
}

View file

@ -0,0 +1,66 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.provider;
import java.util.HashMap;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.element.MUCLightAffiliationsIQ;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParser;
/**
* MUC Light affiliations IQ provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightAffiliationsIQProvider extends IQProvider<MUCLightAffiliationsIQ> {
@Override
public MUCLightAffiliationsIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
String version = null;
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("version")) {
version = parser.nextText();
}
if (parser.getName().equals("user")) {
MUCLightAffiliation affiliation = MUCLightAffiliation
.fromString(parser.getAttributeValue("", "affiliation"));
occupants.put(JidCreate.from(parser.nextText()), affiliation);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
return new MUCLightAffiliationsIQ(version, occupants);
}
}

View file

@ -0,0 +1,84 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.provider;
import java.io.IOException;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* MUC Light blocking IQ provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightBlockingIQProvider extends IQProvider<MUCLightBlockingIQ> {
@Override
public MUCLightBlockingIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
HashMap<Jid, Boolean> rooms = null;
HashMap<Jid, Boolean> users = null;
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("room")) {
rooms = parseBlocking(parser, rooms);
}
if (parser.getName().equals("user")) {
users = parseBlocking(parser, users);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, users);
mucLightBlockingIQ.setType(Type.result);
return mucLightBlockingIQ;
}
private HashMap<Jid, Boolean> parseBlocking(XmlPullParser parser, HashMap<Jid, Boolean> map)
throws XmppStringprepException, XmlPullParserException, IOException {
if (map == null) {
map = new HashMap<>();
}
String action = parser.getAttributeValue("", "action");
if (action.equals("deny")) {
map.put(JidCreate.from(parser.nextText()), false);
} else if (action.equals("allow")) {
map.put(JidCreate.from(parser.nextText()), true);
}
return map;
}
}

View file

@ -0,0 +1,71 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.provider;
import java.util.HashMap;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.element.MUCLightConfigurationIQ;
import org.xmlpull.v1.XmlPullParser;
/**
* MUC Light configuration IQ provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightConfigurationIQProvider extends IQProvider<MUCLightConfigurationIQ> {
@Override
public MUCLightConfigurationIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
String version = null;
String roomName = null;
String subject = null;
HashMap<String, String> customConfigs = null;
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("version")) {
version = parser.nextText();
} else if (parser.getName().equals("roomname")) {
roomName = parser.nextText();
} else if (parser.getName().equals("subject")) {
subject = parser.nextText();
} else {
if (customConfigs == null) {
customConfigs = new HashMap<>();
}
customConfigs.put(parser.getName(), parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
MUCLightRoomConfiguration configuration = new MUCLightRoomConfiguration(roomName, subject, customConfigs);
return new MUCLightConfigurationIQ(version, configuration);
}
}

View file

@ -0,0 +1,71 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.provider;
import java.util.HashMap;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationsChangeExtension;
import org.xmlpull.v1.XmlPullParser;
/**
* MUC Light configurations change provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightConfigurationsChangeProvider extends ExtensionElementProvider<ConfigurationsChangeExtension> {
@Override
public ConfigurationsChangeExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
String prevVersion = null;
String version = null;
String roomName = null;
String subject = null;
HashMap<String, String> customConfigs = null;
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("prev-version")) {
prevVersion = parser.nextText();
} else if (parser.getName().equals("version")) {
version = parser.nextText();
} else if (parser.getName().equals("roomname")) {
roomName = parser.nextText();
} else if (parser.getName().equals("subject")) {
subject = parser.nextText();
} else {
if (customConfigs == null) {
customConfigs = new HashMap<>();
}
customConfigs.put(parser.getName(), parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
return new ConfigurationsChangeExtension(prevVersion, version, roomName, subject, customConfigs);
}
}

View file

@ -0,0 +1,116 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight.provider;
import java.util.HashMap;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.element.MUCLightInfoIQ;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParser;
/**
* MUC Light info IQ provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightInfoIQProvider extends IQProvider<MUCLightInfoIQ> {
@Override
public MUCLightInfoIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
String version = null;
String roomName = null;
String subject = null;
HashMap<String, String> customConfigs = null;
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("version")) {
version = parser.nextText();
}
if (parser.getName().equals("configuration")) {
int depth = parser.getDepth();
outerloop2: while (true) {
eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("roomname")) {
roomName = parser.nextText();
} else if (parser.getName().equals("subject")) {
subject = parser.nextText();
} else {
if (customConfigs == null) {
customConfigs = new HashMap<>();
}
customConfigs.put(parser.getName(), parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == depth) {
break outerloop2;
}
}
}
}
if (parser.getName().equals("occupants")) {
occupants = iterateOccupants(parser);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
return new MUCLightInfoIQ(version, new MUCLightRoomConfiguration(roomName, subject, customConfigs), occupants);
}
private HashMap<Jid, MUCLightAffiliation> iterateOccupants(XmlPullParser parser) throws Exception {
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
int depth = parser.getDepth();
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("user")) {
MUCLightAffiliation affiliation = MUCLightAffiliation
.fromString(parser.getAttributeValue("", "affiliation"));
occupants.put(JidCreate.from(parser.nextText()), affiliation);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == depth) {
break outerloop;
}
}
}
return occupants;
}
}

View file

@ -0,0 +1,25 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.
*/
/**
* Multi-User Chat Light (MUC Light) providers.
*
* @see <a href=
* "http://mongooseim.readthedocs.io/en/latest/open-extensions/xeps/xep-muc-light.html">
* XEP-xxxx: Multi-User Chat Light</a>
*
*/
package org.jivesoftware.smackx.muclight.provider;

View file

@ -52,6 +52,38 @@
<className>org.jivesoftware.smackx.gcm.provider.GcmExtensionProvider</className>
</extensionProvider>
<!-- XEP-xxxx: Multi-User Chat Light -->
<iqProvider>
<elementName>query</elementName>
<namespace>urn:xmpp:muclight:0#info</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightInfoIQProvider</className>
</iqProvider>
<extensionProvider>
<elementName>x</elementName>
<namespace>urn:xmpp:muclight:0#affiliations</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightAffiliationsChangeProvider</className>
</extensionProvider>
<extensionProvider>
<elementName>x</elementName>
<namespace>urn:xmpp:muclight:0#configuration</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightConfigurationsChangeProvider</className>
</extensionProvider>
<iqProvider>
<elementName>query</elementName>
<namespace>urn:xmpp:muclight:0#configuration</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightConfigurationIQProvider</className>
</iqProvider>
<iqProvider>
<elementName>query</elementName>
<namespace>urn:xmpp:muclight:0#affiliations</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightAffiliationsIQProvider</className>
</iqProvider>
<iqProvider>
<elementName>query</elementName>
<namespace>urn:xmpp:muclight:0#blocking</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightBlockingIQProvider</className>
</iqProvider>
<!-- XEP-0313 Message Archive Management -->
<iqProvider>
<elementName>prefs</elementName>

View file

@ -0,0 +1,92 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.AffiliationsChangeExtension;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightAffiliationsChangeExtensionTest {
String exampleMessageStanza = "<message " + "to='coven@muclight.shakespeare.lit' id='member1' type='groupchat'>"
+ "<x xmlns='urn:xmpp:muclight:0#affiliations'>"
+ "<user affiliation='owner'>sarasa2@shakespeare.lit</user>"
+ "<user affiliation='member'>sarasa1@shakespeare.lit</user>"
+ "<user affiliation='none'>sarasa3@shakespeare.lit</user>" + "</x>" + "</message>";
String exampleMessageStanzaWithVersion = "<message "
+ "to='coven@muclight.shakespeare.lit' id='member1' type='groupchat'>"
+ "<x xmlns='urn:xmpp:muclight:0#affiliations'>" + "<version>qwerty</version>"
+ "<user affiliation='member'>sarasa1@shakespeare.lit</user>"
+ "<user affiliation='none'>sarasa3@shakespeare.lit</user>" + "</x>" + "<body></body>" + "</message>";
String exampleMessageStanzaWithPrevVersion = "<message "
+ "to='coven@muclight.shakespeare.lit' id='member1' type='groupchat'>"
+ "<x xmlns='urn:xmpp:muclight:0#affiliations'>" + "<prev-version>njiokm</prev-version>"
+ "<version>qwerty</version>" + "<user affiliation='owner'>sarasa2@shakespeare.lit</user>"
+ "<user affiliation='member'>sarasa1@shakespeare.lit</user>" + "</x>" + "<body></body>" + "</message>";
@Test
public void checkAffiliationsChangeExtension() throws Exception {
Message changeAffiliationsMessage = (Message) PacketParserUtils.parseStanza(exampleMessageStanza);
AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension
.from(changeAffiliationsMessage);
HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
Assert.assertEquals(affiliations.size(), 3);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa2@shakespeare.lit")), MUCLightAffiliation.owner);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa3@shakespeare.lit")), MUCLightAffiliation.none);
}
@Test
public void checkAffiliationsChangeExtensionWithVersion() throws Exception {
Message changeAffiliationsMessage = (Message) PacketParserUtils.parseStanza(exampleMessageStanzaWithVersion);
AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension
.from(changeAffiliationsMessage);
HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
Assert.assertEquals(affiliations.size(), 2);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa3@shakespeare.lit")), MUCLightAffiliation.none);
Assert.assertEquals(affiliationsChangeExtension.getVersion(), "qwerty");
}
@Test
public void checkAffiliationsChangeExtensionWithPrevVersion() throws Exception {
Message changeAffiliationsMessage = (Message) PacketParserUtils
.parseStanza(exampleMessageStanzaWithPrevVersion);
AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension
.from(changeAffiliationsMessage);
HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
Assert.assertEquals(affiliations.size(), 2);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa2@shakespeare.lit")), MUCLightAffiliation.owner);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(affiliationsChangeExtension.getPrevVersion(), "njiokm");
Assert.assertEquals(affiliationsChangeExtension.getVersion(), "qwerty");
}
}

View file

@ -0,0 +1,122 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightBlockingTest {
String getBlockingListIQExample = "<iq to='muclight.shakespeare.lit' id='getblock1' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>" + "</query>" + "</iq>";
String getBlockingListIQResponse = "<iq type='result' id='getblock1' to='crone1@shakespeare.lit/desktop' from='muclight.shakespeare.lit'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>"
+ "<room action='deny'>coven@muclight.shakespeare.lit</room>"
+ "<room action='deny'>sarasa@muclight.shakespeare.lit</room>"
+ "<user action='deny'>hag77@shakespeare.lit</user>" + "</query>" + "</iq>";
String blockingRoomsIQExample = "<iq to='muclight.shakespeare.lit' id='block1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>"
+ "<room action='deny'>coven@muclight.shakespeare.lit</room>"
+ "<room action='deny'>chapel@shakespeare.lit</room>" + "</query>" + "</iq>";
String blockingUsersIQExample = "<iq to='muclight.shakespeare.lit' id='block2' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>" + "<user action='deny'>hag77@shakespeare.lit</user>"
+ "<user action='deny'>hag66@shakespeare.lit</user>" + "</query>" + "</iq>";
String unblockingUsersAndRoomsExample = "<iq to='muclight.shakespeare.lit' id='unblock1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#blocking'>"
+ "<room action='allow'>coven@muclight.shakespeare.lit</room>"
+ "<user action='allow'>hag66@shakespeare.lit</user>" + "</query>" + "</iq>";
@Test
public void checkGetBlockingListIQ() throws Exception {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, null);
mucLightBlockingIQ.setType(Type.get);
mucLightBlockingIQ.setStanzaId("getblock1");
mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
Assert.assertEquals(getBlockingListIQExample, mucLightBlockingIQ.toXML().toString());
}
@Test
public void checkGetBlockingListResponse() throws Exception {
IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(getBlockingListIQResponse);
MUCLightBlockingIQ mucLightBlockingIQ = (MUCLightBlockingIQ) iqInfoResult;
Assert.assertEquals(2, mucLightBlockingIQ.getRooms().size());
Assert.assertEquals(1, mucLightBlockingIQ.getUsers().size());
Assert.assertEquals(false, mucLightBlockingIQ.getRooms().get(JidCreate.from("coven@muclight.shakespeare.lit")));
Assert.assertEquals(false,
mucLightBlockingIQ.getRooms().get(JidCreate.from("sarasa@muclight.shakespeare.lit")));
Assert.assertEquals(false, mucLightBlockingIQ.getUsers().get(JidCreate.from("hag77@shakespeare.lit")));
}
@Test
public void checkBlockRoomsIQ() throws Exception {
HashMap<Jid, Boolean> rooms = new HashMap<>();
rooms.put(JidCreate.from("coven@muclight.shakespeare.lit"), false);
rooms.put(JidCreate.from("chapel@shakespeare.lit"), false);
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
mucLightBlockingIQ.setStanzaId("block1");
Assert.assertEquals(blockingRoomsIQExample, mucLightBlockingIQ.toXML().toString());
}
@Test
public void checkBlockUsersIQ() throws Exception {
HashMap<Jid, Boolean> users = new HashMap<>();
users.put(JidCreate.from("hag77@shakespeare.lit"), false);
users.put(JidCreate.from("hag66@shakespeare.lit"), false);
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
mucLightBlockingIQ.setStanzaId("block2");
Assert.assertEquals(blockingUsersIQExample, mucLightBlockingIQ.toXML().toString());
}
@Test
public void checkUnblockUsersAndRoomsIQ() throws Exception {
HashMap<Jid, Boolean> users = new HashMap<>();
users.put(JidCreate.from("hag66@shakespeare.lit"), true);
HashMap<Jid, Boolean> rooms = new HashMap<>();
rooms.put(JidCreate.from("coven@muclight.shakespeare.lit"), true);
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, users);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
mucLightBlockingIQ.setStanzaId("unblock1");
Assert.assertEquals(unblockingUsersAndRoomsExample, mucLightBlockingIQ.toXML().toString());
}
}

View file

@ -0,0 +1,56 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.element.MUCLightChangeAffiliationsIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightChangeAffiliationsIQTest {
String stanza = "<iq " + "to='coven@muclight.shakespeare.lit' id='member1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#affiliations'>"
+ "<user affiliation='owner'>sarasa2@shakespeare.lit</user>"
+ "<user affiliation='member'>sarasa1@shakespeare.lit</user>"
+ "<user affiliation='none'>sarasa3@shakespeare.lit</user>" + "</query>" + "</iq>";
@Test
public void checkChangeAffiliationsMUCLightStanza() throws Exception {
HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>();
affiliations.put(JidCreate.from("sarasa2@shakespeare.lit"), MUCLightAffiliation.owner);
affiliations.put(JidCreate.from("sarasa1@shakespeare.lit"), MUCLightAffiliation.member);
affiliations.put(JidCreate.from("sarasa3@shakespeare.lit"), MUCLightAffiliation.none);
MUCLightChangeAffiliationsIQ mucLightChangeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), affiliations);
mucLightChangeAffiliationsIQ.setStanzaId("member1");
Assert.assertEquals(mucLightChangeAffiliationsIQ.getTo(), "coven@muclight.shakespeare.lit");
Assert.assertEquals(mucLightChangeAffiliationsIQ.getType(), IQ.Type.set);
HashMap<Jid, MUCLightAffiliation> iqAffiliations = mucLightChangeAffiliationsIQ.getAffiliations();
Assert.assertEquals(iqAffiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(iqAffiliations.get(JidCreate.from("sarasa2@shakespeare.lit")), MUCLightAffiliation.owner);
Assert.assertEquals(iqAffiliations.get(JidCreate.from("sarasa3@shakespeare.lit")), MUCLightAffiliation.none);
}
}

View file

@ -0,0 +1,83 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationsChangeExtension;
import org.junit.Assert;
import org.junit.Test;
public class MUCLightConfigurationsChangeExtensionTest {
String messageWithSubjectChangeExample = "<message to='crone1@shakespeare.lit' from='coven@muclight.shakespeare.lit' id='newsubject' type='groupchat'>"
+ "<body></body>" + "<x xmlns='urn:xmpp:muclight:0#configuration'>"
+ "<prev-version>asdfghj000</prev-version>" + "<version>asdfghj</version>"
+ "<subject>To be or not to be?</subject>" + "</x>" + "</message>";
String messageWithRoomNameChangeExample = "<message to='crone1@shakespeare.lit' from='coven@muclight.shakespeare.lit' id='newsubject' type='groupchat'>"
+ "<body></body>" + "<x xmlns='urn:xmpp:muclight:0#configuration'>" + "<prev-version>zaqwsx</prev-version>"
+ "<version>zxcvbnm</version>" + "<roomname>A Darker Cave</roomname>" + "</x>" + "</message>";
String messageWithConfigsChangeExample = "<message to='crone1@shakespeare.lit' from='coven@muclight.shakespeare.lit' id='newsubject' type='groupchat'>"
+ "<body></body>" + "<x xmlns='urn:xmpp:muclight:0#configuration'>" + "<prev-version>zaqwsx</prev-version>"
+ "<version>zxcvbnm</version>" + "<roomname>A Darker Cave</roomname>" + "<color>blue</color>" + "</x>"
+ "</message>";
@Test
public void checkSubjectChangeExtension() throws Exception {
Message configurationsMessage = (Message) PacketParserUtils.parseStanza(messageWithSubjectChangeExample);
ConfigurationsChangeExtension configurationsChangeExtension = ConfigurationsChangeExtension
.from(configurationsMessage);
Assert.assertEquals("asdfghj000", configurationsChangeExtension.getPrevVersion());
Assert.assertEquals("asdfghj", configurationsChangeExtension.getVersion());
Assert.assertEquals("To be or not to be?", configurationsChangeExtension.getSubject());
Assert.assertNull(configurationsChangeExtension.getRoomName());
Assert.assertNull(configurationsChangeExtension.getCustomConfigs());
Assert.assertEquals(messageWithSubjectChangeExample, configurationsMessage.toXML().toString());
}
@Test
public void checkRoomNameChangeExtension() throws Exception {
Message configurationsMessage = (Message) PacketParserUtils.parseStanza(messageWithRoomNameChangeExample);
ConfigurationsChangeExtension configurationsChangeExtension = ConfigurationsChangeExtension
.from(configurationsMessage);
Assert.assertEquals("zaqwsx", configurationsChangeExtension.getPrevVersion());
Assert.assertEquals("zxcvbnm", configurationsChangeExtension.getVersion());
Assert.assertEquals("A Darker Cave", configurationsChangeExtension.getRoomName());
Assert.assertNull(configurationsChangeExtension.getSubject());
Assert.assertNull(configurationsChangeExtension.getCustomConfigs());
Assert.assertEquals(messageWithRoomNameChangeExample, configurationsMessage.toXML().toString());
}
@Test
public void checkConfigsChangeExtension() throws Exception {
Message configurationsMessage = (Message) PacketParserUtils.parseStanza(messageWithConfigsChangeExample);
ConfigurationsChangeExtension configurationsChangeExtension = ConfigurationsChangeExtension
.from(configurationsMessage);
Assert.assertEquals("zaqwsx", configurationsChangeExtension.getPrevVersion());
Assert.assertEquals("zxcvbnm", configurationsChangeExtension.getVersion());
Assert.assertEquals("A Darker Cave", configurationsChangeExtension.getRoomName());
Assert.assertNull(configurationsChangeExtension.getSubject());
Assert.assertEquals("blue", configurationsChangeExtension.getCustomConfigs().get("color"));
Assert.assertEquals(messageWithConfigsChangeExample, configurationsMessage.toXML().toString());
}
}

View file

@ -0,0 +1,55 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.jivesoftware.smackx.muclight.element.MUCLightCreateIQ;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.junit.Assert;
public class MUCLightCreateIQTest {
String stanza = "<iq to='ef498f55-5f79-4238-a5ae-4efe19cbe617@muclight.test.com' id='1c72W-50' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#create'>" + "<configuration>" + "<roomname>test</roomname>"
+ "</configuration>" + "<occupants>" + "<user affiliation='member'>charlie@test.com</user>"
+ "<user affiliation='member'>pep@test.com</user>" + "</occupants>" + "</query>" + "</iq>";
@Test
public void checkCreateMUCLightStanza() throws Exception {
List<Jid> occupants = new ArrayList<>();
occupants.add(JidCreate.from("charlie@test.com"));
occupants.add(JidCreate.from("pep@test.com"));
MUCLightCreateIQ mucLightCreateIQ = new MUCLightCreateIQ(
JidCreate.from("ef498f55-5f79-4238-a5ae-4efe19cbe617@muclight.test.com").asEntityJidIfPossible(),
"test", occupants);
mucLightCreateIQ.setStanzaId("1c72W-50");
Assert.assertEquals(mucLightCreateIQ.getConfiguration().getRoomName(), "test");
HashMap<Jid, MUCLightAffiliation> iqOccupants = mucLightCreateIQ.getOccupants();
Assert.assertEquals(iqOccupants.get(JidCreate.from("charlie@test.com")), MUCLightAffiliation.member);
Assert.assertEquals(iqOccupants.get(JidCreate.from("pep@test.com")), MUCLightAffiliation.member);
}
}

View file

@ -0,0 +1,36 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import org.jivesoftware.smackx.muclight.element.MUCLightDestroyIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightDestroyTest {
String stanza = "<iq to='coven@muclight.shakespeare.lit' id='destroy1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#destroy'/>" + "</iq>";
@Test
public void checkDestroyMUCLightStanza() throws Exception{
MUCLightDestroyIQ mucLightDestroyIQ = new MUCLightDestroyIQ(JidCreate.from("coven@muclight.shakespeare.lit"));
mucLightDestroyIQ.setStanzaId("destroy1");
Assert.assertEquals(mucLightDestroyIQ.toXML().toString(), stanza);
}
}

View file

@ -0,0 +1,63 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightAffiliationsIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightGetAffiliationsIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightGetAffiliationsTest {
String getAffiliationsIQExample = "<iq to='coven@muclight.shakespeare.lit' id='getmembers' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#affiliations'>" + "<version>abcdefg</version>" + "</query>" + "</iq>";
String getAffiliationsResponseExample = "<iq from='coven@muclight.shakespeare.lit' id='getmembers' to='crone1@shakespeare.lit/desktop' type='result'>"
+ "<query xmlns='urn:xmpp:muclight:0#affiliations'>" + "<version>123456</version>"
+ "<user affiliation='owner'>user1@shakespeare.lit</user>"
+ "<user affiliation='member'>user2@shakespeare.lit</user>"
+ "<user affiliation='member'>user3@shakespeare.lit</user>" + "</query>" + "</iq>";
@Test
public void checkGetAffiliationsIQ() throws Exception {
MUCLightGetAffiliationsIQ mucLightGetAffiliationsIQ = new MUCLightGetAffiliationsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), "abcdefg");
mucLightGetAffiliationsIQ.setStanzaId("getmembers");
Assert.assertEquals(getAffiliationsIQExample, mucLightGetAffiliationsIQ.toXML().toString());
}
@Test
public void checkGetAffiliationsResponse() throws Exception {
IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(getAffiliationsResponseExample);
MUCLightAffiliationsIQ mucLightAffiliationsIQ = (MUCLightAffiliationsIQ) iqInfoResult;
Assert.assertEquals("123456", mucLightAffiliationsIQ.getVersion());
HashMap<Jid, MUCLightAffiliation> affiliations = mucLightAffiliationsIQ.getAffiliations();
Assert.assertEquals(3, affiliations.size());
Assert.assertEquals(MUCLightAffiliation.owner, affiliations.get(JidCreate.from("user1@shakespeare.lit")));
Assert.assertEquals(MUCLightAffiliation.member, affiliations.get(JidCreate.from("user2@shakespeare.lit")));
Assert.assertEquals(MUCLightAffiliation.member, affiliations.get(JidCreate.from("user3@shakespeare.lit")));
}
}

View file

@ -0,0 +1,77 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightConfigurationIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightGetConfigsIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightGetConfigsTest {
String getConfigsIQExample = "<iq to='coven@muclight.shakespeare.lit' id='config0' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#configuration'>" + "<version>abcdefg</version>" + "</query>" + "</iq>";
String getConfigsResponseExample = "<iq from='coven@muclight.shakespeare.lit' id='getconfig1' "
+ "to='crone1@shakespeare.lit/desktop' type='result'>" + "<query xmlns='urn:xmpp:muclight:0#configuration'>"
+ "<version>123456</version>" + "<roomname>A Dark Cave</roomname>" + "<subject>A subject</subject>"
+ "</query>" + "</iq>";
String getConfigsResponseExampleWithCustomConfigs = "<iq from='coven@muclight.shakespeare.lit' id='getconfig2' "
+ "to='crone1@shakespeare.lit/desktop' type='result'>" + "<query xmlns='urn:xmpp:muclight:0#configuration'>"
+ "<version>123456</version>" + "<roomname>A Dark Cave</roomname>" + "<color>blue</color>"
+ "<size>20</size>" + "</query>" + "</iq>";
@Test
public void checkGetConfigsIQ() throws Exception {
MUCLightGetConfigsIQ mucLightGetConfigsIQ = new MUCLightGetConfigsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), "abcdefg");
mucLightGetConfigsIQ.setStanzaId("config0");
Assert.assertEquals(getConfigsIQExample, mucLightGetConfigsIQ.toXML().toString());
}
@Test
public void checkGetConfigsResponse() throws Exception {
IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(getConfigsResponseExample);
MUCLightConfigurationIQ mucLightConfigurationIQ = (MUCLightConfigurationIQ) iqInfoResult;
Assert.assertEquals("123456", mucLightConfigurationIQ.getVersion());
Assert.assertEquals("A Dark Cave", mucLightConfigurationIQ.getConfiguration().getRoomName());
Assert.assertEquals("A subject", mucLightConfigurationIQ.getConfiguration().getSubject());
Assert.assertNull(mucLightConfigurationIQ.getConfiguration().getCustomConfigs());
}
@Test
public void checkGetConfigsResponseWithCustomConfigs() throws Exception {
IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(getConfigsResponseExampleWithCustomConfigs);
MUCLightConfigurationIQ mucLightConfigurationIQ = (MUCLightConfigurationIQ) iqInfoResult;
Assert.assertEquals("123456", mucLightConfigurationIQ.getVersion());
Assert.assertEquals("A Dark Cave", mucLightConfigurationIQ.getConfiguration().getRoomName());
Assert.assertNull(mucLightConfigurationIQ.getConfiguration().getSubject());
HashMap<String, String> customConfigs = mucLightConfigurationIQ.getConfiguration().getCustomConfigs();
Assert.assertEquals("blue", customConfigs.get("color"));
Assert.assertEquals("20", customConfigs.get("size"));
}
}

View file

@ -0,0 +1,72 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.muclight.element.MUCLightGetInfoIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightInfoIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightInfoTest {
String exampleWithVersion = "<iq to='coven@muclight.shakespeare.lit' id='getinfo1' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#info'>" + "<version>abcdefg</version>" + "</query>" + "</iq>";
String exampleWithoutVersion = "<iq to='coven@muclight.shakespeare.lit' id='getinfo1' type='get'>"
+ "<query xmlns='urn:xmpp:muclight:0#info'>" + "</query>" + "</iq>";
String exampleInfoResult = "<iq from='coven@muclight.shakespeare.lit' to='cronel@shakespeare.lit/desktop' id='getinfo1' type='result'>"
+ "<query xmlns='urn:xmpp:muclight:0#info'>" + "<version>123456</version>" + "<configuration>"
+ "<roomname>test</roomname>" + "</configuration>" + "<occupants>"
+ "<user affiliation='owner'>john@test.com</user>" + "<user affiliation='member'>charlie@test.com</user>"
+ "<user affiliation='member'>pep@test.com</user>" + "</occupants>" + "</query>" + "</iq>";
@Test
public void checkMUCLightGetInfoIQStanzaWithVersion() throws Exception {
MUCLightGetInfoIQ mucLightGetInfoIQWithVersion = new MUCLightGetInfoIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), "abcdefg");
mucLightGetInfoIQWithVersion.setStanzaId("getinfo1");
Assert.assertEquals(mucLightGetInfoIQWithVersion.toXML().toString(), exampleWithVersion);
}
@Test
public void checkMUCLightGetInfoIQStanzaWithoutVersion() throws Exception {
MUCLightGetInfoIQ mucLightGetInfoIQWithoutVersion = new MUCLightGetInfoIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), null);
mucLightGetInfoIQWithoutVersion.setStanzaId("getinfo1");
Assert.assertEquals(mucLightGetInfoIQWithoutVersion.toXML().toString(), exampleWithoutVersion);
}
@Test
public void checkMUCLightInfoResult() throws Exception {
IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(exampleInfoResult);
MUCLightInfoIQ mucLightInfoResponseIQ = (MUCLightInfoIQ) iqInfoResult;
Assert.assertEquals(mucLightInfoResponseIQ.getVersion(), "123456");
Assert.assertEquals(mucLightInfoResponseIQ.getConfiguration().getRoomName(), "test");
Assert.assertEquals(mucLightInfoResponseIQ.getOccupants().size(), 3);
Assert.assertEquals(mucLightInfoResponseIQ.getOccupants().get(JidCreate.from("john@test.com")),
MUCLightAffiliation.owner);
Assert.assertEquals(mucLightInfoResponseIQ.getOccupants().get(JidCreate.from("charlie@test.com")),
MUCLightAffiliation.member);
Assert.assertEquals(mucLightInfoResponseIQ.getOccupants().get(JidCreate.from("pep@test.com")),
MUCLightAffiliation.member);
}
}

View file

@ -0,0 +1,70 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.muclight;
import java.util.HashMap;
import org.jivesoftware.smackx.muclight.element.MUCLightSetConfigsIQ;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
public class MUCLightSetConfigsIQTest {
String setConfigsIQExample = "<iq to='coven@muclight.shakespeare.lit' id='conf1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#configuration'>" + "<roomname>A Darker Cave</roomname>"
+ "<color>blue</color>" + "</query>" + "</iq>";
String changeRoomNameIQExample = "<iq to='coven@muclight.shakespeare.lit' id='roomName1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#configuration'>" + "<roomname>A Darker Cave</roomname>" + "</query>"
+ "</iq>";
String changeSubjectIQExample = "<iq to='coven@muclight.shakespeare.lit' id='subject1' type='set'>"
+ "<query xmlns='urn:xmpp:muclight:0#configuration'>" + "<subject>To be or not to be?</subject>"
+ "</query>" + "</iq>";
@Test
public void checkSetConfigsStanza() throws Exception {
HashMap<String, String> customConfigs = new HashMap<>();
customConfigs.put("color", "blue");
MUCLightSetConfigsIQ mucLightSetConfigsIQ = new MUCLightSetConfigsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), "A Darker Cave", customConfigs);
mucLightSetConfigsIQ.setStanzaId("conf1");
Assert.assertEquals(setConfigsIQExample, mucLightSetConfigsIQ.toXML().toString());
}
@Test
public void checkChangeRoomNameStanza() throws Exception {
MUCLightSetConfigsIQ mucLightChangeRoomNameIQ = new MUCLightSetConfigsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), "A Darker Cave", null);
mucLightChangeRoomNameIQ.setStanzaId("roomName1");
Assert.assertEquals(changeRoomNameIQExample, mucLightChangeRoomNameIQ.toXML().toString());
}
@Test
public void checkChangeSubjectStanza() throws Exception {
MUCLightSetConfigsIQ mucLightChangeSubjectIQ = new MUCLightSetConfigsIQ(
JidCreate.from("coven@muclight.shakespeare.lit"), null, "To be or not to be?", null);
mucLightChangeSubjectIQ.setStanzaId("subject1");
Assert.assertEquals(changeSubjectIQExample, mucLightChangeSubjectIQ.toXML().toString());
}
}