Search in sources :

Example 1 with ChatRoomCreateException

use of org.eclipse.ecf.presence.chatroom.ChatRoomCreateException in project ecf by eclipse.

the class XMPPChatRoomManager method createChatRoom.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.presence.chatroom.IChatRoomManager#createChatRoom(java.lang.String,
	 *      java.util.Map)
	 */
public IChatRoomInfo createChatRoom(String roomname, Map properties) throws ChatRoomCreateException {
    if (roomname == null)
        throw new ChatRoomCreateException(roomname, Messages.XMPPChatRoomManager_EXCEPTION_ROOM_CANNOT_BE_NULL);
    try {
        final String nickname = ecfConnection.getXMPPConnection().getUser();
        final String server = ecfConnection.getXMPPConnection().getHost();
        final String domain = (properties == null) ? XMPPRoomID.DOMAIN_DEFAULT : (String) properties.get(PROP_XMPP_CONFERENCE);
        final String conference = XMPPRoomID.fixConferenceDomain(domain, server);
        final String roomID = roomname + XMPPRoomID.AT_SIGN + conference;
        // create proxy to the room
        final MultiUserChat muc = new MultiUserChat(ecfConnection.getXMPPConnection(), roomID);
        if (!checkRoom(conference, roomID)) {
            // otherwise create a new one
            muc.create(nickname);
            muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
            final String subject = (properties == null) ? null : (String) properties.get(PROP_XMPP_SUBJECT);
            if (subject != null)
                muc.changeSubject(subject);
        }
        String longname = muc.getRoom();
        if (longname == null || longname.length() <= 0) {
            longname = roomID;
        }
        final RoomInfo info = MultiUserChat.getRoomInfo(ecfConnection.getXMPPConnection(), roomID);
        if (info != null) {
            final XMPPRoomID xid = new XMPPRoomID(connectedID.getNamespace(), ecfConnection.getXMPPConnection(), roomID, longname);
            return new ECFRoomInfo(xid, info, connectedID);
        } else
            throw new XMPPException(NLS.bind(Messages.XMPPChatRoomManager_EXCEPTION_NO_ROOM_INFO, roomID));
    } catch (final XMPPException e) {
        throw new ChatRoomCreateException(roomname, e.getMessage(), e);
    } catch (final URISyntaxException e) {
        throw new ChatRoomCreateException(roomname, e.getMessage(), e);
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) Form(org.jivesoftware.smackx.Form) IChatRoomInfo(org.eclipse.ecf.presence.chatroom.IChatRoomInfo) RoomInfo(org.jivesoftware.smackx.muc.RoomInfo) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) URISyntaxException(java.net.URISyntaxException) XMPPException(org.jivesoftware.smack.XMPPException) ChatRoomCreateException(org.eclipse.ecf.presence.chatroom.ChatRoomCreateException)

Aggregations

URISyntaxException (java.net.URISyntaxException)1 ChatRoomCreateException (org.eclipse.ecf.presence.chatroom.ChatRoomCreateException)1 IChatRoomInfo (org.eclipse.ecf.presence.chatroom.IChatRoomInfo)1 XMPPRoomID (org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID)1 XMPPException (org.jivesoftware.smack.XMPPException)1 Form (org.jivesoftware.smackx.Form)1 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)1 RoomInfo (org.jivesoftware.smackx.muc.RoomInfo)1