You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2023/09/29 06:36:03 UTC

svn commit: r1912599 - /pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java

Author: lehmi
Date: Fri Sep 29 06:36:03 2023
New Revision: 1912599

URL: http://svn.apache.org/viewvc?rev=1912599&view=rev
Log:
PDFBOX-5576: remove code targeting java <= 8 versions

Modified:
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java

Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java?rev=1912599&r1=1912598&r2=1912599&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/OSXAdapter.java Fri Sep 29 06:36:03 2023
@@ -70,7 +70,6 @@ import java.lang.reflect.InvocationHandl
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.util.StringTokenizer;
 import java.util.List;
 
 /**
@@ -92,66 +91,38 @@ public class OSXAdapter implements Invoc
 
     static Object macOSXApplication;
     
-    private static boolean isMinJdk9()
-    {
-        // strategy from lucene-solr/lucene/core/src/java/org/apache/lucene/util/Constants.java
-        String version = System.getProperty("java.specification.version");
-        final StringTokenizer st = new StringTokenizer(version, ".");
-        try
-        {
-            int major = Integer.parseInt(st.nextToken());
-            int minor = 0;
-            if (st.hasMoreTokens())
-            {
-                minor = Integer.parseInt(st.nextToken());
-            }
-            return major > 1 || (major == 1 && minor >= 9);
-        }
-        catch (NumberFormatException nfe)
-        {
-            // maybe some new numbering scheme in the 22nd century
-            return true;
-        }
-    }
-
     // Pass this method an Object and Method equipped to perform application shutdown logic
     // The method passed should return a boolean stating whether or not the quit should occur
     public static void setQuitHandler(final Object target, final Method quitHandler)
     {
-        if (isMinJdk9())
+        try
         {
-            try
+            Desktop desktopObject = Desktop.getDesktop();
+            Class<?> filesHandlerClass = Class.forName("java.awt.desktop.QuitHandler");
+            final Method setQuitHandlerMethod = desktopObject.getClass().getMethod("setQuitHandler",
+                    filesHandlerClass);
+            Object osxAdapterProxy = Proxy.newProxyInstance(OSXAdapter.class.getClassLoader(),
+                    new Class[] { filesHandlerClass }, new InvocationHandler()
             {
-                Desktop desktopObject = Desktop.getDesktop();
-                Class<?> filesHandlerClass = Class.forName("java.awt.desktop.QuitHandler");
-                final Method setQuitHandlerMethod = desktopObject.getClass().getMethod("setQuitHandler", filesHandlerClass);
-                Object osxAdapterProxy = Proxy.newProxyInstance(OSXAdapter.class.getClassLoader(),
-                        new Class[]
-                        {
-                            filesHandlerClass
-                        }, new InvocationHandler()
+                        @Override
+                        public Object invoke(Object proxy, Method method, Object[] args)
+                                throws Throwable
                 {
-                    @Override
-                    public Object invoke(Object proxy, Method method, Object[] args)
-                            throws Throwable
+                            if ("handleQuitRequestWith".equals(method.getName()))
                     {
-                        if ("handleQuitRequestWith".equals(method.getName()))
-                        {
-                            // We just call our own quit handler
-                            quitHandler.invoke(target);
-                        }
-                        return null;
+                                // We just call our own quit handler
+                                quitHandler.invoke(target);
                     }
-                });
-                setQuitHandlerMethod.invoke(desktopObject, osxAdapterProxy);
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-            return;
+                            return null;
+                        }
+                    });
+            setQuitHandlerMethod.invoke(desktopObject, osxAdapterProxy);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
         }
-        setHandler(new OSXAdapter("handleQuit", target, quitHandler));
+        return;
     }
 
     // Pass this method an Object and Method equipped to display application info
@@ -195,69 +166,48 @@ public class OSXAdapter implements Invoc
     // application bundle's Info.plist
     public static void setFileHandler(Object target, Method fileHandler)
     {
-        if (isMinJdk9())
+        try
         {
-            try
+            Desktop desktopObject = Desktop.getDesktop();
+            Class<?> filesHandlerClass = Class.forName("java.awt.desktop.OpenFilesHandler");
+            Method setOpenFileHandlerMethod = desktopObject.getClass()
+                    .getMethod("setOpenFileHandler", filesHandlerClass);
+            Object osxAdapterProxy = Proxy.newProxyInstance(OSXAdapter.class.getClassLoader(),
+                    new Class[] { filesHandlerClass },
+                    new OSXAdapter("openFiles", target, fileHandler)
             {
-                Desktop desktopObject = Desktop.getDesktop();
-                Class<?> filesHandlerClass = Class.forName("java.awt.desktop.OpenFilesHandler");
-                Method setOpenFileHandlerMethod = desktopObject.getClass().getMethod("setOpenFileHandler", filesHandlerClass);
-                Object osxAdapterProxy = Proxy.newProxyInstance(OSXAdapter.class.getClassLoader(),
-                        new Class[]
-                        {
-                            filesHandlerClass
-                        }, new OSXAdapter("openFiles", target, fileHandler)
+                        // Override OSXAdapter.callTarget to send information on the
+                        // file to be opened
+                        @Override
+                        public boolean callTarget(Object openFilesEvent)
                 {
-                    // Override OSXAdapter.callTarget to send information on the
-                    // file to be opened
-                    @Override
-                    public boolean callTarget(Object openFilesEvent)
+                            if (openFilesEvent != null)
                     {
-                        if (openFilesEvent != null)
+                                try
+                                {
+                                    Method getFilesMethod = openFilesEvent.getClass()
+                                            .getDeclaredMethod("getFiles", (Class[]) null);
+                                    @SuppressWarnings("unchecked")
+                                    List<File> files = (List<File>) getFilesMethod
+                                            .invoke(openFilesEvent, (Object[]) null);
+                                    this.targetMethod.invoke(this.targetObject,
+                                            files.get(0).getAbsolutePath());
+                                }
+                                catch (Exception ex)
                         {
-                            try
-                            {
-                                Method getFilesMethod = openFilesEvent.getClass().getDeclaredMethod("getFiles",
-                                        (Class[]) null);
-                                @SuppressWarnings("unchecked")
-                                List<File> files = (List<File>) getFilesMethod.invoke(openFilesEvent,
-                                        (Object[]) null);
-                                this.targetMethod.invoke(this.targetObject, files.get(0).getAbsolutePath());
-                            }
-                            catch (Exception ex)
-                            {
-                                throw new RuntimeException(ex);
-                            }
+                                    throw new RuntimeException(ex);
                         }
-                        return true;
                     }
-                });
-                setOpenFileHandlerMethod.invoke(desktopObject, osxAdapterProxy);
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-            return;
-        }
-        /* JDK <= 1.8, using Apple classes */
-        setHandler(new OSXAdapter("handleOpenFile", target, fileHandler) {
-            // Override OSXAdapter.callTarget to send information on the
-            // file to be opened
-            @Override
-            public boolean callTarget(Object appleEvent) {
-                if (appleEvent != null) {
-                    try {
-                        Method getFilenameMethod = appleEvent.getClass().getDeclaredMethod("getFilename", (Class[])null);
-                        String filename = (String) getFilenameMethod.invoke(appleEvent, (Object[])null);
-                        this.targetMethod.invoke(this.targetObject, filename);
-                    } catch (Exception ex) {
-                        throw new RuntimeException(ex);
-                    }
-                }
-                return true;
-            }
-        });
+                            return true;
+                        }
+                    });
+            setOpenFileHandlerMethod.invoke(desktopObject, osxAdapterProxy);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return;
     }
 
     // setHandler creates a Proxy object from the passed OSXAdapter and adds it as an ApplicationListener