From c7c8e73160914b011ea2a698709f74e5c30990ac Mon Sep 17 00:00:00 2001 From: slewis Date: Thu, 19 Jul 2007 05:49:23 +0000 Subject: Added support for chat room invitation sending and receiving as per bug 197005. --- .../ecf/internal/provider/xmpp/Messages.java | 12 +++ .../provider/xmpp/XMPPChatRoomContainer.java | 94 +++++++++++++--------- .../provider/xmpp/XMPPChatRoomManager.java | 93 ++++++++++++++------- .../ecf/internal/provider/xmpp/messages.properties | 12 +++ 4 files changed, 144 insertions(+), 67 deletions(-) diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/Messages.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/Messages.java index ff69e337c..aa22fd4c2 100644 --- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/Messages.java +++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/Messages.java @@ -15,7 +15,19 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.ecf.internal.provider.xmpp.messages"; //$NON-NLS-1$ + public static String XMPPChatRoomContainer_EXCEPTION_CALLBACKHANDLER; public static String XMPPChatRoomContainer_Exception_Connect_Wrong_Type; + public static String XMPPChatRoomContainer_EXCEPTION_CREATING_ROOM_ID; + public static String XMPPChatRoomContainer_EXCEPTION_JOINING_ROOM; + public static String XMPPChatRoomContainer_EXCEPTION_NOT_CONNECTED; + public static String XMPPChatRoomContainer_EXCEPTION_SEND_MESSAGE; + public static String XMPPChatRoomContainer_EXCEPTION_TARGET_USER_NOT_NULL; + public static String XMPPChatRoomContainer_NAME_CALLBACK_NICK; + public static String XMPPChatRoomManager_EXCEPTION_CONTAINER_DISCONNECTED; + public static String XMPPChatRoomManager_EXCEPTION_CREATING_CHAT_CONTAINER; + public static String XMPPChatRoomManager_EXCEPTION_NO_ROOM_INFO; + public static String XMPPChatRoomManager_EXCEPTION_ROOM_CANNOT_BE_NULL; + public static String XMPPChatRoomManager_ROOM_NOT_FOUND; public static String XMPPContainer_EXCEPTION_ADDING_SHARED_OBJECT; public static String XMPPContainer_EXCEPTION_DESERIALIZED_OBJECT_NULL; public static String XMPPContainer_EXCEPTION_HANDLING_ASYCH_EVENT; diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomContainer.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomContainer.java index 823ea8065..d26caa271 100644 --- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomContainer.java +++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomContainer.java @@ -34,10 +34,10 @@ import org.eclipse.ecf.internal.provider.xmpp.events.MessageEvent; import org.eclipse.ecf.internal.provider.xmpp.events.PresenceEvent; import org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnection; import org.eclipse.ecf.presence.IIMMessageListener; +import org.eclipse.ecf.presence.chatroom.IChatRoomAdminListener; import org.eclipse.ecf.presence.chatroom.IChatRoomContainer; import org.eclipse.ecf.presence.chatroom.IChatRoomMessageSender; import org.eclipse.ecf.presence.chatroom.IChatRoomParticipantListener; -import org.eclipse.ecf.presence.chatroom.IChatRoomAdminListener; import org.eclipse.ecf.presence.im.IChatMessageSender; import org.eclipse.ecf.provider.comm.ConnectionCreateException; import org.eclipse.ecf.provider.comm.ISynchAsynchConnection; @@ -67,13 +67,11 @@ public class XMPPChatRoomContainer extends ClientSOContainer implements .getName() + ".xmppgroupchathandler"; //$NON-NLS-1$ - protected ID containerHelperID; + private ID containerHelperID; - protected XMPPChatRoomContainerHelper containerHelper; + private XMPPChatRoomContainerHelper containerHelper; - protected MultiUserChat multiuserchat; - - protected Namespace usernamespace = null; + private MultiUserChat multiuserchat; public XMPPChatRoomContainer(ISharedObjectContainerConfig config, ECFConnection conn, Namespace usernamespace) @@ -81,13 +79,25 @@ public class XMPPChatRoomContainer extends ClientSOContainer implements super(config); this.connection = conn; this.config = config; - this.usernamespace = usernamespace; this.containerHelperID = IDFactory.getDefault().createStringID( CONTAINER_HELPER_ID); this.containerHelper = new XMPPChatRoomContainerHelper(usernamespace, getXMPPConnection()); } + protected void sendInvitation(ID toUser, String subject, String body) + throws ECFException { + if (toUser == null) + throw new ECFException( + Messages.XMPPChatRoomContainer_EXCEPTION_TARGET_USER_NOT_NULL); + synchronized (getConnectLock()) { + if (multiuserchat == null) + throw new ContainerConnectException( + Messages.XMPPChatRoomContainer_EXCEPTION_NOT_CONNECTED); + multiuserchat.invite(toUser.getName(), (body == null) ? "" : body); //$NON-NLS-1$ + } + } + public XMPPChatRoomContainer(ECFConnection conn, Namespace usernamespace) throws IDCreateException { this(new SOContainerConfig(IDFactory.getDefault().createGUID()), conn, @@ -233,8 +243,9 @@ public class XMPPChatRoomContainer extends ClientSOContainer implements String nick = null; try { Callback[] callbacks = new Callback[1]; - callbacks[0] = new NameCallback("Nickname", roomID - .getNickname()); + callbacks[0] = new NameCallback( + Messages.XMPPChatRoomContainer_NAME_CALLBACK_NICK, + roomID.getNickname()); if (connectContext != null) { CallbackHandler handler = connectContext .getCallbackHandler(); @@ -248,11 +259,11 @@ public class XMPPChatRoomContainer extends ClientSOContainer implements } } catch (Exception e) { throw new ContainerConnectException( - "Exception in CallbackHandler.handle()", + Messages.XMPPChatRoomContainer_EXCEPTION_CALLBACKHANDLER, e); } String nickname = null; - if (nick == null || nick.equals("")) + if (nick == null || nick.equals("")) //$NON-NLS-1$ nickname = roomID.getNickname(); else nickname = nick; @@ -279,83 +290,83 @@ public class XMPPChatRoomContainer extends ClientSOContainer implements public void voiceGranted(String arg0) { // TODO Auto-generated method stub System.out - .println("voiceGranted(" + arg0 + ")"); + .println("voiceGranted(" + arg0 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } public void voiceRevoked(String arg0) { // TODO Auto-generated method stub System.out - .println("voiceRevoked(" + arg0 + ")"); + .println("voiceRevoked(" + arg0 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } public void membershipGranted(String arg0) { // TODO Auto-generated method stub - System.out.println("membershipGranted(" + arg0 - + ")"); + System.out.println("membershipGranted(" + arg0 //$NON-NLS-1$ + + ")"); //$NON-NLS-1$ } public void membershipRevoked(String arg0) { // TODO Auto-generated method stub - System.out.println("membershipRevoked(" + arg0 - + ")"); + System.out.println("membershipRevoked(" + arg0 //$NON-NLS-1$ + + ")"); //$NON-NLS-1$ } public void moderatorGranted(String arg0) { // TODO Auto-generated method stub - System.out.println("moderatorGranted(" + arg0 - + ")"); + System.out.println("moderatorGranted(" + arg0 //$NON-NLS-1$ + + ")"); //$NON-NLS-1$ } public void moderatorRevoked(String arg0) { // TODO Auto-generated method stub - System.out.println("moderatorRevoked(" + arg0 - + ")"); + System.out.println("moderatorRevoked(" + arg0 //$NON-NLS-1$ + + ")"); //$NON-NLS-1$ } public void ownershipGranted(String arg0) { // TODO Auto-generated method stub - System.out.println("ownershipGranted(" + arg0 - + ")"); + System.out.println("ownershipGranted(" + arg0 //$NON-NLS-1$ + + ")"); //$NON-NLS-1$ } public void ownershipRevoked(String arg0) { // TODO Auto-generated method stub - System.out.println("ownershipRevoked(" + arg0 - + ")"); + System.out.println("ownershipRevoked(" + arg0 //$NON-NLS-1$ + + ")"); //$NON-NLS-1$ } public void adminGranted(String arg0) { // TODO Auto-generated method stub System.out - .println("adminGranted(" + arg0 + ")"); + .println("adminGranted(" + arg0 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } public void adminRevoked(String arg0) { // TODO Auto-generated method stub System.out - .println("adminRevoked(" + arg0 + ")"); + .println("adminRevoked(" + arg0 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } public void kicked(String arg0, String arg1, String arg2) { // TODO Auto-generated method stub - System.out.println("kicked(" + arg0 + "," - + arg1 + "," + arg2 + ")"); + System.out.println("kicked(" + arg0 + "," //$NON-NLS-1$ //$NON-NLS-2$ + + 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("banned(" + arg0 + "," - + arg1 + "," + arg2 + ")"); + System.out.println("banned(" + arg0 + "," //$NON-NLS-1$ //$NON-NLS-2$ + + arg1 + "," + arg2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } public void nicknameChanged(String arg0, String arg1) { // TODO Auto-generated method stub - System.out.println("nicknameChanged(" + arg0 - + "," + arg1 + ")"); + System.out.println("nicknameChanged(" + arg0 //$NON-NLS-1$ + + "," + arg1 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } }); @@ -364,8 +375,8 @@ public class XMPPChatRoomContainer extends ClientSOContainer implements public void invitationDeclined(String arg0, String arg1) { // TODO Auto-generated method stub - System.out.println("invitationDeclined(" + arg0 - + "," + arg1 + ")"); + System.out.println("invitationDeclined(" + arg0 //$NON-NLS-1$ + + "," + arg1 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } }); multiuserchat.join(nickname); @@ -377,7 +388,7 @@ public class XMPPChatRoomContainer extends ClientSOContainer implements } catch (Exception e) { cleanUpConnectFail(); ContainerConnectException ce = new ContainerConnectException( - "Exception joining " + roomID); + NLS.bind(Messages.XMPPChatRoomContainer_EXCEPTION_JOINING_ROOM, roomID)); ce.setStackTrace(e.getStackTrace()); throw ce; } @@ -394,12 +405,13 @@ public class XMPPChatRoomContainer extends ClientSOContainer implements try { multiuserchat.leave(); } catch (Exception e) { - traceStack("Exception in multi user chat.leave", e); + traceStack("Exception in multi user chat.leave", e); //$NON-NLS-1$ } } connectionState = DISCONNECTED; remoteServerID = null; - if (containerHelper != null) containerHelper.setRoomID(null); + if (containerHelper != null) + containerHelper.setRoomID(null); this.connection = null; } // notify listeners @@ -442,7 +454,8 @@ public class XMPPChatRoomContainer extends ClientSOContainer implements multiuserchat.sendMessage(messageBody); } catch (Exception e) { ECFException except = new ECFException( - "Send message exception", e); + Messages.XMPPChatRoomContainer_EXCEPTION_SEND_MESSAGE, + e); throw except; } } @@ -456,7 +469,8 @@ public class XMPPChatRoomContainer extends ClientSOContainer implements targetID = createChatRoomID(groupName); } catch (IDCreateException e) { throw new ContainerConnectException( - "Exception creating chat room id", e); + Messages.XMPPChatRoomContainer_EXCEPTION_CREATING_ROOM_ID, + e); } this.connect(targetID, null); } diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomManager.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomManager.java index 1058ea42f..e7bab2f32 100644 --- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomManager.java +++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/XMPPChatRoomManager.java @@ -22,6 +22,7 @@ import org.eclipse.ecf.core.ContainerCreateException; import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.identity.IDCreateException; import org.eclipse.ecf.core.identity.Namespace; +import org.eclipse.ecf.core.util.ECFException; import org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnection; import org.eclipse.ecf.presence.chatroom.ChatRoomCreateException; import org.eclipse.ecf.presence.chatroom.IChatRoomContainer; @@ -33,6 +34,7 @@ import org.eclipse.ecf.presence.history.IHistory; import org.eclipse.ecf.presence.history.IHistoryManager; import org.eclipse.ecf.provider.xmpp.identity.XMPPID; import org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID; +import org.eclipse.osgi.util.NLS; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Message; @@ -46,14 +48,11 @@ import org.jivesoftware.smackx.packet.DiscoverItems; public class XMPPChatRoomManager implements IChatRoomManager { - /** - * - */ - private static final String PROP_XMPP_SUBJECT = "subject"; + private static final String PROP_XMPP_SUBJECT = "subject"; //$NON-NLS-1$ // key in the create room configuration in order to find the please to find // the conference rooms on the XMPP server - public static final String PROP_XMPP_CONFERENCE = "conference"; + public static final String PROP_XMPP_CONFERENCE = "conference"; //$NON-NLS-1$ ID containerID = null; @@ -67,18 +66,57 @@ public class XMPPChatRoomManager implements IChatRoomManager { ID connectedID = null; + IChatRoomInvitationSender invitationSender = new IChatRoomInvitationSender() { + + public void sendInvitation(ID room, ID targetUser, String subject, + String body) throws ECFException { + XMPPChatRoomManager.this.sendInvitation(room, targetUser, subject, + body); + } + + }; + public XMPPChatRoomManager(ID containerID) { this.containerID = containerID; } - protected void addChat(IChatRoomContainer container) { + /** + * @param room + * @param targetUser + * @param subject + * @param body + */ + protected void sendInvitation(ID room, ID targetUser, String subject, + String body) throws ECFException { + XMPPChatRoomContainer chatRoomContainer = getChatRoomContainer(room); + if (chatRoomContainer == null) + throw new ECFException(NLS + .bind(Messages.XMPPChatRoomManager_ROOM_NOT_FOUND, room.getName())); + chatRoomContainer.sendInvitation(targetUser, subject, body); + } + + protected void addChat(XMPPChatRoomContainer container) { chatrooms.add(container); } - protected void removeChat(IChatRoomContainer container) { + protected void removeChat(XMPPChatRoomContainer container) { chatrooms.remove(container); } + protected XMPPChatRoomContainer getChatRoomContainer(ID roomID) { + if (roomID == null) + return null; + for (Iterator i = chatrooms.iterator(); i.hasNext();) { + XMPPChatRoomContainer container = (XMPPChatRoomContainer) i.next(); + ID containerRoomID = container.getConnectedID(); + if (containerRoomID == null) + continue; + if (containerRoomID.equals(roomID)) + return container; + } + return null; + } + protected ID createRoomIDFromName(String from) { try { return new XMPPRoomID(connectNamespace, ecfConnection @@ -193,9 +231,9 @@ public class XMPPChatRoomManager implements IChatRoomManager { public IChatRoomContainer createChatRoomContainer() throws ContainerCreateException { - IChatRoomContainer chatContainer = null; + XMPPChatRoomContainer chatContainer = null; if (ecfConnection == null) - throw new ContainerCreateException("disconnected"); + throw new ContainerCreateException(Messages.XMPPChatRoomManager_EXCEPTION_CONTAINER_DISCONNECTED); try { chatContainer = new XMPPChatRoomContainer(ecfConnection, connectNamespace); @@ -203,20 +241,20 @@ public class XMPPChatRoomManager implements IChatRoomManager { return chatContainer; } catch (IDCreateException e) { throw new ContainerCreateException( - "Exception creating chat container", e); + Messages.XMPPChatRoomManager_EXCEPTION_CREATING_CHAT_CONTAINER, e); } } public String toString() { - StringBuffer buf = new StringBuffer("ECFRoomInfo["); - buf.append("id=").append(containerID).append(";name=" + getName()); - buf.append(";service=" + getConnectedID()); - buf.append(";count=" + getParticipantsCount()); - buf.append(";subject=" + getSubject()).append( - ";desc=" + getDescription()); - buf.append(";pers=" + isPersistent()).append( - ";pw=" + requiresPassword()); - buf.append(";mod=" + isModerated()).append("]"); + StringBuffer buf = new StringBuffer("ECFRoomInfo["); //$NON-NLS-1$ + buf.append("id=").append(containerID).append(";name=" + getName()); //$NON-NLS-1$ //$NON-NLS-2$ + buf.append(";service=" + getConnectedID()); //$NON-NLS-1$ + buf.append(";count=" + getParticipantsCount()); //$NON-NLS-1$ + buf.append(";subject=" + getSubject()).append( //$NON-NLS-1$ + ";desc=" + getDescription()); //$NON-NLS-1$ + buf.append(";pers=" + isPersistent()).append( //$NON-NLS-1$ + ";pw=" + requiresPassword()); //$NON-NLS-1$ + buf.append(";mod=" + isModerated()).append("]"); //$NON-NLS-1$ //$NON-NLS-2$ return buf.toString(); } } @@ -372,7 +410,7 @@ public class XMPPChatRoomManager implements IChatRoomManager { throws ChatRoomCreateException { if (roomname == null) throw new ChatRoomCreateException(roomname, - "roomname cannot be null"); + Messages.XMPPChatRoomManager_EXCEPTION_ROOM_CANNOT_BE_NULL); try { String nickname = ecfConnection.getXMPPConnection().getUser(); String server = ecfConnection.getXMPPConnection().getHost(); @@ -407,7 +445,7 @@ public class XMPPChatRoomManager implements IChatRoomManager { ecfConnection.getXMPPConnection(), roomID, longname); return new ECFRoomInfo(xid, info, connectedID); } else - throw new XMPPException("No room info for " + roomID); + throw new XMPPException(NLS.bind(Messages.XMPPChatRoomManager_EXCEPTION_NO_ROOM_INFO,roomID)); } catch (XMPPException e) { throw new ChatRoomCreateException(roomname, e.getMessage(), e); } catch (URISyntaxException e) { @@ -455,25 +493,26 @@ public class XMPPChatRoomManager implements IChatRoomManager { public void setActive(boolean active) { // TODO Auto-generated method stub - + } public Object getAdapter(Class adapter) { // TODO Auto-generated method stub return null; } - + }; - + public IHistoryManager getHistoryManager() { return chatRoomHistoryManager; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ecf.presence.chatroom.IChatRoomManager#getInvitationSender() */ public IChatRoomInvitationSender getInvitationSender() { - // TODO Auto-generated method stub - return null; + return invitationSender; } } diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/messages.properties b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/messages.properties index 67d5013d4..473cd81c3 100644 --- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/messages.properties +++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/internal/provider/xmpp/messages.properties @@ -1,6 +1,18 @@ XMPPChatRoomContainer_Exception_Connect_Wrong_Type=remote {0} is not of room id type +XMPPChatRoomContainer_EXCEPTION_TARGET_USER_NOT_NULL=target user cannot be null +XMPPChatRoomContainer_EXCEPTION_NOT_CONNECTED=not connected +XMPPChatRoomContainer_NAME_CALLBACK_NICK=Nickname +XMPPChatRoomContainer_EXCEPTION_CALLBACKHANDLER=Exception in CallbackHandler.handle() +XMPPChatRoomContainer_EXCEPTION_SEND_MESSAGE=Send message exception +XMPPChatRoomContainer_EXCEPTION_JOINING_ROOM=Exception joining %1 +XMPPChatRoomContainer_EXCEPTION_CREATING_ROOM_ID=Exception creating chat room id +XMPPChatRoomManager_EXCEPTION_CONTAINER_DISCONNECTED=container disconnected +XMPPChatRoomManager_EXCEPTION_CREATING_CHAT_CONTAINER=Exception creating chat container +XMPPChatRoomManager_EXCEPTION_ROOM_CANNOT_BE_NULL=roomname cannot be null +XMPPChatRoomManager_EXCEPTION_NO_ROOM_INFO=No room info for XMPPIncomingFileTransfer_Progress_Data=\ - data XMPPContainer_UNEXPECTED_XMPP_MESSAGE=handleXMPPMessage got unexpected packet %1 +XMPPChatRoomManager_ROOM_NOT_FOUND=room %1 not found XMPPIncomingFileTransfer_Exception_User_Cancelled=Cancelled by user XMPPContainer_EXCEPTION_DESERIALIZED_OBJECT_NULL=deserialized object is null XMPPIncomingFileTransfer_Status_Transfer_Completed_OK=Transfer Completed OK -- cgit v1.2.3