|
@@ -543,14 +543,15 @@ public class Identity extends ConfigSource implements Serializable,
|
543
|
543
|
*
|
544
|
544
|
* @param settings The settings to populate the identity with
|
545
|
545
|
* @return A new identity containing the specified properties
|
|
546
|
+ * @throws IOException If the file cannot be created
|
|
547
|
+ * @throws InvalidIdentityFileException If the settings are invalid
|
546
|
548
|
* @since 0.6.3
|
547
|
549
|
*/
|
548
|
|
- protected static Identity createIdentity(final Map<String, Map<String, String>> settings) {
|
|
550
|
+ protected static Identity createIdentity(final Map<String, Map<String, String>> settings)
|
|
551
|
+ throws IOException, InvalidIdentityFileException {
|
549
|
552
|
if (!settings.containsKey(DOMAIN) || !settings.get(DOMAIN).containsKey("name")
|
550
|
553
|
|| settings.get(DOMAIN).get("name").isEmpty()) {
|
551
|
|
- Logger.appError(ErrorLevel.LOW, "createIdentity called with invalid identity",
|
552
|
|
- new InvalidIdentityFileException("identity.name is not set"));
|
553
|
|
- return null;
|
|
554
|
+ throw new InvalidIdentityFileException("identity.name is not set");
|
554
|
555
|
}
|
555
|
556
|
|
556
|
557
|
final String fs = System.getProperty("file.separator");
|
|
@@ -570,32 +571,12 @@ public class Identity extends ConfigSource implements Serializable,
|
570
|
571
|
configFile.addDomain(entry.getKey(), entry.getValue());
|
571
|
572
|
}
|
572
|
573
|
|
573
|
|
- try {
|
574
|
|
- configFile.write();
|
575
|
|
- } catch (IOException ex) {
|
576
|
|
- Logger.userError(ErrorLevel.MEDIUM,
|
577
|
|
- "Unable to write new identity file: " + ex.getMessage());
|
578
|
|
- return null;
|
579
|
|
- }
|
|
574
|
+ configFile.write();
|
580
|
575
|
|
581
|
|
- try {
|
582
|
|
- final Identity identity = new Identity(file, false);
|
583
|
|
- IdentityManager.addIdentity(identity);
|
|
576
|
+ final Identity identity = new Identity(file, false);
|
|
577
|
+ IdentityManager.addIdentity(identity);
|
584
|
578
|
|
585
|
|
- return identity;
|
586
|
|
- } catch (MalformedURLException ex) {
|
587
|
|
- Logger.userError(ErrorLevel.MEDIUM,
|
588
|
|
- "Unable to open new identity file: " + ex.getMessage());
|
589
|
|
- return null;
|
590
|
|
- } catch (InvalidIdentityFileException ex) {
|
591
|
|
- Logger.userError(ErrorLevel.MEDIUM,
|
592
|
|
- "Unable to open new identity file: " + ex.getMessage());
|
593
|
|
- return null;
|
594
|
|
- } catch (IOException ex) {
|
595
|
|
- Logger.userError(ErrorLevel.MEDIUM,
|
596
|
|
- "Unable to open new identity file: " + ex.getMessage());
|
597
|
|
- return null;
|
598
|
|
- }
|
|
579
|
+ return identity;
|
599
|
580
|
}
|
600
|
581
|
|
601
|
582
|
/**
|
|
@@ -603,15 +584,23 @@ public class Identity extends ConfigSource implements Serializable,
|
603
|
584
|
*
|
604
|
585
|
* @param target The target for the new identity
|
605
|
586
|
* @return An empty identity for the specified target
|
|
587
|
+ * @throws IOException if the file can't be written
|
|
588
|
+ * @see #createIdentity(java.util.Map)
|
606
|
589
|
*/
|
607
|
|
- public static Identity buildIdentity(final ConfigTarget target) {
|
|
590
|
+ public static Identity buildIdentity(final ConfigTarget target)
|
|
591
|
+ throws IOException {
|
608
|
592
|
final Map<String, Map<String, String>> settings
|
609
|
593
|
= new HashMap<String, Map<String, String>>();
|
610
|
594
|
settings.put(DOMAIN, new HashMap<String, String>(2));
|
611
|
595
|
settings.get(DOMAIN).put("name", target.getData());
|
612
|
596
|
settings.get(DOMAIN).put(target.getTypeName(), target.getData());
|
613
|
597
|
|
614
|
|
- return createIdentity(settings);
|
|
598
|
+ try {
|
|
599
|
+ return createIdentity(settings);
|
|
600
|
+ } catch (InvalidIdentityFileException ex) {
|
|
601
|
+ Logger.appError(ErrorLevel.MEDIUM, "Unable to create identity", ex);
|
|
602
|
+ return null;
|
|
603
|
+ }
|
615
|
604
|
}
|
616
|
605
|
|
617
|
606
|
/**
|
|
@@ -620,8 +609,10 @@ public class Identity extends ConfigSource implements Serializable,
|
620
|
609
|
*
|
621
|
610
|
* @param name The name of the profile to create
|
622
|
611
|
* @return A new profile with the specified name
|
|
612
|
+ * @throws IOException If the file can't be written
|
|
613
|
+ * @see #createIdentity(java.util.Map)
|
623
|
614
|
*/
|
624
|
|
- public static Identity buildProfile(final String name) {
|
|
615
|
+ public static Identity buildProfile(final String name) throws IOException {
|
625
|
616
|
final Map<String, Map<String, String>> settings
|
626
|
617
|
= new HashMap<String, Map<String, String>>();
|
627
|
618
|
settings.put(DOMAIN, new HashMap<String, String>(1));
|
|
@@ -633,7 +624,12 @@ public class Identity extends ConfigSource implements Serializable,
|
633
|
624
|
settings.get("profile").put("nickname", nick);
|
634
|
625
|
settings.get("profile").put("realname", nick);
|
635
|
626
|
|
636
|
|
- return createIdentity(settings);
|
|
627
|
+ try {
|
|
628
|
+ return createIdentity(settings);
|
|
629
|
+ } catch (InvalidIdentityFileException ex) {
|
|
630
|
+ Logger.appError(ErrorLevel.MEDIUM, "Unable to create identity", ex);
|
|
631
|
+ return null;
|
|
632
|
+ }
|
637
|
633
|
}
|
638
|
634
|
|
639
|
635
|
}
|