1 19 20 package edu.umd.cs.findbugs.util; 21 22 import java.io.IOException ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.lang.reflect.*; 26 27 import edu.umd.cs.findbugs.SystemProperties; 28 import edu.umd.cs.findbugs.annotations.CheckForNull; 29 import edu.umd.cs.findbugs.annotations.Nullable; 30 31 34 public class LaunchBrowser { 35 36 private static final @CheckForNull Method jnlpShowMethod; 37 private static final Object jnlpShowObject; static { 39 Method showMethod = null; 41 Object showObject = null; 42 try { 43 Class serviceManagerClass = Class.forName("javax.jnlp.ServiceManager"); 44 Method lookupMethod = serviceManagerClass.getMethod("lookup", new Class [] { String .class }); 45 showObject = lookupMethod.invoke(null, new Object [] { "javax.jnlp.BasicService" }); 46 showMethod = showObject.getClass().getMethod("showDocument", new Class [] { URL .class }); 47 } catch (ClassNotFoundException e) { 48 assert true; 49 } catch (NoSuchMethodException e) { 50 assert true; 51 } catch (IllegalAccessException e) { 52 assert true; 53 } catch (InvocationTargetException e) { 54 assert true; 55 } 56 jnlpShowMethod = showMethod; 57 jnlpShowObject = showObject; 58 } 59 60 61 62 68 public static boolean showDocument(URL url) { 69 70 if (jnlpShowMethod != null) try { 71 Object result = jnlpShowMethod.invoke(jnlpShowObject, new Object [] { url }); 72 return (Boolean.TRUE.equals(result)); 73 } catch (InvocationTargetException ite) { 74 } catch (IllegalAccessException iae) { 76 } 78 79 return showViaExec( url.toString() ); } 82 83 84 89 public static boolean showDocument(String url) { 90 URL wrapper = null; 91 if (jnlpShowMethod != null) try { 92 wrapper = new URL (url); 93 } catch (MalformedURLException mue) { 94 wrapper = null; 95 } 96 97 if (wrapper != null) try { 98 Object result = jnlpShowMethod.invoke(jnlpShowObject, new Object [] { url }); 99 System.out.println("jnlp result is "+result); 100 return (Boolean.TRUE.equals(result)); 101 } catch (InvocationTargetException ite) { 102 } catch (IllegalAccessException iae) { 104 } 106 107 return showViaExec(url); 109 } 110 111 112 119 private static boolean showViaExec(String url){ 120 return false; 121 150 } 151 152 } 153 | Popular Tags |