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

📄 jdicmanager.java

📁 JDesktop Integration Components (JDIC)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        + File.separator + getPlatform() 
                        + File.separator + getArchitecture();
                }  
            }    
            if(null!=clNativeExtractor){
                //we don't need adjust java.library.path,
                //but we have to add the path in initBrowserNative() call 
                nativeLibPath = NativeExtractor.getBinary();
            }
            
        } catch( JdicInitException e ) {
            throw e;
        } catch( Throwable e ) {
            throw new JdicInitException(e);
        }
    }    
    
    private static String getBinaryPath() {
        //WebBrowserUtil.trace("native lib path " + nativeLibPath);
        return nativeLibPath;
    }
    
    /**
     * Initializes the native file settings for the JDIC Browser component 
     * (package <code>org.jdecktop.jdic.browser</code>). Set necessary 
     * environment variables for the Browser specific native library and 
     * executable files, including *.exe files on Windows, and mozembed-<os>-gtk* 
     * files on Unix.
     * 
     * @exception JdicInitException Generic initialization exception
     */
    public static void initBrowserNative() throws JdicInitException {
        // The Browser component is used.
        // If the Browser specific native file setting was already initialized, 
        // just return.
        try {
            // Pre-append the JDIC binary path to PATH(on Windows) or 
            // LD_LIBRARY_PATH(on Unix).         
            
            /** The environment variable for library path setting */
            boolean isWindows = getPlatform().equals("windows");
            String libPathEnv = isWindows ? "PATH" : "LD_LIBRARY_PATH";
            
            String binaryPath = getBinaryPath();            
            InitUtility.preAppendEnv(libPathEnv, binaryPath); 
            WebBrowserUtil.trace("JDIC found BIN path=[" + binaryPath + "]");

            String browserPath = WebBrowserUtil.getBrowserPath();
            if (browserPath == null) {
                throw new JdicInitException(
                    "Can't locate the native browser path!");
            }
            
            if (WebBrowserUtil.isDefaultBrowserMozilla()) {
                // Mozilla is the default/embedded browser.
                // Use the user defined value or the mozilla binary
                // path as the value of MOZILLA_FIVE_HOME env variable.
                String envMFH = InitUtility.getEnv("MOZILLA_FIVE_HOME");
                if (envMFH == null) {
                    File browserFile = new File(browserPath);
                    if (browserFile.isDirectory()) {
                        envMFH = browserFile.getCanonicalPath();
                    } else {
                        envMFH = browserFile.getCanonicalFile().getParent();
                    }                    
                }
                
                if (!isWindows) {
                    // On Unix, add the binary path to PATH.
                    InitUtility.preAppendEnv("PATH", binaryPath);
                } else {               
                    // Mozilla on Windows, reset MOZILLA_FIVE_HOME to the GRE 
                    // directory path:  
                    //   [Common Files]\mozilla.org\GRE\1.x_BUILDID, 
                    // if Mozilla installs from a .exe package.
                    //                
                    String xpcomPath = envMFH + File.separator + "xpcom.dll";                        
                    if (!(new File(xpcomPath).isFile())) {
                        // Mozilla installs from a .exe package. Check the 
                        // installed GRE directory.
                        String mozGreHome 
                            = WebBrowserUtil.getMozillaGreHome();
                        if (mozGreHome == null) {
                            throw new JdicInitException(
                                "Can't locate the GRE directory of the " +
                                "installed Mozilla binary: " + envMFH);
                        }                       
                        envMFH = mozGreHome;
                    }
                }              

                InitUtility.setEnv("MOZILLA_FIVE_HOME", envMFH);
                InitUtility.preAppendEnv(libPathEnv, envMFH);
            } // end - Mozilla is the default/embedded browser.
        } catch (Throwable e) {
            throw new JdicInitException(e);
        }
    }

    private static boolean initNativeLoader = false;        
    private static HashSet loadedLibraries = new HashSet();  
    
    public static synchronized void loadLibrary(final String libName) 
            throws PrivilegedActionException 
    {
        try {        
            if(!initNativeLoader){
                initNativeLoader = true;
                init();
            }
            if( !loadedLibraries.contains(libName) ){
                loadedLibraries.add(libName);
                if(null!=clNativeExtractor){
                    NativeExtractor.loadLibruary(libName);                    
                } else {
                    AccessController.doPrivileged( new PrivilegedExceptionAction() { 
                        public Object run() throws IOException {
                            System.load(nativeLibPath + File.separator 
                                    + libName + getPlatformDLLext());
                            return null;
                        }
                    });
                }    
            }
        }catch(PrivilegedActionException e){
            throw e;
        }catch(Exception e){
            throw new PrivilegedActionException(e);
        }
    }
    
    private static boolean initBrowserDLLPath = false;        
    public static synchronized Process exec( final String[] args) 
            throws PrivilegedActionException 
    {
        try {        
            if(!initNativeLoader){
                initNativeLoader = true;
                init();
            }
            if(!initBrowserDLLPath){
                initBrowserDLLPath = true;
                initBrowserNative();
            }
            if(null!=clNativeExtractor){
                return NativeExtractor.exec(args);                    
            } else {
                final Process[] res = new Process[] {null};
                AccessController.doPrivileged( new PrivilegedExceptionAction() { 
                    public Object run() throws IOException {
                        res[0] = Runtime.getRuntime().exec( args );
                        return null;
                    }
                });
                return res[0];
            }    
        }catch(PrivilegedActionException e){
            throw e;
        }catch(Exception e){
            throw new PrivilegedActionException(e);
        }
    }        
}

class JNLPClassLoaderAccessor {
    static java.lang.reflect.Method mdJNLPClassLoader_findLibrary = null;
    static{
        java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() {
            public Object run() {
                try {
                    mdJNLPClassLoader_findLibrary = Class
                            .forName("com.sun.jnlp.JNLPClassLoader")
                            .getDeclaredMethod(
                                "findLibrary", 
                                new Class[]{String.class} );
                    mdJNLPClassLoader_findLibrary.setAccessible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                // to please javac
                return null;
            }
        });
    }

    public static String findLibrary(JNLPClassLoader o, String name) {
        try {
            return (String)mdJNLPClassLoader_findLibrary.invoke(o, new Object[]{ name });
        } catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}

⌨️ 快捷键说明

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