Search in sources :

Example 1 with XMPPRoomID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID 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)

Example 2 with XMPPRoomID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID in project ecf by eclipse.

the class XMPPChatRoomManager method findReceiverChatRoom.

public IChatRoomContainer findReceiverChatRoom(ID toID) {
    if (toID == null)
        return null;
    XMPPRoomID roomID = null;
    if (toID instanceof XMPPRoomID) {
        roomID = (XMPPRoomID) toID;
        final String mucname = roomID.getMucString();
        List toNotify = null;
        synchronized (chatrooms) {
            toNotify = new ArrayList(chatrooms);
        }
        for (final Iterator i = toNotify.iterator(); i.hasNext(); ) {
            final IChatRoomContainer cont = (IChatRoomContainer) i.next();
            if (cont == null)
                continue;
            final ID tid = cont.getConnectedID();
            if (tid != null && tid instanceof XMPPRoomID) {
                final XMPPRoomID targetID = (XMPPRoomID) tid;
                final String tmuc = targetID.getMucString();
                if (tmuc.equals(mucname)) {
                    return cont;
                }
            }
        }
    }
    return null;
}
Also used : IChatRoomContainer(org.eclipse.ecf.presence.chatroom.IChatRoomContainer) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) ArrayList(java.util.ArrayList) List(java.util.List) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) ID(org.eclipse.ecf.core.identity.ID)

Example 3 with XMPPRoomID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID in project ecf by eclipse.

the class XMPPChatRoomContainer method connect.

public void connect(ID remote, IConnectContext connectContext) throws ContainerConnectException {
    if (!(remote instanceof XMPPRoomID)) {
        throw new ContainerConnectException(NLS.bind(Messages.XMPPChatRoomContainer_Exception_Connect_Wrong_Type, remote));
    }
    final XMPPRoomID roomID = (XMPPRoomID) remote;
    fireContainerEvent(new ContainerConnectingEvent(this.getID(), remote, connectContext));
    synchronized (getConnectLock()) {
        try {
            connectionState = CONNECTING;
            remoteServerID = null;
            addSharedObjectToContainer(remote);
            multiuserchat = new MultiUserChat(getXMPPConnection(), roomID.getMucString());
            // Get nickname from join context
            String nick = null;
            try {
                final Callback[] callbacks = new Callback[1];
                callbacks[0] = new NameCallback(Messages.XMPPChatRoomContainer_NAME_CALLBACK_NICK, roomID.getNickname());
                if (connectContext != null) {
                    final CallbackHandler handler = connectContext.getCallbackHandler();
                    if (handler != null) {
                        handler.handle(callbacks);
                    }
                }
                if (callbacks[0] instanceof NameCallback) {
                    final NameCallback cb = (NameCallback) callbacks[0];
                    nick = cb.getName();
                }
            } catch (final Exception e) {
                throw new ContainerConnectException(Messages.XMPPChatRoomContainer_EXCEPTION_CALLBACKHANDLER, e);
            }
            String nickname = null;
            if (// $NON-NLS-1$
            nick == null || nick.equals(""))
                nickname = roomID.getNickname();
            else
                nickname = nick;
            multiuserchat.addSubjectUpdatedListener(new SubjectUpdatedListener() {

                public void subjectUpdated(String subject, String from) {
                    fireSubjectUpdated(subject, from);
                }
            });
            multiuserchat.addMessageListener(new PacketListener() {

                public void processPacket(Packet arg0) {
                    handleXMPPMessage(arg0);
                }
            });
            multiuserchat.addParticipantListener(new PacketListener() {

                public void processPacket(Packet arg0) {
                    handleXMPPMessage(arg0);
                }
            });
            multiuserchat.addParticipantStatusListener(new ParticipantStatusListener() {

                public void joined(String arg0) {
                    handleChatMembershipEvent(arg0, true);
                }

                public void left(String arg0) {
                    handleChatMembershipEvent(arg0, false);
                }

                public void voiceGranted(String arg0) {
                    // TODO Auto-generated method stub
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("voiceGranted(" + arg0 + ")");
                }

                public void voiceRevoked(String arg0) {
                    // TODO Auto-generated method stub
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("voiceRevoked(" + arg0 + ")");
                }

                public void membershipGranted(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "membershipGranted(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void membershipRevoked(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "membershipRevoked(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void moderatorGranted(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "moderatorGranted(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void moderatorRevoked(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "moderatorRevoked(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void ownershipGranted(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "ownershipGranted(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void ownershipRevoked(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "ownershipRevoked(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void adminGranted(String arg0) {
                    // TODO Auto-generated method stub
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("adminGranted(" + arg0 + ")");
                }

                public void adminRevoked(String arg0) {
                    // TODO Auto-generated method stub
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("adminRevoked(" + arg0 + ")");
                }

                public void kicked(String arg0, String arg1, String arg2) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$ //$NON-NLS-2$
                    "kicked(" + arg0 + "," + arg1 + "," + arg2 + // $NON-NLS-1$ //$NON-NLS-2$
                    ")");
                }

                public void banned(String arg0, String arg1, String arg2) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$ //$NON-NLS-2$
                    "banned(" + arg0 + "," + arg1 + "," + arg2 + // $NON-NLS-1$ //$NON-NLS-2$
                    ")");
                }

                public void nicknameChanged(String arg0, String arg1) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "nicknameChanged(" + arg0 + "," + arg1 + // $NON-NLS-1$ //$NON-NLS-2$
                    ")");
                }
            });
            multiuserchat.addInvitationRejectionListener(new InvitationRejectionListener() {

                public void invitationDeclined(String arg0, String arg1) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "invitationDeclined(" + arg0 + "," + arg1 + // $NON-NLS-1$ //$NON-NLS-2$
                    ")");
                }
            });
            multiuserchat.join(nickname);
            connectionState = CONNECTED;
            remoteServerID = roomID;
            containerHelper.setRoomID(remoteServerID);
            fireContainerEvent(new ContainerConnectedEvent(this.getID(), roomID));
        } catch (final Exception e) {
            cleanUpConnectFail();
            final ContainerConnectException ce = new ContainerConnectException(NLS.bind(Messages.XMPPChatRoomContainer_EXCEPTION_JOINING_ROOM, roomID));
            ce.setStackTrace(e.getStackTrace());
            throw ce;
        }
    }
}
Also used : ParticipantStatusListener(org.jivesoftware.smackx.muc.ParticipantStatusListener) Packet(org.jivesoftware.smack.packet.Packet) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) CallbackHandler(org.eclipse.ecf.core.security.CallbackHandler) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) SubjectUpdatedListener(org.jivesoftware.smackx.muc.SubjectUpdatedListener) PacketListener(org.jivesoftware.smack.PacketListener) ECFException(org.eclipse.ecf.core.util.ECFException) ConnectionCreateException(org.eclipse.ecf.provider.comm.ConnectionCreateException) XMPPException(org.jivesoftware.smack.XMPPException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IOException(java.io.IOException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) SharedObjectAddException(org.eclipse.ecf.core.sharedobject.SharedObjectAddException) InvitationRejectionListener(org.jivesoftware.smackx.muc.InvitationRejectionListener) Callback(org.eclipse.ecf.core.security.Callback) NameCallback(org.eclipse.ecf.core.security.NameCallback) NameCallback(org.eclipse.ecf.core.security.NameCallback) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent)

