1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
|
package net.java.sip.communicator.plugin.jabberaccregwizz;
import java.awt.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
import net.java.sip.communicator.service.credentialsstorage.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.swing.*;
/**
* The <tt>JabberAccountRegistrationForm</tt>.
*
* @author Yana Stamcheva
*/
public class JabberAccountRegistrationForm
extends TransparentPanel
{
/**
* Serial version UID.
*/
private static final long serialVersionUID = 0L;
private final AccountPanel accountPanel;
private final ConnectionPanel connectionPanel;
private final IceConfigPanel iceConfigPanel;
private final TelephonyConfigPanel telephonyConfigPanel;
private boolean isModification;
private final JabberAccountRegistrationWizard wizard;
private final JTabbedPane tabbedPane = new SIPCommTabbedPane();
/**
* The panels which value needs validation before we continue.
*/
private List<ValidatingPanel> validatingPanels =
new ArrayList<ValidatingPanel>();
/**
* Creates an instance of <tt>JabberAccountRegistrationForm</tt>.
* @param wizard the parent wizard
*/
public JabberAccountRegistrationForm(JabberAccountRegistrationWizard wizard)
{
super(new BorderLayout());
this.wizard = wizard;
accountPanel = new AccountPanel(this);
connectionPanel = new ConnectionPanel(this);
iceConfigPanel = new IceConfigPanel();
telephonyConfigPanel = new TelephonyConfigPanel();
}
/**
* Initializes all panels, buttons, etc.
*/
void init()
{
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JabberAccountCreationFormService createService =
getCreateAccountService();
if (createService != null)
createService.clear();
if (!JabberAccRegWizzActivator.isAdvancedAccountConfigDisabled())
{
// Indicate that this panel is opened in a simple form.
accountPanel.setSimpleForm(false);
if (accountPanel.getParent() != tabbedPane)
tabbedPane.addTab( Resources.getString("service.gui.ACCOUNT"),
accountPanel);
if (connectionPanel.getParent() != tabbedPane)
tabbedPane.addTab(Resources.getString("service.gui.CONNECTION"),
connectionPanel);
if (iceConfigPanel.getParent() != tabbedPane)
tabbedPane.addTab(Resources.getString("service.gui.ICE"),
iceConfigPanel);
if (telephonyConfigPanel.getParent() != tabbedPane)
tabbedPane.addTab(Resources.getString("service.gui.TELEPHONY"),
telephonyConfigPanel);
if (tabbedPane.getParent() != this)
this.add(tabbedPane, BorderLayout.NORTH);
tabbedPane.setSelectedIndex(0);
}
else
add(accountPanel, BorderLayout.NORTH);
}
/**
* Parse the server part from the jabber id and set it to server as default
* value. If Advanced option is enabled Do nothing.
* @param userName the account user name
*/
void setServerFieldAccordingToUIN(String userName)
{
if (!wizard.isModification()
&& !wizard.getRegistration().isServerOverridden())
{
connectionPanel.setServerAddress(getServerFromUserName(userName));
}
}
/**
* Enables/disables the next/finish button of the parent wizard.
* @param isEnabled <tt>true</tt> to enable the next button, <tt>false</tt>
* otherwise
*/
private void setNextFinishButtonEnabled(boolean isEnabled)
{
JabberAccRegWizzActivator.getUIService().getAccountRegWizardContainer()
.setNextFinishButtonEnabled(isEnabled);
}
/**
* Call this to trigger revalidation of all the input values
* and change the state of next/finish button.
*/
void reValidateInput()
{
for(ValidatingPanel panel : validatingPanels)
{
if(!panel.isValidated())
{
setNextFinishButtonEnabled(false);
return;
}
}
setNextFinishButtonEnabled(true);
}
/**
* Adds panel to the list of panels with values which need validation.
* @param panel ValidatingPanel.
*/
public void addValidatingPanel(ValidatingPanel panel)
{
validatingPanels.add(panel);
}
/**
* Return the server part of the jabber user name.
*
* @param userName the username.
* @return the server part of the jabber user name.
*/
static String getServerFromUserName(String userName)
{
int delimIndex = userName.indexOf("@");
if (delimIndex != -1)
{
return userName.substring(delimIndex + 1);
}
return null;
}
/**
* Return the user part of the user name (i.e. the string before the @
* sign).
*
* @param userName the username.
* @return the user part of the jabber user name.
*/
public static String getUserFromUserName(String userName)
{
int delimIndex = userName.indexOf("@");
if (delimIndex != -1)
{
return userName.substring(0, delimIndex);
}
return userName;
}
/**
* Returns the server address.
*
* @return the server address
*/
String getServerAddress()
{
return wizard.getRegistration().getServerAddress();
}
/**
* Indicates if this wizard is modifying an existing account or is creating
* a new one.
*
* @return <code>true</code> to indicate that this wizard is currently in
* modification mode, <code>false</code> - otherwise.
*/
public boolean isModification()
{
return isModification;
}
/**
* Saves the user input when the "Next" wizard buttons is clicked.
*
* @param registration the JabberAccountRegistration
* @return <tt>true</tt> if the page is correctly committed
*/
public boolean commitPage(JabberAccountRegistration registration)
{
String userID = null;
char[] password = null;
String serverAddress = null;
String serverPort = null;
if (accountPanel.isCreateAccount())
{
NewAccount newAccount
= getCreateAccountService().createAccount();
if (newAccount != null)
{
userID = newAccount.getUserName();
password = newAccount.getPassword();
serverAddress = newAccount.getServerAddress();
serverPort = newAccount.getServerPort();
if (serverAddress == null)
setServerFieldAccordingToUIN(userID);
}
else
{
// If we didn't succeed to create our new account, we have
// nothing more to do here.
return false;
}
}
else
{
userID = accountPanel.getUsername();
if(userID == null || userID.trim().length() == 0)
throw new IllegalStateException("No user ID provided.");
if(userID.indexOf('@') < 0
&& registration.getDefaultUserSufix() != null)
userID = userID + '@' + registration.getDefaultUserSufix();
password = accountPanel.getPassword();
serverAddress = connectionPanel.getServerAddress();
serverPort = connectionPanel.getServerPort();
}
registration.setUserID(userID);
registration.setPassword(new String(password));
registration.setRememberPassword(accountPanel.isRememberPassword());
registration.setServerAddress(serverAddress);
registration.setSendKeepAlive(connectionPanel.isSendKeepAlive());
registration.setGmailNotificationEnabled(
connectionPanel.isGmailNotificationsEnabled());
registration.setGoogleContactsEnabled(
connectionPanel.isGoogleContactsEnabled());
registration.setResourceAutogenerated(
connectionPanel.isAutogenerateResourceEnabled());
registration.setResource(connectionPanel.getResource());
if (serverPort != null)
registration.setPort(Integer.parseInt(serverPort));
String priority = connectionPanel.getPriority();
if (priority != null)
registration.setPriority(Integer.parseInt(priority));
registration.setUseIce(iceConfigPanel.isUseIce());
registration.setUseGoogleIce(iceConfigPanel.isUseGoogleIce());
registration.setAutoDiscoverStun(iceConfigPanel.isAutoDiscoverStun());
registration.setUseDefaultStunServer(
iceConfigPanel.isUseDefaultStunServer());
//we will be reentering all stun servers so let's make sure we clear
//the servers vector in case we already did that with a "Next".
registration.getAdditionalStunServers().clear();
List<StunServerDescriptor> stunServers
= iceConfigPanel.getAdditionalStunServers();
for (StunServerDescriptor descriptor : stunServers)
registration.addStunServer(descriptor);
registration.setUseJingleNodes(iceConfigPanel.isUseJingleNodes());
registration.setAutoDiscoverJingleNodes(
iceConfigPanel.isAutoDiscoverJingleNodes());
//we will be reentering all Jingle nodes so let's make sure we clear
//the servers vector in case we already did that with a "Next".
registration.getAdditionalJingleNodes().clear();
List<JingleNodeDescriptor> jingleNodes
= iceConfigPanel.getAdditionalJingleNodes();
for (JingleNodeDescriptor descriptor : jingleNodes)
registration.addJingleNodes(descriptor);
registration.setUseUPNP(iceConfigPanel.isUseUPNP());
registration.setTelephonyDomainBypassCaps(
telephonyConfigPanel.getTelephonyDomainBypassCaps());
registration.setOverridePhoneSufix(
telephonyConfigPanel.getTelephonyDomain());
return true;
}
/**
* Loads the account with the given identifier.
* @param accountID the account identifier
*/
public void loadAccount(AccountID accountID)
{
Map<String, String> accountProperties
= accountID.getAccountProperties();
String password
= JabberAccRegWizzActivator.getJabberProtocolProviderFactory()
.loadPassword(accountID);
accountPanel.setRememberPassword(false);
accountPanel.setUsername(accountID.getUserID());
if (password != null)
{
accountPanel.setPassword(password);
accountPanel.setRememberPassword(true);
}
String serverAddress
= accountProperties.get(ProtocolProviderFactory.SERVER_ADDRESS);
connectionPanel.setServerAddress(serverAddress);
String serverPort
= accountProperties.get(ProtocolProviderFactory.SERVER_PORT);
connectionPanel.setServerPort(serverPort);
boolean keepAlive
= Boolean.parseBoolean(accountProperties.get("SEND_KEEP_ALIVE"));
connectionPanel.setSendKeepAlive(keepAlive);
boolean gmailNotificationEnabled
= Boolean.parseBoolean(
accountProperties.get("GMAIL_NOTIFICATIONS_ENABLED"));
connectionPanel.setGmailNotificationsEnabled(gmailNotificationEnabled);
String useGC = accountProperties.get("GOOGLE_CONTACTS_ENABLED");
boolean googleContactsEnabled = Boolean.parseBoolean(
(useGC != null && useGC.length() != 0) ? useGC : "true");
connectionPanel.setGoogleContactsEnabled(googleContactsEnabled);
String resource
= accountProperties.get(ProtocolProviderFactory.RESOURCE);
connectionPanel.setResource(resource);
String autoGenerateResourceValue = accountProperties.get(
ProtocolProviderFactory.AUTO_GENERATE_RESOURCE);
boolean autoGenerateResource =
JabberAccountRegistration.DEFAULT_RESOURCE_AUTOGEN;
if(autoGenerateResourceValue != null)
autoGenerateResource = Boolean.parseBoolean(
autoGenerateResourceValue);
connectionPanel.setAutogenerateResource(autoGenerateResource);
String priority
= accountProperties.get(ProtocolProviderFactory.RESOURCE_PRIORITY);
connectionPanel.setPriority(priority);
String useIce =
accountProperties.get(ProtocolProviderFactory.IS_USE_ICE);
boolean isUseIce = Boolean.parseBoolean(
(useIce != null && useIce.length() != 0) ? useIce : "true");
iceConfigPanel.setUseIce(isUseIce);
String useGoogleIce =
accountProperties.get(ProtocolProviderFactory.IS_USE_GOOGLE_ICE);
boolean isUseGoogleIce = Boolean.parseBoolean(
(useGoogleIce != null && useGoogleIce.length() != 0) ?
useGoogleIce : "false");
iceConfigPanel.setUseGoogleIce(isUseGoogleIce);
String useAutoDiscoverStun
= accountProperties.get(
ProtocolProviderFactory.AUTO_DISCOVER_STUN);
boolean isUseAutoDiscoverStun = Boolean.parseBoolean(
(useAutoDiscoverStun != null &&
useAutoDiscoverStun.length() != 0) ?
useAutoDiscoverStun : "true");
iceConfigPanel.setAutoDiscoverStun(isUseAutoDiscoverStun);
String useDefaultStun
= accountProperties.get(
ProtocolProviderFactory.USE_DEFAULT_STUN_SERVER);
boolean isUseDefaultStun = Boolean.parseBoolean(
(useDefaultStun != null &&
useDefaultStun.length() != 0) ?
useDefaultStun : "true");
iceConfigPanel.setUseDefaultStunServer(isUseDefaultStun);
iceConfigPanel.removeAllStunServer();
for (int i = 0; i < StunServerDescriptor.MAX_STUN_SERVER_COUNT; i ++)
{
StunServerDescriptor stunServer
= StunServerDescriptor.loadDescriptor(
accountProperties, ProtocolProviderFactory.STUN_PREFIX + i);
// If we don't find a stun server with the given index, it means
// that there're no more servers left in the table so we've nothing
// more to do here.
if (stunServer == null)
break;
String stunPassword = loadStunPassword(accountID,
ProtocolProviderFactory.STUN_PREFIX + i);
if(stunPassword != null)
{
stunServer.setPassword(stunPassword);
}
iceConfigPanel.addStunServer(stunServer);
}
String useJN =
accountProperties.get(ProtocolProviderFactory.IS_USE_JINGLE_NODES);
boolean isUseJN = Boolean.parseBoolean(
(useJN != null && useJN.length() != 0) ? useJN : "true");
iceConfigPanel.setUseJingleNodes(isUseJN);
String useAutoDiscoverJN
= accountProperties.get(
ProtocolProviderFactory.AUTO_DISCOVER_JINGLE_NODES);
boolean isUseAutoDiscoverJN = Boolean.parseBoolean(
(useAutoDiscoverJN != null &&
useAutoDiscoverJN.length() != 0) ?
useAutoDiscoverJN : "true");
iceConfigPanel.setAutoDiscoverJingleNodes(isUseAutoDiscoverJN);
iceConfigPanel.removeAllJingleNodes();
for (int i = 0; i < JingleNodeDescriptor.MAX_JN_RELAY_COUNT ; i ++)
{
JingleNodeDescriptor jn
= JingleNodeDescriptor.loadDescriptor(
accountProperties, JingleNodeDescriptor.JN_PREFIX + i);
// If we don't find a stun server with the given index, it means
// that there're no more servers left in the table so we've nothing
// more to do here.
if (jn == null)
break;
iceConfigPanel.addJingleNodes(jn);
}
String useUPNP =
accountProperties.get(ProtocolProviderFactory.IS_USE_UPNP);
boolean isUseUPNP = Boolean.parseBoolean(
(useUPNP != null && useUPNP.length() != 0) ? useUPNP : "true");
iceConfigPanel.setUseUPNP(isUseUPNP);
wizard.getRegistration().setServerOverridden(
accountID.getAccountPropertyBoolean(
ProtocolProviderFactory.IS_SERVER_OVERRIDDEN,
false));
String telephonyDomain = accountProperties.get("OVERRIDE_PHONE_SUFFIX");
telephonyConfigPanel.setTelephonyDomain(telephonyDomain);
String bypassCapsDomain = accountProperties.get(
"TELEPHONY_BYPASS_GTALK_CAPS");
telephonyConfigPanel.setTelephonyDomainBypassCaps(bypassCapsDomain);
}
/**
* Returns a simple version of this registration form.
* @return the simple form component
*/
public Component getSimpleForm()
{
JabberAccountCreationFormService createAccountService
= getCreateAccountService();
if (createAccountService != null)
createAccountService.clear();
// Indicate that this panel is opened in a simple form.
accountPanel.setSimpleForm(true);
return accountPanel;
}
/**
* Sets the isModification property.
* @param isModification indicates if this form is created for modification
*/
public void setModification(boolean isModification)
{
this.isModification = isModification;
}
/**
* Returns the username example.
* @return the username example string
*/
public String getUsernameExample()
{
return wizard.getUserNameExample();
}
/**
* Sign ups through the web.
*/
public void webSignup()
{
wizard.webSignup();
}
/**
* Returns <code>true</code> if the web sign up is supported by the current
* implementation, <code>false</code> - otherwise.
* @return <code>true</code> if the web sign up is supported by the current
* implementation, <code>false</code> - otherwise
*/
public boolean isWebSignupSupported()
{
return wizard.isWebSignupSupported();
}
/**
* Returns an instance of <tt>CreateAccountService</tt> through which the
* user could create an account. This method is meant to be implemented by
* specific protocol provider wizards.
* @return an instance of <tt>CreateAccountService</tt>
*/
public JabberAccountCreationFormService getCreateAccountService()
{
return wizard.getCreateAccountService();
}
/**
* Returns the display label used for the jabber id field.
* @return the jabber id display label string.
*/
protected String getUsernameLabel()
{
return wizard.getUsernameLabel();
}
/**
* Returns the current jabber registration holding all values.
* @return jabber registration.
*/
public JabberAccountRegistration getRegistration()
{
return wizard.getRegistration();
}
/**
* Return the string for add existing account button.
* @return the string for add existing account button.
*/
protected String getCreateAccountButtonLabel()
{
return wizard.getCreateAccountButtonLabel();
}
/**
* Return the string for create new account button.
* @return the string for create new account button.
*/
protected String getCreateAccountLabel()
{
return wizard.getCreateAccountLabel();
}
/**
* Return the string for add existing account button.
* @return the string for add existing account button.
*/
protected String getExistingAccountLabel()
{
return wizard.getExistingAccountLabel();
}
/**
* Return the string for home page link label.
* @return the string for home page link label
*/
protected String getHomeLinkLabel()
{
return wizard.getHomeLinkLabel();
}
/**
* Load password for this STUN descriptor.
*
* @param accountID account ID
* @param namePrefix name prefix
* @return password or null if empty
*/
private static String loadStunPassword(AccountID accountID,
String namePrefix)
{
ProtocolProviderFactory providerFactory =
JabberAccRegWizzActivator.getJabberProtocolProviderFactory();
String password = null;
String className = providerFactory.getClass().getName();
String packageSourceName = className.substring(0,
className.lastIndexOf('.'));
String accountPrefix = ProtocolProviderFactory.findAccountPrefix(
JabberAccRegWizzActivator.bundleContext,
accountID, packageSourceName);
CredentialsStorageService credentialsService =
JabberAccRegWizzActivator.getCredentialsService();
try
{
password = credentialsService.
loadPassword(accountPrefix + "." + namePrefix);
}
catch(Exception e)
{
return null;
}
return password;
}
}
|