Search in sources :

Example 16 with MultiUserChatService

use of org.jivesoftware.openfire.muc.MultiUserChatService in project Openfire by igniterealtime.

the class ServiceAddedEvent method run.

@Override
public void run() {
    // should really never occur.
    if (!XMPPServer.getInstance().getMultiUserChatManager().isServiceRegistered(subdomain)) {
        MultiUserChatService service = new MultiUserChatServiceImpl(subdomain, description, isHidden);
        XMPPServer.getInstance().getMultiUserChatManager().registerMultiUserChatService(service, false);
    }
}
Also used : MultiUserChatServiceImpl(org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl) MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService)

Example 17 with MultiUserChatService

use of org.jivesoftware.openfire.muc.MultiUserChatService in project Openfire by igniterealtime.

the class CreateMUCRoom method execute.

@Override
public void execute(SessionData sessionData, Element command) {
    Element note = command.addElement("note");
    Collection<JID> admins = XMPPServer.getInstance().getAdmins();
    if (admins.size() <= 0) {
        note.addAttribute("type", "error");
        note.setText("Server needs admin user to be able to create rooms.");
        return;
    }
    Map<String, List<String>> data = sessionData.getData();
    // Let's find the requested MUC service to create the room in
    String servicehostname = get(data, "servicename", 0);
    if (servicehostname == null) {
        note.addAttribute("type", "error");
        note.setText("Service name must be specified.");
        return;
    }
    // Remove the server's domain name from the passed hostname
    String servicename = servicehostname.replace("." + XMPPServer.getInstance().getServerInfo().getXMPPDomain(), "");
    MultiUserChatService mucService;
    mucService = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(servicename);
    if (mucService == null) {
        note.addAttribute("type", "error");
        note.setText("Invalid service name specified.");
        return;
    }
    if (!mucService.isServiceEnabled()) {
        note.addAttribute("type", "error");
        note.setText("Multi user chat is disabled for specified service.");
        return;
    }
    // Let's create the jid and check that they are a local user
    String roomname = get(data, "roomname", 0);
    if (roomname == null) {
        note.addAttribute("type", "error");
        note.setText("Room name must be specified.");
        return;
    }
    JID admin = admins.iterator().next();
    boolean isPersistent;
    try {
        final String value = get(data, "persistent", 0);
        if (value == null) {
            // this field is not required.
            isPersistent = false;
        } else {
            isPersistent = DataForm.parseBoolean(value);
        }
    } catch (ParseException e) {
        note.addAttribute("type", "error");
        note.setText("persistent has invalid value. Needs to be boolean.");
        return;
    }
    boolean isPublic;
    try {
        final String value = get(data, "public", 0);
        if (value == null) {
            // this field is not required.
            isPublic = false;
        } else {
            isPublic = DataForm.parseBoolean(value);
        }
    } catch (ParseException e) {
        note.addAttribute("type", "error");
        note.setText("public has invalid value. Needs to be boolean.");
        return;
    }
    final Lock lock = mucService.getChatRoomLock(roomname);
    lock.lock();
    try {
        MUCRoom room;
        try {
            room = mucService.getChatRoom(roomname, admin);
        } catch (NotAllowedException e) {
            note.addAttribute("type", "error");
            note.setText("No permission to create rooms.");
            return;
        }
        room.setPersistent(isPersistent);
        room.setPublicRoom(isPublic);
        String password = get(data, "password", 0);
        if (password != null) {
            room.setPassword(password);
        }
        // Make sure that other cluster nodes see the changes made here.
        mucService.syncChatRoom(room);
    } finally {
        lock.unlock();
    }
}
Also used : JID(org.xmpp.packet.JID) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) NotAllowedException(org.jivesoftware.openfire.muc.NotAllowedException) Element(org.dom4j.Element) MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService) List(java.util.List) ParseException(java.text.ParseException) Lock(java.util.concurrent.locks.Lock)

Aggregations

MultiUserChatService (org.jivesoftware.openfire.muc.MultiUserChatService)17 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)5 MUCRole (org.jivesoftware.openfire.muc.MUCRole)3 MultiUserChatManager (org.jivesoftware.openfire.muc.MultiUserChatManager)3 MultiUserChatServiceImpl (org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl)3 JID (org.xmpp.packet.JID)3 ArchivedMessage (com.reucon.openfire.plugin.archive.model.ArchivedMessage)2 Date (java.util.Date)2 List (java.util.List)2 Lock (java.util.concurrent.locks.Lock)2 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)2 ServerFeaturesProvider (org.jivesoftware.openfire.disco.ServerFeaturesProvider)2 IQHandler (org.jivesoftware.openfire.handler.IQHandler)2 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)2 LocalMUCRoom (org.jivesoftware.openfire.muc.spi.LocalMUCRoom)2 XmppResultSet (com.reucon.openfire.plugin.archive.xep0059.XmppResultSet)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1