1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import java.io.File; |
24 |
|
import java.io.IOException; |
25 |
|
import java.lang.reflect.Constructor; |
26 |
|
import java.lang.reflect.Field; |
27 |
|
import java.lang.reflect.InvocationTargetException; |
28 |
|
import java.lang.reflect.Method; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@author |
79 |
|
|
80 |
|
@version |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 279 (279) |
Complexity: 77 |
Complexity Density: 0.33 |
|
82 |
|
public class BrowserLauncher |
83 |
|
{ |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
private static int jvm; |
90 |
|
|
91 |
|
|
92 |
|
private static Object browser; |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
private static boolean loadedWithoutErrors; |
102 |
|
|
103 |
|
|
104 |
|
private static Class mrjFileUtilsClass; |
105 |
|
|
106 |
|
|
107 |
|
private static Class mrjOSTypeClass; |
108 |
|
|
109 |
|
|
110 |
|
private static Class aeDescClass; |
111 |
|
|
112 |
|
|
113 |
|
private static Constructor aeTargetConstructor; |
114 |
|
|
115 |
|
|
116 |
|
private static Constructor appleEventConstructor; |
117 |
|
|
118 |
|
|
119 |
|
private static Constructor aeDescConstructor; |
120 |
|
|
121 |
|
|
122 |
|
private static Method findFolder; |
123 |
|
|
124 |
|
|
125 |
|
private static Method getFileCreator; |
126 |
|
|
127 |
|
|
128 |
|
private static Method getFileType; |
129 |
|
|
130 |
|
|
131 |
|
private static Method openURL; |
132 |
|
|
133 |
|
|
134 |
|
private static Method makeOSType; |
135 |
|
|
136 |
|
|
137 |
|
private static Method putParameter; |
138 |
|
|
139 |
|
|
140 |
|
private static Method sendNoReply; |
141 |
|
|
142 |
|
|
143 |
|
private static Object kSystemFolderType; |
144 |
|
|
145 |
|
|
146 |
|
private static Integer keyDirectObject; |
147 |
|
|
148 |
|
|
149 |
|
private static Integer kAutoGenerateReturnID; |
150 |
|
|
151 |
|
|
152 |
|
private static Integer kAnyTransactionID; |
153 |
|
|
154 |
|
|
155 |
|
private static Object linkage; |
156 |
|
|
157 |
|
|
158 |
|
private static final String JDirect_MacOSX = "/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/HIToolbox"; |
159 |
|
|
160 |
|
|
161 |
|
private static final int MRJ_2_0 = 0; |
162 |
|
|
163 |
|
|
164 |
|
private static final int MRJ_2_1 = 1; |
165 |
|
|
166 |
|
|
167 |
|
private static final int MRJ_3_0 = 3; |
168 |
|
|
169 |
|
|
170 |
|
private static final int MRJ_3_1 = 4; |
171 |
|
|
172 |
|
|
173 |
|
private static final int WINDOWS_NT = 5; |
174 |
|
|
175 |
|
|
176 |
|
private static final int WINDOWS_9x = 6; |
177 |
|
|
178 |
|
|
179 |
|
private static final int OTHER = -1; |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
private static final String FINDER_TYPE = "FNDR"; |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
private static final String FINDER_CREATOR = "MACS"; |
192 |
|
|
193 |
|
|
194 |
|
private static final String GURL_EVENT = "GURL"; |
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
private static final String FIRST_WINDOWS_PARAMETER = "/c"; |
201 |
|
|
202 |
|
|
203 |
|
private static final String SECOND_WINDOWS_PARAMETER = "start"; |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
private static final String THIRD_WINDOWS_PARAMETER = "\"\""; |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
private static final String NETSCAPE_REMOTE_PARAMETER = "-remote"; |
217 |
|
|
218 |
|
private static final String NETSCAPE_OPEN_PARAMETER_START = "openURL("; |
219 |
|
|
220 |
|
private static final String NETSCAPE_OPEN_NEW_WINDOW = ", new-window"; |
221 |
|
|
222 |
|
private static final String NETSCAPE_OPEN_PARAMETER_END = ")"; |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
private static String errorMessage; |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 12 |
Complexity Density: 0.41 |
|
234 |
0 |
static... |
235 |
|
{ |
236 |
|
|
237 |
0 |
loadedWithoutErrors = true; |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
{ |
245 |
0 |
String osName = System.getProperty("os.name"); |
246 |
|
|
247 |
0 |
if (osName.startsWith("Mac OS")) |
248 |
|
{ |
249 |
0 |
String mrjVersion = System.getProperty("mrj.version"); |
250 |
0 |
String majorMRJVersion; |
251 |
0 |
if (mrjVersion == null) |
252 |
|
{ |
253 |
|
|
254 |
0 |
majorMRJVersion = "3.1"; |
255 |
|
} |
256 |
|
else |
257 |
|
{ |
258 |
0 |
majorMRJVersion = mrjVersion.substring(0, 3); |
259 |
|
} |
260 |
|
|
261 |
0 |
try |
262 |
|
{ |
263 |
0 |
double version = Double.valueOf(majorMRJVersion).doubleValue(); |
264 |
|
|
265 |
0 |
if (version == 2) |
266 |
|
{ |
267 |
0 |
jvm = MRJ_2_0; |
268 |
|
} |
269 |
0 |
else if ((version >= 2.1) && (version < 3)) |
270 |
|
{ |
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
0 |
jvm = MRJ_2_1; |
276 |
|
} |
277 |
0 |
else if (version == 3.0) |
278 |
|
{ |
279 |
0 |
jvm = MRJ_3_0; |
280 |
|
} |
281 |
0 |
else if (version >= 3.1) |
282 |
|
{ |
283 |
|
|
284 |
0 |
jvm = MRJ_3_1; |
285 |
|
} |
286 |
|
else |
287 |
|
{ |
288 |
0 |
loadedWithoutErrors = false; |
289 |
0 |
errorMessage = "Unsupported MRJ version: " + version; |
290 |
|
} |
291 |
|
} catch (NumberFormatException nfe) |
292 |
|
{ |
293 |
0 |
loadedWithoutErrors = false; |
294 |
0 |
errorMessage = "Invalid MRJ version: " + mrjVersion; |
295 |
|
} |
296 |
|
} |
297 |
0 |
else if (osName.startsWith("Windows")) |
298 |
|
{ |
299 |
0 |
if (osName.indexOf("9") != -1) |
300 |
|
{ |
301 |
0 |
jvm = WINDOWS_9x; |
302 |
|
} |
303 |
|
else |
304 |
|
{ |
305 |
0 |
jvm = WINDOWS_NT; |
306 |
|
} |
307 |
|
} |
308 |
|
else |
309 |
|
{ |
310 |
0 |
jvm = OTHER; |
311 |
|
} |
312 |
|
|
313 |
0 |
if (loadedWithoutErrors) |
314 |
|
{ |
315 |
0 |
loadedWithoutErrors = loadClasses(); |
316 |
|
} |
317 |
|
} |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
323 |
0 |
private BrowserLauncher()... |
324 |
|
{ |
325 |
|
} |
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
@return |
332 |
|
|
333 |
|
|
|
|
| 0% |
Uncovered Elements: 77 (77) |
Complexity: 21 |
Complexity Density: 0.27 |
|
334 |
0 |
private static boolean loadClasses()... |
335 |
|
{ |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
{ |
342 |
0 |
switch (jvm) |
343 |
|
{ |
344 |
0 |
case MRJ_2_0: |
345 |
|
|
346 |
0 |
try |
347 |
|
{ |
348 |
0 |
Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget"); |
349 |
0 |
Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils"); |
350 |
0 |
Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent"); |
351 |
0 |
Class aeClass = Class.forName("com.apple.MacOS.ae"); |
352 |
0 |
aeDescClass = Class.forName("com.apple.MacOS.AEDesc"); |
353 |
|
|
354 |
0 |
aeTargetConstructor = aeTargetClass |
355 |
|
.getDeclaredConstructor(new Class[] |
356 |
|
{ int.class }); |
357 |
0 |
appleEventConstructor = appleEventClass |
358 |
|
.getDeclaredConstructor(new Class[] |
359 |
|
{ int.class, int.class, aeTargetClass, int.class, |
360 |
|
int.class }); |
361 |
0 |
aeDescConstructor = aeDescClass |
362 |
|
.getDeclaredConstructor(new Class[] |
363 |
|
{ String.class }); |
364 |
|
|
365 |
0 |
makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", |
366 |
|
new Class[] |
367 |
|
{ String.class }); |
368 |
0 |
putParameter = appleEventClass.getDeclaredMethod("putParameter", |
369 |
|
new Class[] |
370 |
|
{ int.class, aeDescClass }); |
371 |
0 |
sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", |
372 |
|
new Class[] {}); |
373 |
|
|
374 |
0 |
Field keyDirectObjectField = aeClass |
375 |
|
.getDeclaredField("keyDirectObject"); |
376 |
0 |
keyDirectObject = (Integer) keyDirectObjectField.get(null); |
377 |
|
|
378 |
0 |
Field autoGenerateReturnIDField = appleEventClass |
379 |
|
.getDeclaredField("kAutoGenerateReturnID"); |
380 |
0 |
kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField |
381 |
|
.get(null); |
382 |
|
|
383 |
0 |
Field anyTransactionIDField = appleEventClass |
384 |
|
.getDeclaredField("kAnyTransactionID"); |
385 |
0 |
kAnyTransactionID = (Integer) anyTransactionIDField.get(null); |
386 |
|
} catch (ClassNotFoundException cnfe) |
387 |
|
{ |
388 |
0 |
errorMessage = cnfe.getMessage(); |
389 |
|
|
390 |
0 |
return false; |
391 |
|
} catch (NoSuchMethodException nsme) |
392 |
|
{ |
393 |
0 |
errorMessage = nsme.getMessage(); |
394 |
|
|
395 |
0 |
return false; |
396 |
|
} catch (NoSuchFieldException nsfe) |
397 |
|
{ |
398 |
0 |
errorMessage = nsfe.getMessage(); |
399 |
|
|
400 |
0 |
return false; |
401 |
|
} catch (IllegalAccessException iae) |
402 |
|
{ |
403 |
0 |
errorMessage = iae.getMessage(); |
404 |
|
|
405 |
0 |
return false; |
406 |
|
} |
407 |
|
|
408 |
0 |
break; |
409 |
|
|
410 |
0 |
case MRJ_2_1: |
411 |
|
|
412 |
0 |
try |
413 |
|
{ |
414 |
0 |
mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils"); |
415 |
0 |
mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType"); |
416 |
|
|
417 |
0 |
Field systemFolderField = mrjFileUtilsClass |
418 |
|
.getDeclaredField("kSystemFolderType"); |
419 |
0 |
kSystemFolderType = systemFolderField.get(null); |
420 |
0 |
findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", |
421 |
|
new Class[] |
422 |
|
{ mrjOSTypeClass }); |
423 |
0 |
getFileCreator = mrjFileUtilsClass |
424 |
|
.getDeclaredMethod("getFileCreator", new Class[] |
425 |
|
{ File.class }); |
426 |
0 |
getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", |
427 |
|
new Class[] |
428 |
|
{ File.class }); |
429 |
|
} catch (ClassNotFoundException cnfe) |
430 |
|
{ |
431 |
0 |
errorMessage = cnfe.getMessage(); |
432 |
|
|
433 |
0 |
return false; |
434 |
|
} catch (NoSuchFieldException nsfe) |
435 |
|
{ |
436 |
0 |
errorMessage = nsfe.getMessage(); |
437 |
|
|
438 |
0 |
return false; |
439 |
|
} catch (NoSuchMethodException nsme) |
440 |
|
{ |
441 |
0 |
errorMessage = nsme.getMessage(); |
442 |
|
|
443 |
0 |
return false; |
444 |
|
} catch (SecurityException se) |
445 |
|
{ |
446 |
0 |
errorMessage = se.getMessage(); |
447 |
|
|
448 |
0 |
return false; |
449 |
|
} catch (IllegalAccessException iae) |
450 |
|
{ |
451 |
0 |
errorMessage = iae.getMessage(); |
452 |
|
|
453 |
0 |
return false; |
454 |
|
} |
455 |
|
|
456 |
0 |
break; |
457 |
|
|
458 |
0 |
case MRJ_3_0: |
459 |
|
|
460 |
0 |
try |
461 |
|
{ |
462 |
0 |
Class linker = Class.forName("com.apple.mrj.jdirect.Linker"); |
463 |
0 |
Constructor constructor = linker |
464 |
|
.getConstructor(new Class[] |
465 |
|
{ Class.class }); |
466 |
0 |
linkage = constructor |
467 |
|
.newInstance(new Object[] |
468 |
|
{ BrowserLauncher.class }); |
469 |
|
} catch (ClassNotFoundException cnfe) |
470 |
|
{ |
471 |
0 |
errorMessage = cnfe.getMessage(); |
472 |
|
|
473 |
0 |
return false; |
474 |
|
} catch (NoSuchMethodException nsme) |
475 |
|
{ |
476 |
0 |
errorMessage = nsme.getMessage(); |
477 |
|
|
478 |
0 |
return false; |
479 |
|
} catch (InvocationTargetException ite) |
480 |
|
{ |
481 |
0 |
errorMessage = ite.getMessage(); |
482 |
|
|
483 |
0 |
return false; |
484 |
|
} catch (InstantiationException ie) |
485 |
|
{ |
486 |
0 |
errorMessage = ie.getMessage(); |
487 |
|
|
488 |
0 |
return false; |
489 |
|
} catch (IllegalAccessException iae) |
490 |
|
{ |
491 |
0 |
errorMessage = iae.getMessage(); |
492 |
|
|
493 |
0 |
return false; |
494 |
|
} |
495 |
|
|
496 |
0 |
break; |
497 |
|
|
498 |
0 |
case MRJ_3_1: |
499 |
|
|
500 |
0 |
try |
501 |
|
{ |
502 |
0 |
mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils"); |
503 |
0 |
openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", |
504 |
|
new Class[] |
505 |
|
{ String.class }); |
506 |
|
} catch (ClassNotFoundException cnfe) |
507 |
|
{ |
508 |
0 |
errorMessage = cnfe.getMessage(); |
509 |
|
|
510 |
0 |
return false; |
511 |
|
} catch (NoSuchMethodException nsme) |
512 |
|
{ |
513 |
0 |
errorMessage = nsme.getMessage(); |
514 |
|
|
515 |
0 |
return false; |
516 |
|
} |
517 |
|
|
518 |
0 |
break; |
519 |
|
|
520 |
0 |
default: |
521 |
0 |
break; |
522 |
|
} |
523 |
|
|
524 |
|
} |
525 |
0 |
return true; |
526 |
|
} |
527 |
|
|
528 |
|
|
529 |
|
|
530 |
|
|
531 |
|
|
532 |
|
|
533 |
|
@return |
534 |
|
|
535 |
|
|
536 |
|
|
537 |
|
|
538 |
|
|
|
|
| 0% |
Uncovered Elements: 79 (79) |
Complexity: 22 |
Complexity Density: 0.32 |
|
539 |
0 |
private static Object locateBrowser()... |
540 |
|
{ |
541 |
|
|
542 |
|
|
543 |
|
|
544 |
|
|
545 |
|
{ |
546 |
0 |
if (browser != null) |
547 |
|
{ |
548 |
0 |
return browser; |
549 |
|
} |
550 |
|
|
551 |
0 |
switch (jvm) |
552 |
|
{ |
553 |
0 |
case MRJ_2_0: |
554 |
|
|
555 |
0 |
try |
556 |
|
{ |
557 |
0 |
Integer finderCreatorCode = (Integer) makeOSType.invoke(null, |
558 |
|
new Object[] |
559 |
|
{ FINDER_CREATOR }); |
560 |
0 |
Object aeTarget = aeTargetConstructor |
561 |
|
.newInstance(new Object[] |
562 |
|
{ finderCreatorCode }); |
563 |
0 |
Integer gurlType = (Integer) makeOSType.invoke(null, |
564 |
|
new Object[] |
565 |
|
{ GURL_EVENT }); |
566 |
0 |
Object appleEvent = appleEventConstructor |
567 |
|
.newInstance(new Object[] |
568 |
|
{ gurlType, gurlType, aeTarget, kAutoGenerateReturnID, |
569 |
|
kAnyTransactionID }); |
570 |
|
|
571 |
|
|
572 |
|
|
573 |
|
|
574 |
|
|
575 |
|
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
0 |
return appleEvent; |
580 |
|
} catch (IllegalAccessException iae) |
581 |
|
{ |
582 |
0 |
browser = null; |
583 |
0 |
errorMessage = iae.getMessage(); |
584 |
|
|
585 |
0 |
return browser; |
586 |
|
} catch (InstantiationException ie) |
587 |
|
{ |
588 |
0 |
browser = null; |
589 |
0 |
errorMessage = ie.getMessage(); |
590 |
|
|
591 |
0 |
return browser; |
592 |
|
} catch (InvocationTargetException ite) |
593 |
|
{ |
594 |
0 |
browser = null; |
595 |
0 |
errorMessage = ite.getMessage(); |
596 |
|
|
597 |
0 |
return browser; |
598 |
|
} |
599 |
|
|
600 |
0 |
case MRJ_2_1: |
601 |
|
|
602 |
0 |
File systemFolder; |
603 |
|
|
604 |
0 |
try |
605 |
|
{ |
606 |
0 |
systemFolder = (File) findFolder.invoke(null, |
607 |
|
new Object[] |
608 |
|
{ kSystemFolderType }); |
609 |
|
} catch (IllegalArgumentException iare) |
610 |
|
{ |
611 |
0 |
browser = null; |
612 |
0 |
errorMessage = iare.getMessage(); |
613 |
|
|
614 |
0 |
return browser; |
615 |
|
} catch (IllegalAccessException iae) |
616 |
|
{ |
617 |
0 |
browser = null; |
618 |
0 |
errorMessage = iae.getMessage(); |
619 |
|
|
620 |
0 |
return browser; |
621 |
|
} catch (InvocationTargetException ite) |
622 |
|
{ |
623 |
0 |
browser = null; |
624 |
0 |
errorMessage = ite.getTargetException().getClass() + ": " |
625 |
|
+ ite.getTargetException().getMessage(); |
626 |
|
|
627 |
0 |
return browser; |
628 |
|
} |
629 |
|
|
630 |
0 |
String[] systemFolderFiles = systemFolder.list(); |
631 |
|
|
632 |
|
|
633 |
0 |
for (int i = 0; i < systemFolderFiles.length; i++) |
634 |
|
{ |
635 |
0 |
try |
636 |
|
{ |
637 |
0 |
File file = new File(systemFolder, systemFolderFiles[i]); |
638 |
|
|
639 |
0 |
if (!file.isFile()) |
640 |
|
{ |
641 |
0 |
continue; |
642 |
|
} |
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
0 |
Object fileType = getFileType.invoke(null, new Object[] { file }); |
650 |
|
|
651 |
0 |
if (FINDER_TYPE.equals(fileType.toString())) |
652 |
|
{ |
653 |
0 |
Object fileCreator = getFileCreator.invoke(null, |
654 |
|
new Object[] |
655 |
|
{ file }); |
656 |
|
|
657 |
0 |
if (FINDER_CREATOR.equals(fileCreator.toString())) |
658 |
|
{ |
659 |
0 |
browser = file.toString(); |
660 |
|
|
661 |
0 |
return browser; |
662 |
|
} |
663 |
|
} |
664 |
|
} catch (IllegalArgumentException iare) |
665 |
|
{ |
666 |
0 |
errorMessage = iare.getMessage(); |
667 |
|
|
668 |
0 |
return null; |
669 |
|
} catch (IllegalAccessException iae) |
670 |
|
{ |
671 |
0 |
browser = null; |
672 |
0 |
errorMessage = iae.getMessage(); |
673 |
|
|
674 |
0 |
return browser; |
675 |
|
} catch (InvocationTargetException ite) |
676 |
|
{ |
677 |
0 |
browser = null; |
678 |
0 |
errorMessage = ite.getTargetException().getClass() + ": " |
679 |
|
+ ite.getTargetException().getMessage(); |
680 |
|
|
681 |
0 |
return browser; |
682 |
|
} |
683 |
|
} |
684 |
|
|
685 |
0 |
browser = null; |
686 |
|
|
687 |
0 |
break; |
688 |
|
|
689 |
0 |
case MRJ_3_0: |
690 |
0 |
case MRJ_3_1: |
691 |
0 |
browser = ""; |
692 |
|
|
693 |
0 |
break; |
694 |
|
|
695 |
0 |
case WINDOWS_NT: |
696 |
0 |
browser = "cmd.exe"; |
697 |
|
|
698 |
0 |
break; |
699 |
|
|
700 |
0 |
case WINDOWS_9x: |
701 |
0 |
browser = "command.com"; |
702 |
|
|
703 |
0 |
break; |
704 |
|
|
705 |
0 |
case OTHER: |
706 |
0 |
default: |
707 |
0 |
browser = jalview.bin.Cache.getDefault("DEFAULT_BROWSER", "firefox"); |
708 |
|
|
709 |
0 |
break; |
710 |
|
} |
711 |
|
|
712 |
|
} |
713 |
|
|
714 |
0 |
return browser; |
715 |
|
|
716 |
|
} |
717 |
|
|
718 |
|
|
719 |
|
|
720 |
|
|
721 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
722 |
0 |
public static void resetBrowser()... |
723 |
|
{ |
724 |
0 |
browser = null; |
725 |
|
} |
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
|
730 |
|
@param |
731 |
|
|
732 |
|
@throws |
733 |
|
|
734 |
|
|
|
|
| 0% |
Uncovered Elements: 69 (69) |
Complexity: 20 |
Complexity Density: 0.34 |
|
735 |
0 |
public static void openURL(String url) throws IOException... |
736 |
|
{ |
737 |
|
|
738 |
|
|
739 |
|
|
740 |
|
|
741 |
|
|
742 |
|
|
743 |
|
|
744 |
|
|
745 |
|
|
746 |
|
{ |
747 |
|
|
748 |
0 |
if (!loadedWithoutErrors) |
749 |
|
{ |
750 |
0 |
throw new IOException(MessageManager |
751 |
|
.formatMessage("exception.browser_not_found", new String[] |
752 |
|
{ errorMessage })); |
753 |
|
} |
754 |
|
|
755 |
0 |
Object browser = locateBrowser(); |
756 |
|
|
757 |
0 |
if (browser == null) |
758 |
|
{ |
759 |
0 |
throw new IOException(MessageManager.formatMessage( |
760 |
|
"exception.browser_unable_to_locate", new String[] |
761 |
|
{ errorMessage })); |
762 |
|
} |
763 |
|
|
764 |
0 |
switch (jvm) |
765 |
|
{ |
766 |
0 |
case MRJ_2_0: |
767 |
|
|
768 |
0 |
Object aeDesc = null; |
769 |
|
|
770 |
0 |
try |
771 |
|
{ |
772 |
0 |
aeDesc = aeDescConstructor.newInstance(new Object[] { url }); |
773 |
0 |
putParameter.invoke(browser, |
774 |
|
new Object[] |
775 |
|
{ keyDirectObject, aeDesc }); |
776 |
0 |
sendNoReply.invoke(browser, new Object[] {}); |
777 |
|
} catch (InvocationTargetException ite) |
778 |
|
{ |
779 |
0 |
throw new IOException(MessageManager.formatMessage( |
780 |
|
"exception.invocation_target_exception_creating_aedesc", |
781 |
|
new String[] |
782 |
|
{ ite.getMessage() })); |
783 |
|
} catch (IllegalAccessException iae) |
784 |
|
{ |
785 |
0 |
throw new IOException(MessageManager.formatMessage( |
786 |
|
"exception.illegal_access_building_apple_evt", new String[] |
787 |
|
{ iae.getMessage() })); |
788 |
|
} catch (InstantiationException ie) |
789 |
|
{ |
790 |
0 |
throw new IOException(MessageManager.formatMessage( |
791 |
|
"exception.illegal_access_building_apple_evt", new String[] |
792 |
|
{ ie.getMessage() })); |
793 |
|
} finally |
794 |
|
{ |
795 |
0 |
aeDesc = null; |
796 |
0 |
browser = null; |
797 |
|
} |
798 |
|
|
799 |
0 |
break; |
800 |
|
|
801 |
0 |
case MRJ_2_1: |
802 |
0 |
Runtime.getRuntime().exec(new String[] { (String) browser, url }); |
803 |
|
|
804 |
0 |
break; |
805 |
|
|
806 |
0 |
case MRJ_3_0: |
807 |
|
|
808 |
0 |
int[] instance = new int[1]; |
809 |
0 |
int result = ICStart(instance, 0); |
810 |
|
|
811 |
0 |
if (result == 0) |
812 |
|
{ |
813 |
0 |
int[] selectionStart = new int[] { 0 }; |
814 |
0 |
byte[] urlBytes = url.getBytes(); |
815 |
0 |
int[] selectionEnd = new int[] { urlBytes.length }; |
816 |
0 |
result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes, |
817 |
|
urlBytes.length, selectionStart, selectionEnd); |
818 |
|
|
819 |
0 |
if (result == 0) |
820 |
|
{ |
821 |
|
|
822 |
|
|
823 |
0 |
ICStop(instance); |
824 |
|
} |
825 |
|
else |
826 |
|
{ |
827 |
0 |
throw new IOException(MessageManager.formatMessage( |
828 |
|
"exception.unable_to_launch_url", new String[] |
829 |
|
{ Integer.valueOf(result).toString() })); |
830 |
|
} |
831 |
|
} |
832 |
|
else |
833 |
|
{ |
834 |
0 |
throw new IOException(MessageManager.formatMessage( |
835 |
|
"exception.unable_to_create_internet_config", new String[] |
836 |
|
{ Integer.valueOf(result).toString() })); |
837 |
|
} |
838 |
|
|
839 |
0 |
break; |
840 |
|
|
841 |
0 |
case MRJ_3_1: |
842 |
|
|
843 |
0 |
try |
844 |
|
{ |
845 |
0 |
openURL.invoke(null, new Object[] { url }); |
846 |
|
} catch (InvocationTargetException ite) |
847 |
|
{ |
848 |
0 |
throw new IOException(MessageManager.formatMessage( |
849 |
|
"exception.invocation_target_calling_url", new String[] |
850 |
|
{ ite.getMessage() })); |
851 |
|
} catch (IllegalAccessException iae) |
852 |
|
{ |
853 |
0 |
throw new IOException(MessageManager.formatMessage( |
854 |
|
"exception.illegal_access_calling_url", new String[] |
855 |
|
{ iae.getMessage() })); |
856 |
|
} |
857 |
|
|
858 |
0 |
break; |
859 |
|
|
860 |
0 |
case WINDOWS_NT: |
861 |
0 |
case WINDOWS_9x: |
862 |
|
|
863 |
|
|
864 |
|
|
865 |
0 |
Process process = Runtime.getRuntime() |
866 |
|
.exec(new String[] |
867 |
|
{ (String) browser, FIRST_WINDOWS_PARAMETER, |
868 |
|
SECOND_WINDOWS_PARAMETER, THIRD_WINDOWS_PARAMETER, |
869 |
|
'"' + url + '"' }); |
870 |
|
|
871 |
|
|
872 |
|
|
873 |
|
|
874 |
0 |
try |
875 |
|
{ |
876 |
0 |
process.waitFor(); |
877 |
0 |
process.exitValue(); |
878 |
|
} catch (InterruptedException ie) |
879 |
|
{ |
880 |
0 |
throw new IOException(MessageManager.formatMessage( |
881 |
|
"exception.interrupted_launching_browser", new String[] |
882 |
|
{ ie.getMessage() })); |
883 |
|
} |
884 |
|
|
885 |
0 |
break; |
886 |
|
|
887 |
0 |
case OTHER: |
888 |
|
|
889 |
|
|
890 |
|
|
891 |
|
|
892 |
|
|
893 |
|
|
894 |
|
|
895 |
|
|
896 |
|
|
897 |
|
|
898 |
|
|
899 |
|
|
900 |
0 |
process = Runtime.getRuntime() |
901 |
|
.exec(new String[] |
902 |
|
{ (String) browser, NETSCAPE_REMOTE_PARAMETER, |
903 |
|
|
904 |
|
NETSCAPE_OPEN_PARAMETER_START + url |
905 |
|
+ NETSCAPE_OPEN_NEW_WINDOW |
906 |
|
+ NETSCAPE_OPEN_PARAMETER_END }); |
907 |
|
|
908 |
0 |
try |
909 |
|
{ |
910 |
0 |
int exitCode = process.waitFor(); |
911 |
|
|
912 |
0 |
if (exitCode != 0) |
913 |
|
{ |
914 |
0 |
Runtime.getRuntime().exec(new String[] { (String) browser, url }); |
915 |
|
} |
916 |
|
} catch (InterruptedException ie) |
917 |
|
{ |
918 |
0 |
throw new IOException(MessageManager.formatMessage( |
919 |
|
"exception.interrupted_launching_browser", new String[] |
920 |
|
{ ie.getMessage() })); |
921 |
|
} |
922 |
|
|
923 |
0 |
break; |
924 |
|
|
925 |
0 |
default: |
926 |
|
|
927 |
|
|
928 |
|
|
929 |
0 |
Runtime.getRuntime().exec(new String[] { (String) browser, url }); |
930 |
|
|
931 |
0 |
break; |
932 |
|
} |
933 |
|
} |
934 |
|
} |
935 |
|
|
936 |
|
|
937 |
|
|
938 |
|
|
939 |
|
|
940 |
|
|
941 |
|
private native static int ICStart(int[] instance, int signature); |
942 |
|
|
943 |
|
private native static int ICStop(int[] instance); |
944 |
|
|
945 |
|
private native static int ICLaunchURL(int instance, byte[] hint, |
946 |
|
byte[] data, int len, int[] selectionStart, int[] selectionEnd); |
947 |
|
} |