Example 4 with XMPPRoomID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID in project ecf by eclipse.

the class XMPPChatRoomManager method getChatRoomInfo.

public IChatRoomInfo getChatRoomInfo(String roomname) {
    try {
        if (ecfConnection == null)
            return null;
        // Create roomid
        final XMPPConnection conn = ecfConnection.getXMPPConnection();
        final XMPPRoomID roomID = new XMPPRoomID(connectNamespace, conn, roomname);
        final String mucName = roomID.getMucString();
        final RoomInfo info = MultiUserChat.getRoomInfo(conn, mucName);
        if (info != null) {
            return new ECFRoomInfo(roomID, info, connectedID);
        }
    } catch (final Exception e) {
        return null;
    }
    return null;
}
Also used : XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) IChatRoomInfo(org.eclipse.ecf.presence.chatroom.IChatRoomInfo) RoomInfo(org.jivesoftware.smackx.muc.RoomInfo) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ECFException(org.eclipse.ecf.core.util.ECFException) ChatRoomCreateException(org.eclipse.ecf.presence.chatroom.ChatRoomCreateException) URISyntaxException(java.net.URISyntaxException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 5 with XMPPRoomID

use of org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID in project ecf by eclipse.

the class ECFConnection method sendMessage.

protected void sendMessage(ID receiver, Message aMsg) throws IOException {
    synchronized (this) {
        if (!isConnected())
            throw new IOException("not connected");
        try {
            if (receiver == null)
                throw new IOException("receiver cannot be null for xmpp instant messaging");
            else if (receiver instanceof XMPPID) {
                final XMPPID rcvr = (XMPPID) receiver;
                aMsg.setType(Message.Type.chat);
                final String receiverName = rcvr.getFQName();
                final Chat localChat = connection.getChatManager().createChat(receiverName, new MessageListener() {

                    public void processMessage(Chat chat, Message message) {
                    }
                });
                localChat.sendMessage(aMsg);
            } else if (receiver instanceof XMPPRoomID) {
                final XMPPRoomID roomID = (XMPPRoomID) receiver;
                aMsg.setType(Message.Type.groupchat);
                final String to = roomID.getMucString();
                aMsg.setTo(to);
                connection.sendPacket(aMsg);
            } else
                throw new IOException("receiver must be of type XMPPID or XMPPRoomID");
        } catch (final XMPPException e) {
            final IOException result = new IOException("XMPPException in sendMessage: " + e.getMessage());
            result.setStackTrace(e.getStackTrace());
            throw result;
        }
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) Chat(org.jivesoftware.smack.Chat) MessageListener(org.jivesoftware.smack.MessageListener) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) IOException(java.io.IOException) XMPPException(org.jivesoftware.smack.XMPPException) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID)

Aggregations

XMPPRoomID (org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID)5 XMPPException (org.jivesoftware.smack.XMPPException)4 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)2 ECFException (org.eclipse.ecf.core.util.ECFException)2 ChatRoomCreateException (org.eclipse.ecf.presence.chatroom.ChatRoomCreateException)2 IChatRoomInfo (org.eclipse.ecf.presence.chatroom.IChatRoomInfo)2 XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)2 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)2 RoomInfo (org.jivesoftware.smackx.muc.RoomInfo)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1 ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)1 ContainerConnectedEvent (org.eclipse.ecf.core.events.ContainerConnectedEvent)1 ContainerConnectingEvent (org.eclipse.ecf.core.events.ContainerConnectingEvent)1 ID (org.eclipse.ecf.core.identity.ID)1 Callback (org.eclipse.ecf.core.security.Callback)1