Lines 8-13
Link Here
|
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* Composent, Inc. - initial API and implementation |
9 |
* Composent, Inc. - initial API and implementation |
10 |
* Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197329 |
10 |
* Jacek Pospychala <jacek.pospychala@pl.ibm.com> - bug 197329 |
|
|
11 |
* Cagatay Calli <ccalli@gmail.com> - https://bugs.eclipse.org/bugs/show_bug.cgi?id=192757 |
11 |
*****************************************************************************/ |
12 |
*****************************************************************************/ |
12 |
|
13 |
|
13 |
package org.eclipse.ecf.internal.irc.ui; |
14 |
package org.eclipse.ecf.internal.irc.ui; |
Lines 16-28
Link Here
|
16 |
import java.net.URISyntaxException; |
17 |
import java.net.URISyntaxException; |
17 |
import java.util.StringTokenizer; |
18 |
import java.util.StringTokenizer; |
18 |
|
19 |
|
|
|
20 |
import org.eclipse.ecf.core.ContainerFactory; |
19 |
import org.eclipse.ecf.core.IContainer; |
21 |
import org.eclipse.ecf.core.IContainer; |
20 |
import org.eclipse.ecf.core.identity.ID; |
22 |
import org.eclipse.ecf.core.identity.ID; |
|
|
23 |
import org.eclipse.ecf.core.identity.IDFactory; |
24 |
import org.eclipse.ecf.core.security.ConnectContextFactory; |
25 |
import org.eclipse.ecf.core.security.IConnectContext; |
21 |
import org.eclipse.ecf.core.util.IExceptionHandler; |
26 |
import org.eclipse.ecf.core.util.IExceptionHandler; |
22 |
import org.eclipse.ecf.presence.chatroom.IChatRoomContainer; |
27 |
import org.eclipse.ecf.presence.chatroom.IChatRoomContainer; |
23 |
import org.eclipse.ecf.presence.chatroom.IChatRoomManager; |
28 |
import org.eclipse.ecf.presence.chatroom.IChatRoomManager; |
24 |
import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerUI; |
29 |
import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerUI; |
25 |
import org.eclipse.ecf.presence.ui.chatroom.IMessageRenderer; |
30 |
import org.eclipse.ecf.presence.ui.chatroom.IMessageRenderer; |
|
|
31 |
import org.eclipse.ecf.ui.actions.AsynchContainerConnectAction; |
32 |
import org.eclipse.ecf.ui.util.PasswordCacheHelper; |
26 |
import org.eclipse.jface.dialogs.MessageDialog; |
33 |
import org.eclipse.jface.dialogs.MessageDialog; |
27 |
import org.eclipse.osgi.util.NLS; |
34 |
import org.eclipse.osgi.util.NLS; |
28 |
|
35 |
|
Lines 36-41
Link Here
|
36 |
private static final String COMMAND_PREFIX = "/"; //$NON-NLS-1$ |
43 |
private static final String COMMAND_PREFIX = "/"; //$NON-NLS-1$ |
37 |
|
44 |
|
38 |
private static final String COMMAND_DELIM = " "; //$NON-NLS-1$ |
45 |
private static final String COMMAND_DELIM = " "; //$NON-NLS-1$ |
|
|
46 |
|
47 |
String connectID; |
48 |
String password; |
39 |
|
49 |
|
40 |
/** |
50 |
/** |
41 |
* @param container |
51 |
* @param container |
Lines 80-86
Link Here
|
80 |
* @see org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerUI#handleCommand(java.lang.String) |
90 |
* @see org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerUI#handleCommand(java.lang.String) |
81 |
*/ |
91 |
*/ |
82 |
public String handleCommand(IChatRoomContainer chatRoomContainer, |
92 |
public String handleCommand(IChatRoomContainer chatRoomContainer, |
83 |
String inputLine) { |
93 |
String username, String inputLine) { |
84 |
if ((inputLine != null && inputLine.startsWith(COMMAND_PREFIX))) { |
94 |
if ((inputLine != null && inputLine.startsWith(COMMAND_PREFIX))) { |
85 |
StringTokenizer st = new StringTokenizer(inputLine, COMMAND_DELIM); |
95 |
StringTokenizer st = new StringTokenizer(inputLine, COMMAND_DELIM); |
86 |
int countTokens = st.countTokens(); |
96 |
int countTokens = st.countTokens(); |
Lines 91-101
Link Here
|
91 |
while (command.startsWith(COMMAND_PREFIX)) |
101 |
while (command.startsWith(COMMAND_PREFIX)) |
92 |
command = command.substring(1); |
102 |
command = command.substring(1); |
93 |
// Look at first one and switch |
103 |
// Look at first one and switch |
94 |
String[] args = new String[tokens.length - 1]; |
104 |
final String[] args = new String[tokens.length - 1]; |
95 |
System.arraycopy(tokens, 1, args, 0, tokens.length - 1); |
105 |
System.arraycopy(tokens, 1, args, 0, tokens.length - 1); |
|
|
106 |
|
107 |
// SERVER can be done from root or channel |
108 |
if (command.equalsIgnoreCase(Messages.IRCUI_SERVER_COMMAND)) { |
109 |
int size = args.length; |
110 |
for(int i=0;i<size;i++){ |
111 |
if(i==0){ |
112 |
connectID = getConnectID(args[i]); |
113 |
} |
114 |
else if(i==1){ |
115 |
password = args[i]; |
116 |
} |
117 |
} |
118 |
|
119 |
if(connectID.indexOf("@") == -1){ |
120 |
String nick = username; |
121 |
connectID = nick + "@" + connectID; |
122 |
} |
123 |
|
124 |
try { |
125 |
IContainer container = ContainerFactory.getDefault() |
126 |
.createContainer(Messages.IRCUI_ECF_IRC_CONTAINER_NAME); |
127 |
|
128 |
IConnectContext connectContext = ConnectContextFactory |
129 |
.createPasswordConnectContext(connectID); |
130 |
|
131 |
targetID = IDFactory.getDefault().createID( |
132 |
container.getConnectNamespace(), connectID); |
133 |
|
134 |
IChatRoomManager manager = (IChatRoomManager) container |
135 |
.getAdapter(IChatRoomManager.class); |
136 |
|
137 |
IRCUI ui = new IRCUI(container, manager, null); |
138 |
ui.showForTarget(targetID); |
139 |
// If it's not already connected, then we connect this new container |
140 |
if (!ui.isContainerConnected()) { |
141 |
new AsynchContainerConnectAction(container, targetID, connectContext, null, new Runnable() { |
142 |
public void run() { |
143 |
cachePassword(getPasswordKeyFromUserName(connectID), password); |
144 |
}}).run(); |
145 |
} |
146 |
} catch (Exception e) { |
147 |
e.printStackTrace(); |
148 |
} |
149 |
|
150 |
return null; |
151 |
} |
96 |
// JOIN can be done from root or channel |
152 |
// JOIN can be done from root or channel |
97 |
if (command.equalsIgnoreCase(Messages.IRCUI_JOIN_COMMAND)) { |
153 |
if (command.equalsIgnoreCase(Messages.IRCUI_JOIN_COMMAND)) { |
98 |
chatroomview.joinRoom(manager.getChatRoomInfo(args[0]), (args.length > 1)?args[1]:""); |
154 |
chatroomview.joinRoom(manager.getChatRoomInfo(args[0]), (args.length > 1)?args[1]:""); //$NON-NLS-1$ |
99 |
return null; |
155 |
return null; |
100 |
} |
156 |
} |
101 |
// QUIT can be done from root or channel |
157 |
// QUIT can be done from root or channel |
Lines 122-129
Link Here
|
122 |
return inputLine; |
178 |
return inputLine; |
123 |
|
179 |
|
124 |
} |
180 |
} |
125 |
|
181 |
|
126 |
protected IMessageRenderer getDefaultMessageRenderer() { |
182 |
protected IMessageRenderer getDefaultMessageRenderer() { |
127 |
return new IRCMessageRenderer(); |
183 |
return new IRCMessageRenderer(); |
128 |
} |
184 |
} |
|
|
185 |
|
186 |
// TODO Share these methods from a common class between IRCConnectWizardPage and IRCUI |
187 |
String getConnectID(String connectText) { |
188 |
String clean = connectText.replaceAll("#",""); |
189 |
return clean; |
190 |
} |
191 |
|
192 |
String getPasswordKeyFromUserName(String username) { |
193 |
if (username == null || username.equals("")) return null; |
194 |
else { |
195 |
int slashIndex = username.indexOf("/"); |
196 |
if (slashIndex == -1) return username; |
197 |
else return username.substring(0,username.indexOf("/")); |
198 |
} |
199 |
} |
200 |
|
201 |
protected void cachePassword(final String connectID, String password) { |
202 |
if (password != null && !password.equals("")) { |
203 |
PasswordCacheHelper pwStorage = new PasswordCacheHelper(connectID); |
204 |
pwStorage.savePassword(password); |
205 |
} |
206 |
} |
129 |
} |
207 |
} |