< prev index next >

src/com/sun/javatest/tool/HelpExternalLink.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


  57             public void mousePressed(MouseEvent e) {
  58                 if (!openUrl(getTarget())) {
  59                     JHelpContentViewer cv = (JHelpContentViewer) SwingUtilities.getAncestorOfClass(JHelpContentViewer.class, e.getComponent());
  60                     HelpBroker hb = (HelpBroker) (cv.getClientProperty(HELPBROKER_FOR_HELPLINK));
  61                     hb.displayCurrentID(getTarget());
  62                 }
  63             }
  64         });
  65     }
  66 
  67     public static boolean openUrl(String url) {
  68         String os = System.getProperty("os.name");
  69         try {
  70             if (os != null) {
  71                 if (os.startsWith("Windows")) {
  72                     // rundll32 allows to open a file in appropriate default application
  73                     Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
  74                 } else if (os.startsWith("Mac OS")) {
  75                     Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
  76                     Method openURL = fileMgr.getDeclaredMethod("openURL",
  77                             new Class[]{String.class});
  78                     openURL.invoke(null, new Object[]{url});
  79                 } else {
  80                     String[] commands = {
  81                         // xdg-open is used on some linux systems to open files types in default applications
  82                         "xdg-open", "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"};
  83                     String resultCommand = null;
  84                     for (int i = 0; i < commands.length && resultCommand == null; i++) {
  85                         Process process = Runtime.getRuntime().exec(new String[]{"which", commands[i]});
  86                         // IOException is thrown if there is no "which" command in the system, false returned - cannot find browser
  87                         BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
  88 
  89                         int time = 0;
  90                         int exitValue = -1;
  91                         // don't want to catch a lock - waiting 10 seconds for result
  92                         while(true) {
  93                             try {
  94                                 exitValue = process.exitValue();
  95                                 break;
  96                             } catch(IllegalThreadStateException e) {
  97                             }




  57             public void mousePressed(MouseEvent e) {
  58                 if (!openUrl(getTarget())) {
  59                     JHelpContentViewer cv = (JHelpContentViewer) SwingUtilities.getAncestorOfClass(JHelpContentViewer.class, e.getComponent());
  60                     HelpBroker hb = (HelpBroker) (cv.getClientProperty(HELPBROKER_FOR_HELPLINK));
  61                     hb.displayCurrentID(getTarget());
  62                 }
  63             }
  64         });
  65     }
  66 
  67     public static boolean openUrl(String url) {
  68         String os = System.getProperty("os.name");
  69         try {
  70             if (os != null) {
  71                 if (os.startsWith("Windows")) {
  72                     // rundll32 allows to open a file in appropriate default application
  73                     Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
  74                 } else if (os.startsWith("Mac OS")) {
  75                     Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
  76                     Method openURL = fileMgr.getDeclaredMethod("openURL",
  77                             new Class<?>[]{String.class});
  78                     openURL.invoke(null, new Object[]{url});
  79                 } else {
  80                     String[] commands = {
  81                         // xdg-open is used on some linux systems to open files types in default applications
  82                         "xdg-open", "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"};
  83                     String resultCommand = null;
  84                     for (int i = 0; i < commands.length && resultCommand == null; i++) {
  85                         Process process = Runtime.getRuntime().exec(new String[]{"which", commands[i]});
  86                         // IOException is thrown if there is no "which" command in the system, false returned - cannot find browser
  87                         BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
  88 
  89                         int time = 0;
  90                         int exitValue = -1;
  91                         // don't want to catch a lock - waiting 10 seconds for result
  92                         while(true) {
  93                             try {
  94                                 exitValue = process.exitValue();
  95                                 break;
  96                             } catch(IllegalThreadStateException e) {
  97                             }


< prev index next >