|
@@ -30,7 +30,6 @@ import java.io.FileOutputStream;
|
30
|
30
|
import java.io.IOException;
|
31
|
31
|
import java.io.InputStream;
|
32
|
32
|
import java.io.UnsupportedEncodingException;
|
33
|
|
-import java.net.URL;
|
34
|
33
|
import java.util.List;
|
35
|
34
|
import java.util.Map;
|
36
|
35
|
import java.util.Map.Entry;
|
|
@@ -41,23 +40,15 @@ import java.util.Map.Entry;
|
41
|
40
|
public abstract class ResourceManager {
|
42
|
41
|
|
43
|
42
|
/** Previously assigned ResourceManager. */
|
|
43
|
+ @Deprecated
|
44
|
44
|
private static ResourceManager me;
|
45
|
45
|
|
46
|
|
- /** Enum indicating resource manager type. */
|
47
|
|
- public enum Type {
|
48
|
|
- /** File resource manager. */
|
49
|
|
- FILE,
|
50
|
|
- /** Jar resource manager. */
|
51
|
|
- JAR,
|
52
|
|
- /** No resource manager. */
|
53
|
|
- NONE,
|
54
|
|
- }
|
55
|
|
-
|
56
|
46
|
/**
|
57
|
47
|
* Returns an appropriate instance of ResourceManager.
|
58
|
48
|
*
|
59
|
49
|
* @return ResourceManager implementation
|
60
|
50
|
*/
|
|
51
|
+ @Deprecated
|
61
|
52
|
public static final synchronized ResourceManager getResourceManager() {
|
62
|
53
|
if (me == null) {
|
63
|
54
|
String path = Thread.currentThread().getContextClassLoader().
|
|
@@ -92,79 +83,38 @@ public abstract class ResourceManager {
|
92
|
83
|
}
|
93
|
84
|
|
94
|
85
|
/**
|
95
|
|
- * Returns an appropriate instance of ResourceManager for the specified url string.
|
96
|
|
- *
|
97
|
|
- * @param type file://path/to/base
|
98
|
|
- * jar://path/to/jar
|
99
|
|
- * zip://path/to/zip
|
|
86
|
+ * Returns a resource manager for the specified URL. The following URL types
|
|
87
|
+ * are valid:
|
100
|
88
|
*
|
101
|
|
- * @return ResourceManager implementation
|
|
89
|
+ * <ul>
|
|
90
|
+ * <li>file://path/</li>
|
|
91
|
+ * <li>zip://path/filename.zip</li>
|
|
92
|
+ * <li>jar://path/filename.jar</li>
|
|
93
|
+ * <li>dmdirc://</li>
|
|
94
|
+ * <li>theme://[themename:]</li>
|
|
95
|
+ * </ul>
|
|
96
|
+ *
|
|
97
|
+ * @param url The URL for which a resource manager is required
|
|
98
|
+ * @return A resource manager for the specified URL
|
102
|
99
|
*
|
103
|
|
- * @throws java.io.IOException if an IO Error occurs opening the file
|
|
100
|
+ * @throws IOException if an IO Error occurs opening the file
|
|
101
|
+ * @throws IllegalArgumentException if the URL type is not valid
|
104
|
102
|
*/
|
105
|
|
- public static final ResourceManager getResourceManager(final String type) throws IOException {
|
106
|
|
- if (type.startsWith("file://")) {
|
107
|
|
- return new FileResourceManager(type.substring(7));
|
108
|
|
- } else if (type.startsWith("jar://") || type.startsWith("zip://")) {
|
109
|
|
- return new ZipResourceManager(type.substring(6));
|
|
103
|
+ public static final ResourceManager getResourceManager(final String url)
|
|
104
|
+ throws IOException, IllegalArgumentException {
|
|
105
|
+ if (url.startsWith("file://")) {
|
|
106
|
+ return new FileResourceManager(url.substring(7));
|
|
107
|
+ } else if (url.startsWith("jar://") || url.startsWith("zip://")) {
|
|
108
|
+ return new ZipResourceManager(url.substring(6));
|
|
109
|
+ } else if (url.startsWith("dmdirc://")) {
|
|
110
|
+ throw new UnsupportedOperationException("Not implemented yet");
|
|
111
|
+ } else if (url.startsWith("theme://")) {
|
|
112
|
+ throw new UnsupportedOperationException("Not implemented yet");
|
110
|
113
|
} else {
|
111
|
114
|
throw new IllegalArgumentException("Unknown resource manager type");
|
112
|
115
|
}
|
113
|
116
|
}
|
114
|
117
|
|
115
|
|
- /**
|
116
|
|
- * Returns the working directory for the application.
|
117
|
|
- *
|
118
|
|
- * @return Current working directory
|
119
|
|
- */
|
120
|
|
- public static final synchronized String getCurrentWorkingDirectory() {
|
121
|
|
- final URL resource = Thread.currentThread().getContextClassLoader().
|
122
|
|
- getResource("com/dmdirc/Main.class");
|
123
|
|
- String path = "";
|
124
|
|
-
|
125
|
|
- final String protocol = resource.getProtocol();
|
126
|
|
-
|
127
|
|
- if ("file".equals(protocol)) {
|
128
|
|
- path = Thread.currentThread().
|
129
|
|
- getContextClassLoader().getResource("").getPath();
|
130
|
|
- } else if ("jar".equals(protocol)) {
|
131
|
|
- final String tempPath = resource.getPath();
|
132
|
|
- if (System.getProperty("os.name").startsWith("Windows")) {
|
133
|
|
- path = tempPath.substring(6, tempPath.length() - 23);
|
134
|
|
- } else {
|
135
|
|
- path = tempPath.substring(5, tempPath.length() - 23);
|
136
|
|
- }
|
137
|
|
- path = path.substring(0, path.lastIndexOf('/') + 1);
|
138
|
|
- }
|
139
|
|
-
|
140
|
|
- try {
|
141
|
|
- path = java.net.URLDecoder.decode(path, "UTF-8");
|
142
|
|
- } catch (UnsupportedEncodingException ex) {
|
143
|
|
- Logger.userError(ErrorLevel.MEDIUM, "Unable to decode path");
|
144
|
|
- path = "";
|
145
|
|
- }
|
146
|
|
- return path;
|
147
|
|
- }
|
148
|
|
-
|
149
|
|
- /**
|
150
|
|
- * Returns the type of the resource manager.
|
151
|
|
- *
|
152
|
|
- * @return ResourceManager Type
|
153
|
|
- */
|
154
|
|
- public static final synchronized Type getResourceManagerType() {
|
155
|
|
- if (me == null) {
|
156
|
|
- getResourceManager();
|
157
|
|
- }
|
158
|
|
-
|
159
|
|
- if (me instanceof ZipResourceManager) {
|
160
|
|
- return Type.JAR;
|
161
|
|
- } else if (me instanceof FileResourceManager) {
|
162
|
|
- return Type.FILE;
|
163
|
|
- } else {
|
164
|
|
- return Type.NONE;
|
165
|
|
- }
|
166
|
|
- }
|
167
|
|
-
|
168
|
118
|
/**
|
169
|
119
|
* Writes a resource to a file.
|
170
|
120
|
*
|
|
@@ -173,6 +123,7 @@ public abstract class ResourceManager {
|
173
|
123
|
*
|
174
|
124
|
* @throws IOException if the write operation fails
|
175
|
125
|
*/
|
|
126
|
+ @Deprecated
|
176
|
127
|
public final void resourceToFile(final byte[] resource, final File file)
|
177
|
128
|
throws IOException {
|
178
|
129
|
final FileOutputStream out = new FileOutputStream(file, false);
|
|
@@ -195,6 +146,7 @@ public abstract class ResourceManager {
|
195
|
146
|
*
|
196
|
147
|
* @return success of failure of the operation
|
197
|
148
|
*/
|
|
149
|
+ @Deprecated
|
198
|
150
|
public final boolean extractResource(final String resourceName,
|
199
|
151
|
final String directory, final boolean usePath) throws IOException {
|
200
|
152
|
final byte[] resource = getResourceBytes(resourceName);
|
|
@@ -241,6 +193,7 @@ public abstract class ResourceManager {
|
241
|
193
|
*
|
242
|
194
|
* @throws IOException if the write operation fails
|
243
|
195
|
*/
|
|
196
|
+ @Deprecated
|
244
|
197
|
public final void extractResources(final String resourcesPrefix,
|
245
|
198
|
final String directory, final boolean usePath) throws IOException {
|
246
|
199
|
final Map<String, byte[]> resourcesBytes =
|
|
@@ -258,6 +211,7 @@ public abstract class ResourceManager {
|
258
|
211
|
*
|
259
|
212
|
* @throws IOException if the write operation fails
|
260
|
213
|
*/
|
|
214
|
+ @Deprecated
|
261
|
215
|
public final void extractResources(final String resourcesPrefix,
|
262
|
216
|
final String directory) throws IOException {
|
263
|
217
|
extractResources(resourcesPrefix, directory, true);
|
|
@@ -270,6 +224,7 @@ public abstract class ResourceManager {
|
270
|
224
|
*
|
271
|
225
|
* @return true iif the resource exists
|
272
|
226
|
*/
|
|
227
|
+ @Deprecated
|
273
|
228
|
public abstract boolean resourceExists(final String resource);
|
274
|
229
|
|
275
|
230
|
/**
|
|
@@ -279,6 +234,7 @@ public abstract class ResourceManager {
|
279
|
234
|
*
|
280
|
235
|
* @return byte[] for the resource, or an empty byte[] if not found
|
281
|
236
|
*/
|
|
237
|
+ @Deprecated
|
282
|
238
|
public abstract byte[] getResourceBytes(final String resource);
|
283
|
239
|
|
284
|
240
|
/**
|
|
@@ -288,6 +244,7 @@ public abstract class ResourceManager {
|
288
|
244
|
*
|
289
|
245
|
* @return InputStream for the resource, or null if not found
|
290
|
246
|
*/
|
|
247
|
+ @Deprecated
|
291
|
248
|
public abstract InputStream getResourceInputStream(final String resource);
|
292
|
249
|
|
293
|
250
|
/**
|
|
@@ -298,6 +255,7 @@ public abstract class ResourceManager {
|
298
|
255
|
*
|
299
|
256
|
* @return Map of byte[]s of resources found
|
300
|
257
|
*/
|
|
258
|
+ @Deprecated
|
301
|
259
|
public abstract Map<String, byte[]> getResourcesStartingWithAsBytes(
|
302
|
260
|
final String resourcesPrefix);
|
303
|
261
|
|
|
@@ -309,6 +267,7 @@ public abstract class ResourceManager {
|
309
|
267
|
*
|
310
|
268
|
* @return Map of InputStreams of resources found
|
311
|
269
|
*/
|
|
270
|
+ @Deprecated
|
312
|
271
|
public abstract Map<String, InputStream> getResourcesStartingWithAsInputStreams(
|
313
|
272
|
final String resourcesPrefix);
|
314
|
273
|
|
|
@@ -320,5 +279,6 @@ public abstract class ResourceManager {
|
320
|
279
|
*
|
321
|
280
|
* @return List of resources found
|
322
|
281
|
*/
|
|
282
|
+ @Deprecated
|
323
|
283
|
public abstract List<String> getResourcesStartingWith(final String resourcesPrefix);
|
324
|
284
|
}
|