matthiasblaesing commented on code in PR #6585:
URL: https://github.com/apache/netbeans/pull/6585#discussion_r1364331672


##########
ide/extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
##########
@@ -212,7 +380,16 @@ private String realDDEServer () {
         }
         
         try {
-            String cmd = getDefaultOpenCommand ();
+            String cmd = NbDdeBrowserImpl.getDefaultWindowsOpenCommand();
+            
+            /** if not found with getDefaultWindowsOpenCommand function
+             *  fallback to previous method
+             */
+            if (cmd.isEmpty())

Review Comment:
   `cmd` needs to be guarded against null, that was caught before and would now 
raise a `NullPointerException`



##########
ide/extbrowser/src/org/netbeans/modules/extbrowser/NbDdeBrowserImpl.java:
##########
@@ -127,6 +132,169 @@ public NbDdeBrowserImpl (ExtWebBrowser extBrowserFactory) 
{
      */
     public static native String getDefaultOpenCommand() throws 
NbBrowserException;
     
+    /**
+     * Get the default browser name using java
+     * part of the solution source 
https://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java
+     * @return 
+     */
+    private static String getDefaultWindowsBrowser()
+    {
+        try
+        {
+            Process process = Runtime.getRuntime().exec("reg query 
HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\URLAssociations\\https\\UserChoice
 /f ProgId /v");

Review Comment:
   We have JNA and JNA platform in the platform. I suggest to use the bindings 
(need to be added as dependencies). The code can be simplified to:
   
   ```java
       private static String getDefaultWindowsBrowser()
       {
           try
           {
               String userChoice = Advapi32Util
                       .registryGetStringValue(
                               WinReg.HKEY_CURRENT_USER,
                               
"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\https\\UserChoice",
                               "ProgId"
                       )
                       .toUpperCase(Locale.ROOT);
   
               if (userChoice.contains(ExtWebBrowser.FIREFOX))
               {
                   return ExtWebBrowser.FIREFOX;
               }
               else if (userChoice.contains(ExtWebBrowser.CHROME))
               {
                   return ExtWebBrowser.CHROME;
               }
               else if (userChoice.contains(ExtWebBrowser.CHROMIUM))
               {
                   return ExtWebBrowser.CHROMIUM;
               }
               else if (userChoice.contains(ExtWebBrowser.MOZILLA))
               {
                   return ExtWebBrowser.MOZILLA;
               }
               else
               {
                   return ExtWebBrowser.IEXPLORE;
               }
           }
           catch (Win32Exception ex)
           {
               ex.printStackTrace();
               return null;
           }
       }
   ```
   
   - query registry directly
   - the browser names are already upper case, so use them as is and convert 
registry value to upper case
   
   and
   
   ```java
       private static String getDefaultWindowsOpenCommandPath(String browser)
       {
           if(browser == null) {
               return null;
           }
           try
           {
               return Advapi32Util.registryGetStringValue(
                       WinReg.HKEY_CLASSES_ROOT,
                       "Applications\\" + browser.toLowerCase() + 
".exe\\shell\\open\\command",
                       null
               );
           }
           catch (Win32Exception ex)
           {
               ex.printStackTrace();
               return null;
           }
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to