瀏覽代碼

ConfigFile now extends TextFile instead of wrapping it rather oddly (groundwork for fixing issue 1154)

Fixed a couple of deprecated method uses in Server
Removed deprecated TextFile constructor

git-svn-id: http://svn.dmdirc.com/trunk@4005 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 年之前
父節點
當前提交
47ceae6b4b

+ 5
- 5
src/com/dmdirc/Server.java 查看文件

@@ -425,7 +425,7 @@ public final class Server extends WritableFrameContainer implements Serializable
425 425
         final String nick = ClientInfo.parseHost(host);
426 426
 
427 427
         for (Query query : queries) {
428
-            if (parser.equalsIgnoreCase(ClientInfo.parseHost(query.getHost()), nick)) {
428
+            if (converter.equalsIgnoreCase(ClientInfo.parseHost(query.getHost()), nick)) {
429 429
                 return true;
430 430
             }
431 431
         }
@@ -443,7 +443,7 @@ public final class Server extends WritableFrameContainer implements Serializable
443 443
         final String nick = ClientInfo.parseHost(host);
444 444
 
445 445
         for (Query query : queries) {
446
-            if (parser.equalsIgnoreCase(ClientInfo.parseHost(query.getHost()), nick)) {
446
+            if (converter.equalsIgnoreCase(ClientInfo.parseHost(query.getHost()), nick)) {
447 447
                 return query;
448 448
             }
449 449
         }
@@ -1000,7 +1000,7 @@ public final class Server extends WritableFrameContainer implements Serializable
1000 1000
         final String lastNick = parser.getMyNickname();
1001 1001
 
1002 1002
         // If our last nick is still valid, ignore the in use message
1003
-        if (!parser.equalsIgnoreCase(lastNick, nickname)) {
1003
+        if (!converter.equalsIgnoreCase(lastNick, nickname)) {
1004 1004
             return;
1005 1005
         }
1006 1006
 
@@ -1010,11 +1010,11 @@ public final class Server extends WritableFrameContainer implements Serializable
1010 1010
             final String[] alts = profile.getOption(DOMAIN_PROFILE, "altnicks").split("\n");
1011 1011
             int offset = 0;
1012 1012
 
1013
-            if (!parser.equalsIgnoreCase(lastNick,
1013
+            if (!converter.equalsIgnoreCase(lastNick,
1014 1014
                     profile.getOption(DOMAIN_PROFILE, "nickname"))) {
1015 1015
                 for (String alt : alts) {
1016 1016
                     offset++;
1017
-                    if (parser.equalsIgnoreCase(alt, lastNick)) {
1017
+                    if (converter.equalsIgnoreCase(alt, lastNick)) {
1018 1018
                         break;
1019 1019
                     }
1020 1020
                 }

+ 2
- 3
src/com/dmdirc/config/Identity.java 查看文件

@@ -29,7 +29,6 @@ import com.dmdirc.logger.ErrorLevel;
29 29
 import com.dmdirc.logger.Logger;
30 30
 import com.dmdirc.util.ConfigFile;
31 31
 import com.dmdirc.util.InvalidConfigFileException;
32
-import com.dmdirc.util.TextFile;
33 32
 import com.dmdirc.util.WeakList;
34 33
 
35 34
 import java.io.File;
@@ -131,7 +130,7 @@ public class Identity extends ConfigSource implements Serializable,
131 130
      */
132 131
     public Identity(final File file, final boolean forceDefault) throws IOException,
133 132
             InvalidIdentityFileException {
134
-        this.file = new ConfigFile(new TextFile(file));
133
+        this.file = new ConfigFile(file);
135 134
         this.file.setAutomake(true);
136 135
         initFile(forceDefault, new FileInputStream(file), new FileInputStream(file));
137 136
         myTarget = getTarget(forceDefault);
@@ -150,7 +149,7 @@ public class Identity extends ConfigSource implements Serializable,
150 149
     public Identity(final InputStream stream, final InputStream stream2,
151 150
             final boolean forceDefault) throws IOException,
152 151
             InvalidIdentityFileException {
153
-        this.file = new ConfigFile(new TextFile(stream));
152
+        this.file = new ConfigFile(stream);
154 153
         this.file.setAutomake(true);
155 154
         initFile(forceDefault, stream, stream2);
156 155
         myTarget = getTarget(forceDefault);

+ 1
- 1
src/com/dmdirc/config/IdentityManager.java 查看文件

@@ -185,7 +185,7 @@ public final class IdentityManager {
185 185
     private static void loadIdentity(final File file) {
186 186
         synchronized (identities) {
187 187
             for (Identity identity : identities) {
188
-                if (file.equals(identity.getFile().getFile().getFile())) {
188
+                if (file.equals(identity.getFile().getFile())) {
189 189
                     try {
190 190
                         identity.reload();
191 191
                     } catch (IOException ex) {

+ 20
- 62
src/com/dmdirc/util/ConfigFile.java 查看文件

@@ -22,10 +22,10 @@
22 22
 
23 23
 package com.dmdirc.util;
24 24
 
25
+import java.io.File;
25 26
 import java.io.FileNotFoundException;
26 27
 import java.io.IOException;
27 28
 import java.io.InputStream;
28
-import java.net.URI;
29 29
 import java.util.ArrayList;
30 30
 import java.util.GregorianCalendar;
31 31
 import java.util.HashMap;
@@ -37,7 +37,7 @@ import java.util.Map;
37 37
  *
38 38
  * @author chris
39 39
  */
40
-public class ConfigFile {
40
+public class ConfigFile extends TextFile {
41 41
 
42 42
     /** A list of domains in this config file. */
43 43
     private final List<String> domains = new ArrayList<String>();
@@ -48,55 +48,38 @@ public class ConfigFile {
48 48
     /** The key/value sets associated with each key domain. */
49 49
     private final Map<String, Map<String, String>> keydomains
50 50
             = new HashMap<String, Map<String, String>>();
51
-
52
-    /** The text file we're reading. */
53
-    private final TextFile file;
54 51
     
55 52
     /** Whether or not we should automatically create domains. */
56 53
     private boolean automake;
57 54
 
58 55
     /**
59
-     * Creates a new instance of ConfigFile.
56
+     * Creates a new read-only Config File from the specified input stream.
60 57
      * 
61
-     * @param file The path of the file to be loaded
62
-     * @deprecated Pass a TextFile instead
63
-     */
64
-    @Deprecated
65
-    public ConfigFile(final String file) {
66
-        this.file = new TextFile(file);
67
-    }
68
-    
69
-    /**
70
-     * Creates a new instance of ConfigFile.
71
-     * 
72
-     * @param uri The URI of the file to be loaded
73
-     * @deprecated Pass a TextFile instead
58
+     * @param is The input stream to read
74 59
      */
75
-    @Deprecated
76
-    public ConfigFile(final URI uri) {
77
-        this.file = new TextFile(uri);
60
+    public ConfigFile(final InputStream is) {
61
+        super(is);
78 62
     }
79
-    
63
+
80 64
     /**
81
-     * Creates a ConfigFile from the specified input stream.
65
+     * Creates a new Config File from the specified file.
82 66
      * 
83
-     * @param is The input stream to read
84
-     * @deprecated Pass a TextFile instead
67
+     * @param file The file to read/write
85 68
      */
86
-    @Deprecated
87
-    public ConfigFile(final InputStream is) {
88
-        this.file = new TextFile(is);
69
+    public ConfigFile(final File file) {
70
+        super(file);
89 71
     }
90
-    
72
+
91 73
     /**
92
-     * Creates a ConfigFile for the specified file.
74
+     * Creates a new Config File from the specified file.
93 75
      * 
94
-     * @param file The file to use
76
+     * @param filename The name of the file to read/write
95 77
      */
96
-    public ConfigFile(final TextFile file) {
97
-        this.file = file;
78
+    public ConfigFile(final String filename) {
79
+        super(filename);
98 80
     }
99 81
 
82
+
100 83
     /**
101 84
      * Sets the "automake" value of this config file. If automake is set to
102 85
      * true, any calls to getKeyDomain will automatically create the domain
@@ -124,7 +107,7 @@ public class ConfigFile {
124 107
         flatdomains.clear();
125 108
         domains.clear();
126 109
 
127
-        for (String line : file.getLines()) {
110
+        for (String line : getLines()) {
128 111
             String tline = line;
129 112
             
130 113
             while (!tline.isEmpty() && (tline.charAt(0) == '\t' || 
@@ -170,7 +153,7 @@ public class ConfigFile {
170 153
      * @throws IOException if the write operation fails
171 154
      */
172 155
     public void write() throws IOException {
173
-        if (!file.isWritable()) {
156
+        if (!isWritable()) {
174 157
             throw new UnsupportedOperationException("Cannot write to a file "
175 158
                     + "that isn't writable");
176 159
         }
@@ -203,34 +186,9 @@ public class ConfigFile {
203 186
             }
204 187
         }
205 188
 
206
-        file.writeLines(lines);
189
+        writeLines(lines);
207 190
     }
208 191
     
209
-    /**
210
-     * Determines if this file is writable or not.
211
-     * 
212
-     * @return True if the file is writable, false otherwise
213
-     */
214
-    public boolean isWritable() {
215
-        return file != null && file.isWritable();
216
-    }    
217
-    
218
-    /**
219
-     * Deletes this config file.
220
-     */
221
-    public void delete() {
222
-        file.delete();
223
-    }
224
-
225
-    /**
226
-     * Retrieves the text file for this config file.
227
-     * 
228
-     * @return This config file's text file
229
-     */
230
-    public TextFile getFile() {
231
-        return file;
232
-    }
233
-
234 192
     /**
235 193
      * Appends the meta-data (keysections) to the specified list of lines.
236 194
      * 

+ 1
- 13
src/com/dmdirc/util/TextFile.java 查看文件

@@ -30,7 +30,6 @@ import java.io.FileWriter;
30 30
 import java.io.IOException;
31 31
 import java.io.InputStream;
32 32
 import java.io.InputStreamReader;
33
-import java.net.URI;
34 33
 import java.util.ArrayList;
35 34
 import java.util.List;
36 35
 
@@ -55,18 +54,7 @@ public class TextFile {
55 54
     public TextFile(final String filename) {
56 55
         file = new File(filename);
57 56
     }
58
-    
59
-    /**
60
-     * Creates a new instance of TextFile for the specified URI.
61
-     * 
62
-     * @param uri The URI of the file
63
-     * @deprecated Pass an InputStream or File instead
64
-     */
65
-    @Deprecated
66
-    public TextFile(final URI uri) {
67
-        file = new File(uri);
68
-    }
69
-    
57
+
70 58
     /**
71 59
      * Creates a new instance of TextFile for the specified File.
72 60
      * 

+ 3
- 3
test/com/dmdirc/actions/ActionTest.java 查看文件

@@ -25,12 +25,12 @@ import com.dmdirc.actions.interfaces.ActionType;
25 25
 
26 26
 import com.dmdirc.util.ConfigFile;
27 27
 import com.dmdirc.util.InvalidConfigFileException;
28
-import com.dmdirc.util.TextFile;
28
+
29 29
 import java.io.File;
30 30
 import java.io.IOException;
31 31
 import java.util.ArrayList;
32
-
33 32
 import java.util.Arrays;
33
+
34 34
 import org.junit.Test;
35 35
 import static org.junit.Assert.*;
36 36
 
@@ -85,7 +85,7 @@ public class ActionTest extends junit.framework.TestCase {
85 85
         ActionManager.init();
86 86
 
87 87
         final Action action = new Action("unit-test", "doesn't_exist");
88
-        action.config = new ConfigFile(new TextFile(getClass().getResourceAsStream("action1")));
88
+        action.config = new ConfigFile(getClass().getResourceAsStream("action1"));
89 89
         action.config.read();
90 90
         action.loadActionFromConfig();
91 91
 

+ 13
- 12
test/com/dmdirc/util/ConfigFileTest.java 查看文件

@@ -28,6 +28,7 @@ import java.io.FileNotFoundException;
28 28
 import java.io.IOException;
29 29
 import java.util.HashMap;
30 30
 import java.util.Map;
31
+
31 32
 import org.junit.Before;
32 33
 import org.junit.Test;
33 34
 import static org.junit.Assert.*;
@@ -39,7 +40,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
39 40
     @Before
40 41
     public void setUp() throws Exception {
41 42
         cf = new ConfigFile(getClass().getClassLoader().
42
-                    getResource("com/dmdirc/util/test2.txt").toURI());
43
+                    getResourceAsStream("com/dmdirc/util/test2.txt"));
43 44
     }    
44 45
 
45 46
     @Test
@@ -107,7 +108,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
107 108
     @Test
108 109
     public void testColons() throws IOException, InvalidConfigFileException {
109 110
         final File file = File.createTempFile("DMDirc.unittest", null);
110
-        ConfigFile config = new ConfigFile(file.toURI());
111
+        ConfigFile config = new ConfigFile(file);
111 112
         Map<String, String> data = new HashMap<String, String>();
112 113
         data.put("test1", "hello");
113 114
         data.put("test:2", "hello");
@@ -115,7 +116,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
115 116
         config.addDomain("test", data);
116 117
         config.write();
117 118
         
118
-        config = new ConfigFile(file.toURI());
119
+        config = new ConfigFile(file);
119 120
         config.read();
120 121
         
121 122
         assertTrue(config.isKeyDomain("test"));
@@ -128,7 +129,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
128 129
     @Test
129 130
     public void testEquals() throws IOException, InvalidConfigFileException {
130 131
         final File file = File.createTempFile("DMDirc.unittest", null);
131
-        ConfigFile config = new ConfigFile(file.toURI());
132
+        ConfigFile config = new ConfigFile(file);
132 133
         Map<String, String> data = new HashMap<String, String>();
133 134
         data.put("test1", "hello");
134 135
         data.put("test=2", "hello");
@@ -136,7 +137,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
136 137
         config.addDomain("test", data);
137 138
         config.write();
138 139
         
139
-        config = new ConfigFile(file.toURI());
140
+        config = new ConfigFile(file);
140 141
         config.read();
141 142
         
142 143
         assertTrue(config.isKeyDomain("test"));
@@ -149,7 +150,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
149 150
     @Test
150 151
     public void testNewlines() throws IOException, InvalidConfigFileException {
151 152
         final File file = File.createTempFile("DMDirc.unittest", null);
152
-        ConfigFile config = new ConfigFile(file.toURI());
153
+        ConfigFile config = new ConfigFile(file);
153 154
         Map<String, String> data = new HashMap<String, String>();
154 155
         data.put("test1", "hello");
155 156
         data.put("test2", "hello\ngoodbye");
@@ -158,7 +159,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
158 159
         config.addDomain("test", data);
159 160
         config.write();
160 161
         
161
-        config = new ConfigFile(file.toURI());
162
+        config = new ConfigFile(file);
162 163
         config.read();
163 164
         
164 165
         assertTrue(config.isKeyDomain("test"));
@@ -172,7 +173,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
172 173
     @Test
173 174
     public void testBackslash() throws IOException, InvalidConfigFileException {
174 175
         final File file = File.createTempFile("DMDirc.unittest", null);
175
-        ConfigFile config = new ConfigFile(file.toURI());
176
+        ConfigFile config = new ConfigFile(file);
176 177
         Map<String, String> data = new HashMap<String, String>();
177 178
         data.put("test1", "hello\\");
178 179
         data.put("test2", "\\nhello");
@@ -180,7 +181,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
180 181
         config.addDomain("test", data);
181 182
         config.write();
182 183
         
183
-        config = new ConfigFile(file.toURI());
184
+        config = new ConfigFile(file);
184 185
         config.read();
185 186
         
186 187
         assertTrue(config.isKeyDomain("test"));
@@ -193,7 +194,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
193 194
     @Test
194 195
     public void testHash() throws IOException, InvalidConfigFileException {
195 196
         final File file = File.createTempFile("DMDirc.unittest", null);
196
-        ConfigFile config = new ConfigFile(file.toURI());
197
+        ConfigFile config = new ConfigFile(file);
197 198
         Map<String, String> data = new HashMap<String, String>();
198 199
         data.put("test1#", "hello");
199 200
         data.put("#test2", "hello");
@@ -201,7 +202,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
201 202
         config.addDomain("test", data);
202 203
         config.write();
203 204
         
204
-        config = new ConfigFile(file.toURI());
205
+        config = new ConfigFile(file);
205 206
         config.read();
206 207
         
207 208
         assertTrue(config.isKeyDomain("test"));
@@ -227,7 +228,7 @@ public class ConfigFileTest extends junit.framework.TestCase {
227 228
     @Test
228 229
     public void testDelete() throws IOException {
229 230
         final File file = File.createTempFile("DMDirc_unittest", null);
230
-        ConfigFile config = new ConfigFile(new TextFile(file));
231
+        ConfigFile config = new ConfigFile(file);
231 232
         config.write();
232 233
         assertTrue(file.exists());
233 234
         config.delete();

Loading…
取消
儲存