Browse Source

Issue 1703: Add missing @since and remove properties migration


git-svn-id: http://svn.dmdirc.com/trunk@4828 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6.3m1rc1
Chris Smith 15 years ago
parent
commit
16a29a3c91

+ 13
- 47
src/com/dmdirc/config/Identity.java View File

@@ -32,10 +32,8 @@ import com.dmdirc.util.WeakList;
32 32
 
33 33
 import java.io.File;
34 34
 import java.io.FileInputStream;
35
-import java.io.FileWriter;
36 35
 import java.io.IOException;
37 36
 import java.io.InputStream;
38
-import java.io.Reader;
39 37
 import java.io.Serializable;
40 38
 import java.net.MalformedURLException;
41 39
 import java.util.ArrayList;
@@ -43,7 +41,6 @@ import java.util.HashMap;
43 41
 import java.util.HashSet;
44 42
 import java.util.List;
45 43
 import java.util.Map;
46
-import java.util.Properties;
47 44
 import java.util.Set;
48 45
 
49 46
 /**
@@ -96,7 +93,7 @@ public class Identity extends ConfigSource implements Serializable,
96 93
     public Identity(final File file, final boolean forceDefault) throws IOException,
97 94
             InvalidIdentityFileException {
98 95
         super();
99
-        
96
+
100 97
         this.file = new ConfigFile(file);
101 98
         this.file.setAutomake(true);
102 99
         initFile(forceDefault, new FileInputStream(file));
@@ -115,50 +112,27 @@ public class Identity extends ConfigSource implements Serializable,
115 112
     public Identity(final InputStream stream, final boolean forceDefault) throws IOException,
116 113
             InvalidIdentityFileException {
117 114
         super();
118
-        
115
+
119 116
         this.file = new ConfigFile(stream);
120 117
         this.file.setAutomake(true);
121 118
         initFile(forceDefault, stream);
122 119
         myTarget = getTarget(forceDefault);
123 120
     }
124
-    
121
+
125 122
     /**
126 123
      * Creates a new identity from the specified config file.
127
-     * 
124
+     *
128 125
      * @param configFile The config file to use
129 126
      * @param target The target of this identity
130 127
      */
131 128
     public Identity(final ConfigFile configFile, final ConfigTarget target) {
132 129
         super();
133
-        
130
+
134 131
         this.file = configFile;
135 132
         this.file.setAutomake(true);
136 133
         this.myTarget = target;
137 134
     }
138 135
 
139
-    /**
140
-     * Migrates the contents of the specified property file into a ConfigFile.
141
-     *
142
-     * @param properties The properties to migrate
143
-     */
144
-    private void migrateProperties(final Properties properties) {
145
-        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
146
-            final String key = (String) entry.getKey();
147
-            final String value = (String) entry.getValue();
148
-            final int offset = key.indexOf('.');
149
-
150
-            if (offset > -1) {
151
-                final String domain = key.substring(0, offset);
152
-                final String option = key.substring(1 + offset);
153
-
154
-                file.getKeyDomain(domain).put(option, value);
155
-            }
156
-        }
157
-        
158
-        needSave = true;
159
-        save();
160
-    }
161
-
162 136
     /**
163 137
      * Determines and returns the target for this identity from its contents.
164 138
      *
@@ -206,19 +180,10 @@ public class Identity extends ConfigSource implements Serializable,
206 180
      */
207 181
     private void initFile(final boolean forceDefault, final InputStream stream)
208 182
             throws InvalidIdentityFileException, IOException {
209
-        
210
-        if (stream.markSupported()) {
211
-            stream.mark(Integer.MAX_VALUE);
212
-        }
213
-        
214 183
         try {
215 184
             this.file.read();
216
-        } catch (InvalidConfigFileException ex) {            
217
-            final Properties properties = new Properties();
218
-            final Reader reader = new LineReader(this.file.getLines());
219
-            properties.load(reader);
220
-            reader.close();
221
-            migrateProperties(properties);
185
+        } catch (InvalidConfigFileException ex) {
186
+            throw new InvalidIdentityFileException(ex);
222 187
         }
223 188
 
224 189
         if (!hasOption(DOMAIN, "name") && !forceDefault) {
@@ -417,21 +382,21 @@ public class Identity extends ConfigSource implements Serializable,
417 382
             listener.configChanged(domain, option);
418 383
         }
419 384
     }
420
-    
385
+
421 386
     /**
422 387
      * Returns the set of domains available in this identity.
423
-     * 
388
+     *
424 389
      * @since 0.6
425 390
      * @return The set of domains used by this identity
426 391
      */
427 392
     public Set<String> getDomains() {
428 393
         return new HashSet<String>(file.getKeyDomains().keySet());
429 394
     }
430
-    
395
+
431 396
     /**
432 397
      * Retrieves a map of all options within the specified domain in this
433 398
      * identity.
434
-     * 
399
+     *
435 400
      * @param domain The domain to retrieve
436 401
      * @since 0.6
437 402
      * @return A map of option names to values
@@ -578,6 +543,7 @@ public class Identity extends ConfigSource implements Serializable,
578 543
      *
579 544
      * @param settings The settings to populate the identity with
580 545
      * @return A new identity containing the specified properties
546
+     * @since 0.6.3
581 547
      */
582 548
     protected static Identity createIdentity(final Map<String, Map<String, String>> settings) {
583 549
         if (!settings.containsKey(DOMAIN) || !settings.get(DOMAIN).containsKey("name")
@@ -662,7 +628,7 @@ public class Identity extends ConfigSource implements Serializable,
662 628
         settings.put("profile", new HashMap<String, String>(2));
663 629
 
664 630
         final String nick = System.getProperty("user.name").replace(' ', '_');
665
-        
631
+
666 632
         settings.get(DOMAIN).put("name", name);
667 633
         settings.get("profile").put("nickname", nick);
668 634
         settings.get("profile").put("realname", nick);

+ 10
- 0
src/com/dmdirc/config/InvalidIdentityFileException.java View File

@@ -40,6 +40,16 @@ public class InvalidIdentityFileException extends Exception {
40 40
     public InvalidIdentityFileException() {
41 41
         super();
42 42
     }
43
+
44
+    /**
45
+     * Creates a new instance of InvalidIdentityFileException.
46
+     *
47
+     * @param cause The cause of the exception
48
+     * @since 0.6.3
49
+     */
50
+    public InvalidIdentityFileException(final Throwable cause) {
51
+        super(cause);
52
+    }
43 53
     
44 54
     /**
45 55
      * Creates a new instance of InvalidIdentityFileException.

Loading…
Cancel
Save