Is there an Java Equivalent of WINC OpenApplicationFile?

Document ID : KB000053688
Last Modified Date : 14/02/2018
Show Technical Document Details

Description

The ShowURL Java API works only with applets as per Plex online help section Reference Guide-> Allfusion Plex Runtime API->Java API->showURLJava API. The Java source code below works with a Java application.

Solution

There is a JAVA API "Startbrowser" which will start the concerning program for the file.

Here is the source code:

//Class
 
  class BrowserControl
  {
 
   public BrowserControl(String url)
 {
    //Call method
    displayURL(url);
   }
      /**
       * Display a file in the system browser.  If you want to display a
       * file, you must include the absolute path name.
       *
       * @param url the file's url (the url must start with either "http://"
 or
       * "file://").
       */
      public void displayURL(String url)
      {
          boolean windows = isWindowsPlatform();
          String cmd = null;
          try
          {
              if (windows)
         {
              if (windows)
              {
                  // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
                  cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
                  Process p = Runtime.getRuntime().exec(cmd);
              }
              else
              {
                 // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
                  cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
                  Process p = Runtime.getRuntime().exec(cmd);
              }
              else
              {
                  // Under Unix, Netscape has to be running for the "-remote"
                  // command to work.  So, we try sending the command and
                  // check for an exit value.  If the exit command is 0,
                  // it worked, otherwise we need to start the browser.
                  // cmd = 'netscape -remote
   openURL(http://www.javaworld.com)'
              cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
              Process p = Runtime.getRuntime().exec(cmd);
    try
                  {
                      // wait for exit code -- if it's 0, command worked,
                      // otherwise we need to start the browser up.
                      int exitCode = p.waitFor();
                      if (exitCode != 0)
                      {
                          // Command failed, start up the browser
                          // cmd = 'netscape http://www.javaworld.com'
                          cmd = UNIX_PATH + " "  + url;
                          p = Runtime.getRuntime().exec(cmd);
                      }
                  }
                  catch(InterruptedException x)
                  {
                      System.err.println("Error bringing up browser, cmd='" +
                                         cmd + "'");
                      System.err.println("Caught: " + x);
                  }
              }
          }
          catch(java.io.IOException x)
          {
              // couldn't exec browser
              System.err.println("Could not invoke browser, command=" + cmd);
              System.err.println("Caught: " + x);
          }
      }
     /**
       * Try to determine whether this application is running under Windows
       * or some other platform by examining the "os.name" property.
       *
       * @return true if this application is running under a Windows OS
       */
     public boolean isWindowsPlatform()
      {
          String os = System.getProperty("os.name");
          if ( os != null && os.startsWith(WIN_ID))
              return true;
          else
              return false;
 
      }
      // Used to identify the windows platform.
      private final String WIN_ID = "Windows";
      // The default system browser under windows.
      private final String WIN_PATH = "rundll32";
      // The flag to display a url.
      private final String WIN_FLAG = "url.dll,FileProtocolHandler";
      // The default browser under unix.
      private final String UNIX_PATH = "netscape";
      // The flag to display a url.
      private final String UNIX_FLAG = "-remote openURL";
  }
 
  //Start browser
  BrowserControl browser = new BrowserControl(&(1:).toString());

Additional info:

With Java 6 (JDK 1.6), Sun has introduced a new Desktop API to enable launching of applications and so on. From the Plex point of view, you still have to write source code objects but hopefully the coding should be
easier.

For more info see:

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/