|
@@ -29,6 +29,7 @@ import com.dmdirc.config.IdentityManager;
|
29
|
29
|
import com.dmdirc.logger.ErrorLevel;
|
30
|
30
|
import com.dmdirc.logger.Logger;
|
31
|
31
|
import com.dmdirc.ui.core.components.StatusBarManager;
|
|
32
|
+import com.dmdirc.ui.interfaces.UIController;
|
32
|
33
|
|
33
|
34
|
import java.awt.Desktop;
|
34
|
35
|
import java.io.IOException;
|
|
@@ -42,34 +43,38 @@ import java.util.List;
|
42
|
43
|
/** Handles URLs. */
|
43
|
44
|
public class URLHandler {
|
44
|
45
|
|
|
46
|
+ /** The UI Controller that owns this handler. */
|
|
47
|
+ private final UIController controller;
|
45
|
48
|
/** Config manager. */
|
46
|
49
|
private final ConfigManager config;
|
47
|
|
- /** Singleton instance. */
|
48
|
|
- private static final URLHandler ME = new URLHandler();
|
49
|
50
|
/** Desktop handler. */
|
50
|
51
|
private final Desktop desktop;
|
51
|
52
|
/** The time a browser was last launched. */
|
52
|
53
|
private static Date lastLaunch;
|
53
|
54
|
|
54
|
|
- /** Instantiates a new URL Handler. */
|
55
|
|
- private URLHandler() {
|
56
|
|
- config = IdentityManager.getGlobalConfig();
|
57
|
|
- if (Desktop.isDesktopSupported()) {
|
58
|
|
- desktop = Desktop.getDesktop();
|
59
|
|
- } else {
|
60
|
|
- desktop = null;
|
61
|
|
- }
|
|
55
|
+ /**
|
|
56
|
+ * Instantiates a new URL Handler.
|
|
57
|
+ *
|
|
58
|
+ * @param controller The UI controller to show dialogs etc on
|
|
59
|
+ */
|
|
60
|
+ public URLHandler(final UIController controller) {
|
|
61
|
+ this.controller = controller;
|
|
62
|
+ this.config = IdentityManager.getGlobalConfig();
|
|
63
|
+ this.desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
|
62
|
64
|
}
|
63
|
65
|
|
64
|
66
|
/**
|
65
|
67
|
* Gets an instance of URLHandler.
|
66
|
68
|
*
|
67
|
69
|
* @return URLHandler instance
|
|
70
|
+ * @deprecated This will return a URLHandler for a random UI which may not
|
|
71
|
+ * implement the required methods. It will probably break. Users of this
|
|
72
|
+ * class must create instances of URLHandler directly with an appropriate
|
|
73
|
+ * UIController.
|
68
|
74
|
*/
|
|
75
|
+ @Deprecated
|
69
|
76
|
public static URLHandler getURLHander() {
|
70
|
|
- synchronized (ME) {
|
71
|
|
- return ME;
|
72
|
|
- }
|
|
77
|
+ return new URLHandler(Main.getUI());
|
73
|
78
|
}
|
74
|
79
|
|
75
|
80
|
/**
|
|
@@ -132,7 +137,7 @@ public class URLHandler {
|
132
|
137
|
}
|
133
|
138
|
|
134
|
139
|
if (!config.hasOptionString("protocol", uri.getScheme().toLowerCase())) {
|
135
|
|
- Main.getUI().showURLDialog(uri);
|
|
140
|
+ controller.showURLDialog(uri);
|
136
|
141
|
return;
|
137
|
142
|
}
|
138
|
143
|
|
|
@@ -161,7 +166,7 @@ public class URLHandler {
|
161
|
166
|
*
|
162
|
167
|
* @return Substituted command
|
163
|
168
|
*/
|
164
|
|
- public String substituteParams(final URI url, final String command) {
|
|
169
|
+ public static String substituteParams(final URI url, final String command) {
|
165
|
170
|
final String userInfo = url.getUserInfo();
|
166
|
171
|
String fragment = "";
|
167
|
172
|
String host = "";
|
|
@@ -192,7 +197,7 @@ public class URLHandler {
|
192
|
197
|
if (url.getQuery() != null) {
|
193
|
198
|
query = url.getQuery();
|
194
|
199
|
}
|
195
|
|
-
|
|
200
|
+
|
196
|
201
|
if (url.getPort() > 0) {
|
197
|
202
|
port = String.valueOf(url.getPort());
|
198
|
203
|
}
|
|
@@ -233,12 +238,12 @@ public class URLHandler {
|
233
|
238
|
ex.getMessage());
|
234
|
239
|
}
|
235
|
240
|
}
|
236
|
|
-
|
|
241
|
+
|
237
|
242
|
/**
|
238
|
243
|
* Parses the specified command into an array of arguments. Arguments are
|
239
|
244
|
* separated by spaces. Multi-word arguments may be specified by starting
|
240
|
245
|
* the argument with a quote (") and finishing it with a quote (").
|
241
|
|
- *
|
|
246
|
+ *
|
242
|
247
|
* @param command The command to parse
|
243
|
248
|
* @return An array of arguments corresponding to the command
|
244
|
249
|
*/
|
|
@@ -246,7 +251,7 @@ public class URLHandler {
|
246
|
251
|
final List<String> args = new ArrayList<String>();
|
247
|
252
|
final StringBuilder builder = new StringBuilder();
|
248
|
253
|
boolean inquote = false;
|
249
|
|
-
|
|
254
|
+
|
250
|
255
|
for (String word : command.split(" ")) {
|
251
|
256
|
if (word.endsWith("\"") && inquote) {
|
252
|
257
|
args.add(builder.toString() + ' ' + word.substring(0, word.length() - 1));
|
|
@@ -256,7 +261,7 @@ public class URLHandler {
|
256
|
261
|
if (builder.length() > 0) {
|
257
|
262
|
builder.append(' ');
|
258
|
263
|
}
|
259
|
|
-
|
|
264
|
+
|
260
|
265
|
builder.append(word);
|
261
|
266
|
} else if (word.startsWith("\"") && !word.endsWith("\"")) {
|
262
|
267
|
inquote = true;
|
|
@@ -271,7 +276,7 @@ public class URLHandler {
|
271
|
276
|
args.add(word);
|
272
|
277
|
}
|
273
|
278
|
}
|
274
|
|
-
|
|
279
|
+
|
275
|
280
|
return args.toArray(new String[args.size()]);
|
276
|
281
|
}
|
277
|
282
|
|