|
@@ -1,5 +1,5 @@
|
1
|
1
|
/*
|
2
|
|
- * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
|
|
2
|
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
|
3
|
3
|
*
|
4
|
4
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
5
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -33,7 +33,9 @@ import java.io.IOException;
|
33
|
33
|
import java.net.URI;
|
34
|
34
|
import java.net.URISyntaxException;
|
35
|
35
|
import java.net.URL;
|
|
36
|
+import java.util.ArrayList;
|
36
|
37
|
import java.util.Date;
|
|
38
|
+import java.util.List;
|
37
|
39
|
|
38
|
40
|
/** Handles URLs. */
|
39
|
41
|
public class URLHandler {
|
|
@@ -127,13 +129,7 @@ public class URLHandler {
|
127
|
129
|
}
|
128
|
130
|
}
|
129
|
131
|
|
130
|
|
- if (!config.hasOption("protocol", uri.getScheme())) {
|
131
|
|
- Main.getUI().showURLDialog(uri);
|
132
|
|
- return;
|
133
|
|
- }
|
134
|
|
-
|
135
|
|
- final String command =
|
136
|
|
- config.getOption("protocol", uri.getScheme(), "");
|
|
132
|
+ final String command = config.getOption("protocol", uri.getScheme(), "");
|
137
|
133
|
|
138
|
134
|
if (command.isEmpty()) {
|
139
|
135
|
Main.getUI().showURLDialog(uri);
|
|
@@ -229,21 +225,50 @@ public class URLHandler {
|
229
|
225
|
* @param command Application and arguments
|
230
|
226
|
*/
|
231
|
227
|
private void execApp(final String command) {
|
232
|
|
- String[] commandLine;
|
233
|
|
-
|
234
|
|
- if (System.getProperty("os.name").startsWith("Windows")) {
|
235
|
|
- commandLine = new String[]{"cmd.exe", command};
|
236
|
|
- } else {
|
237
|
|
- commandLine = new String[]{"/bin/sh", "-c", command};
|
238
|
|
- }
|
239
|
|
-
|
240
|
228
|
try {
|
241
|
|
- Runtime.getRuntime().exec(commandLine);
|
|
229
|
+ Runtime.getRuntime().exec(parseArguments(command));
|
242
|
230
|
} catch (IOException ex) {
|
243
|
|
- Logger.userError(ErrorLevel.LOW,
|
244
|
|
- "Unable to run application: " + ex.getMessage(), ex);
|
|
231
|
+ Logger.userError(ErrorLevel.LOW, "Unable to run application: ",
|
|
232
|
+ ex.getMessage());
|
245
|
233
|
}
|
246
|
234
|
}
|
|
235
|
+
|
|
236
|
+ /**
|
|
237
|
+ * Parses the specified command into an array of arguments. Arguments are
|
|
238
|
+ * separated by spaces. Multi-word arguments may be specified by starting
|
|
239
|
+ * the argument with a quote (") and finishing it with a quote (").
|
|
240
|
+ *
|
|
241
|
+ * @param command The command to parse
|
|
242
|
+ * @return An array of arguments corresponding to the command
|
|
243
|
+ */
|
|
244
|
+ protected static String[] parseArguments(final String command) {
|
|
245
|
+ final List<String> args = new ArrayList<String>();
|
|
246
|
+ final StringBuilder builder = new StringBuilder();
|
|
247
|
+ boolean inquote = false;
|
|
248
|
+
|
|
249
|
+ for (String word : command.split(" ")) {
|
|
250
|
+ if (word.endsWith("\"") && inquote) {
|
|
251
|
+ args.add(builder.toString() + ' ' + word.substring(0, word.length() - 1));
|
|
252
|
+ builder.delete(0, builder.length());
|
|
253
|
+ inquote = false;
|
|
254
|
+ } else if (inquote) {
|
|
255
|
+ if (builder.length() > 0) {
|
|
256
|
+ builder.append(' ');
|
|
257
|
+ }
|
|
258
|
+
|
|
259
|
+ builder.append(word);
|
|
260
|
+ } else if (word.startsWith("\"") && !word.endsWith("\"")) {
|
|
261
|
+ inquote = true;
|
|
262
|
+ builder.append(word.substring(1));
|
|
263
|
+ } else if (word.startsWith("\"") && word.endsWith("\"")) {
|
|
264
|
+ args.add(word.substring(1, word.length() - 1));
|
|
265
|
+ } else {
|
|
266
|
+ args.add(word);
|
|
267
|
+ }
|
|
268
|
+ }
|
|
269
|
+
|
|
270
|
+ return args.toArray(new String[0]);
|
|
271
|
+ }
|
247
|
272
|
|
248
|
273
|
/**
|
249
|
274
|
* Opens the specified URL in the users browser.
|
|
@@ -260,7 +285,11 @@ public class URLHandler {
|
260
|
285
|
"Unable to open URL: " + ex.getMessage());
|
261
|
286
|
}
|
262
|
287
|
} else {
|
263
|
|
- Logger.userError(ErrorLevel.LOW, "Unable to open your browser.");
|
|
288
|
+ Logger.userError(ErrorLevel.LOW,
|
|
289
|
+ "Unable to open your browser: Your desktop enviroment is " +
|
|
290
|
+ "not supported, please go to the URL Handlers section of " +
|
|
291
|
+ "the preferences dialog and set the path to your browser " +
|
|
292
|
+ "manually");
|
264
|
293
|
}
|
265
|
294
|
}
|
266
|
295
|
|
|
@@ -278,7 +307,11 @@ public class URLHandler {
|
278
|
307
|
"Unable to open URL: " + ex.getMessage());
|
279
|
308
|
}
|
280
|
309
|
} else {
|
281
|
|
- Logger.userError(ErrorLevel.LOW, "Unable to open your mail client.");
|
|
310
|
+ Logger.userError(ErrorLevel.LOW,
|
|
311
|
+ "Unable to open your mail client: Your desktop enviroment is " +
|
|
312
|
+ "not supported, please go to the URL Handlers section of " +
|
|
313
|
+ "the preferences dialog and set the path to your browser " +
|
|
314
|
+ "manually");
|
282
|
315
|
}
|
283
|
316
|
}
|
284
|
317
|
}
|