⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 browserlauncher.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        loadedWithoutErrors = false;
                        errorMessage = "Unsupported MRJ version: " + version;
                    }
                } catch (NumberFormatException nfe) {
                    loadedWithoutErrors = false;
                    errorMessage = "Invalid MRJ version: " + mrjVersion;
                }
            }
        } else if (osName.startsWith("Windows")) {
            if (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1) {
                jvm = WINDOWS_9x;
            } else {
                jvm = WINDOWS_NT;
            }
        } else {
            jvm = OTHER;
        }

        if (loadedWithoutErrors) { // if we haven't hit any errors yet
            loadedWithoutErrors = loadClasses();
        }
    }

    /**
     * This class should be never be instantiated; this just ensures so.
     */
    private BrowserLauncher() {
    }

    /**
     * Manually set the browser command. If this is set then none the this
     * command will <b>always </b> be used.
     * 
     * @param browserCommand browser command
     */
    public static void setBrowserCommand(String browserCommand) {
        BrowserLauncher.browserCommand = browserCommand;
    }

    /**
     * Called by a static initializer to load any classes, fields, and methods
     * required at runtime to locate the user's web browser.
     * 
     * @return <code>true</code> if all intialization succeeded
     *         <code>false</code> if any portion of the initialization failed
     */
    private static boolean loadClasses() {
        switch (jvm) {
            case MRJ_2_0:
                return loadMRJ20Classes();
            case MRJ_2_1:
                try {
                    mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
                    mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
                    Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
                    kSystemFolderType = systemFolderField.get(null);
                    findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] {
                        mrjOSTypeClass
                    });
                    getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator", new Class[] {
                        File.class
                    });
                    getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] {
                        File.class
                    });
                } catch (ClassNotFoundException cnfe) {
                    errorMessage = cnfe.getMessage();
                    return false;
                } catch (NoSuchFieldException nsfe) {
                    errorMessage = nsfe.getMessage();
                    return false;
                } catch (NoSuchMethodException nsme) {
                    errorMessage = nsme.getMessage();
                    return false;
                } catch (SecurityException se) {
                    errorMessage = se.getMessage();
                    return false;
                } catch (IllegalAccessException iae) {
                    errorMessage = iae.getMessage();
                    return false;
                }
                break;
            case MRJ_3_0:
                try {
                    Class linker = Class.forName("com.apple.mrj.jdirect.Linker");
                    Constructor constructor = linker.getConstructor(new Class[] {
                        Class.class
                    });
                    constructor.newInstance(new Object[] {
                        BrowserLauncher.class
                    });
                } catch (ClassNotFoundException cnfe) {
                    errorMessage = cnfe.getMessage();
                    return false;
                } catch (NoSuchMethodException nsme) {
                    errorMessage = nsme.getMessage();
                    return false;
                } catch (InvocationTargetException ite) {
                    errorMessage = ite.getMessage();
                    return false;
                } catch (InstantiationException ie) {
                    errorMessage = ie.getMessage();
                    return false;
                } catch (IllegalAccessException iae) {
                    errorMessage = iae.getMessage();
                    return false;
                }
                break;
            case MRJ_3_1:
            case MRJ_COCOA:
                String className;
                if (jvm == MRJ_3_1) {
                    className = "com.apple.mrj.MRJFileUtils";
                } else {
                    className = "com.apple.eio.FileManager";
                }
                try {
                    mrjFileUtilsClass = Class.forName(className);
                    openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", new Class[] {
                        String.class
                    });
                } catch (ClassNotFoundException cnfe) {
                    errorMessage = cnfe.getMessage();
                    return false;
                } catch (NoSuchMethodException nsme) {
                    errorMessage = nsme.getMessage();
                    return false;
                }
                break;
            default:
                break;
        }
        return true;
    }

    /**
     * Loads the classes, fields, and methods needed when running under MRJ 2.0.
     * Sets <code>errorMessage</code> if it fails.
     * 
     * @return <code>true</code> if all operations succeeded;
     *         <code>false</code> otherwise
     */
    private static boolean loadMRJ20Classes() {
        try {
            Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
            Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
            Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
            Class aeClass = Class.forName("com.apple.MacOS.ae");
            aeDescClass = Class.forName("com.apple.MacOS.AEDesc");

            aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] {
                int.class
            });
            appleEventConstructor = appleEventClass.getDeclaredConstructor(new Class[] {
                            int.class, int.class, aeTargetClass, int.class, int.class
            });
            aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] {
                String.class
            });

            makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] {
                String.class
            });
            putParameter = appleEventClass.getDeclaredMethod("putParameter", new Class[] {
                            int.class, aeDescClass
            });
            sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] {});

            Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
            keyDirectObject = (Integer) keyDirectObjectField.get(null);
            Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
            kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null);
            Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
            kAnyTransactionID = (Integer) anyTransactionIDField.get(null);
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        return true;
    }

    /**
     * Attempts to locate the default web browser on the local system. Caches
     * the result so it only locates the browser once for each use of this class
     * per JVM instance.
     * 
     * @return The browser for the system. Note that this may not be what you
     *         would consider to be a standard web browser; instead, it's the
     *         application that gets called to open the default web browser. In
     *         some cases this will be a non-String object that provides the
     *         means of calling the default browser.
     */
    private static Object locateBrowser() {
        if (browser != null) {
            return browser;
        }
        switch (jvm) {
            case MRJ_2_0:
                try {
                    Integer finderCreatorCode = (Integer) makeOSType.invoke(null, new Object[] {
                        FINDER_CREATOR
                    });
                    Object aeTarget = aeTargetConstructor.newInstance(new Object[] {
                        finderCreatorCode
                    });
                    Integer gurlType = (Integer) makeOSType.invoke(null, new Object[] {
                        GURL_EVENT
                    });
                    Object appleEvent = appleEventConstructor.newInstance(new Object[] {
                                    gurlType, gurlType, aeTarget, kAutoGenerateReturnID, kAnyTransactionID
                    });
                    // Don't set browser = appleEvent because then the next time
                    // we call
                    // locateBrowser(), we'll get the same AppleEvent, to which
                    // we'll
                    // already have
                    // added the relevant parameter. Instead, regenerate the
                    // AppleEvent
                    // every time.
                    // There's probably a way to do this better; if any has any
                    // ideas,
                    // please let
                    // me know.
                    return appleEvent;
                } catch (IllegalAccessException iae) {
                    browser = null;
                    errorMessage = iae.getMessage();
                    return browser;
                } catch (InstantiationException ie) {
                    browser = null;
                    errorMessage = ie.getMessage();
                    return browser;
                } catch (InvocationTargetException ite) {
                    browser = null;
                    errorMessage = ite.getMessage();
                    return browser;
                }
            case MRJ_2_1:
                File systemFolder;
                try {
                    systemFolder = (File) findFolder.invoke(null, new Object[] {
                        kSystemFolderType
                    });
                } catch (IllegalArgumentException iare) {
                    browser = null;
                    errorMessage = iare.getMessage();
                    return browser;
                } catch (IllegalAccessException iae) {
                    browser = null;
                    errorMessage = iae.getMessage();
                    return browser;
                } catch (InvocationTargetException ite) {
                    browser = null;
                    errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
                    return browser;
                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -