1 20 package org.jdesktop.jdic.browser.internal; 21 22 import java.io.File ; 23 24 27 public class WebBrowserUtil { 28 private static final String EMBED_BINARY_WINDOWS_IE 32 = "IeEmbed.exe"; 33 private static final String EMBED_BINARY_WINDOWS_MOZILLA 34 = "MozEmbed.exe"; 35 private static final String EMBED_BINARY_LINUX_GTK1 36 = "mozembed-linux-gtk1.2"; 37 private static final String EMBED_BINARY_LINUX_GTK2 38 = "mozembed-linux-gtk2"; 39 private static final String EMBED_BINARY_FREEBSD_GTK1 40 = "mozembed-freebsd-gtk1.2"; 41 private static final String EMBED_BINARY_FREEBSD_GTK2 42 = "mozembed-freebsd-gtk2"; 43 private static final String EMBED_BINARY_SOLARIS_GTK1 44 = "mozembed-solaris-gtk1.2"; 45 private static final String EMBED_BINARY_SOLARIS_GTK2 46 = "mozembed-solaris-gtk2"; 47 48 private static String embedBinary; 49 50 private static String browserPath = null; 51 52 53 private static native String nativeGetBrowserPath(); 54 private static native String nativeGetMozillaGreHome(); 55 56 private static boolean isDebugOn = false; 58 59 static { 60 System.loadLibrary("jdic"); 61 } 62 63 67 public static String getEmbedBinaryName() { 68 if (embedBinary != null && embedBinary.length() > 0) 69 return embedBinary; 70 71 String nativePath = WebBrowserUtil.getBrowserPath(); 72 if (null == nativePath) { 73 trace("No default browser is found. " + 74 "Or environment variable MOZILLA_FIVE_HOME is not set to " + 75 "a Mozilla binary path if you are on Linux/Unix platform."); 76 return null; 77 } 78 79 String osname = System.getProperty("os.name"); 80 if (osname.indexOf("Windows") >= 0) { 81 String windowspath = nativePath; 82 int index = windowspath.indexOf("mozilla.exe"); 83 if (index >= 0) 84 embedBinary = EMBED_BINARY_WINDOWS_MOZILLA; 85 else 86 embedBinary = EMBED_BINARY_WINDOWS_IE; 87 } 88 else { 89 String libwidgetpath = nativePath + File.separator + 90 "components" + File.separator + 91 "libwidget_gtk2.so"; 92 File file = new File (libwidgetpath); 93 if (!file.exists()) { 94 if (osname.indexOf("Linux") >= 0) { 95 embedBinary = EMBED_BINARY_LINUX_GTK1; 96 } 97 else if (osname.indexOf("SunOS") >= 0) { 98 embedBinary = EMBED_BINARY_SOLARIS_GTK1; 99 } 100 else if (osname.indexOf("FreeBSD") >= 0) { 101 embedBinary = EMBED_BINARY_FREEBSD_GTK1; 102 } 103 } 104 else { 105 if (osname.indexOf("Linux") >= 0) { 106 embedBinary = EMBED_BINARY_LINUX_GTK2; 107 } 108 else if (osname.indexOf("SunOS") >= 0) { 109 embedBinary = EMBED_BINARY_SOLARIS_GTK2; 110 } 111 else if (osname.indexOf("FreeBSD") >= 0) { 112 embedBinary = EMBED_BINARY_FREEBSD_GTK2; 113 } 114 } 115 } 116 117 return embedBinary; 118 } 119 120 124 public static String getBrowserPath() { 125 if (browserPath == null) { 126 browserPath = nativeGetBrowserPath(); 127 } 128 return browserPath; 129 } 130 131 136 public static boolean isDefaultBrowserMozilla() { 137 String osName = System.getProperty("os.name").toLowerCase(); 138 139 if ((osName.indexOf("solaris") >= 0) || 140 (osName.indexOf("linux") >= 0) ) { 141 return true; 142 } else { 143 String nativeBrowserPath = getBrowserPath(); 144 if (nativeBrowserPath.indexOf("mozilla") >= 0) { 150 return true; 151 } else { 152 return false; 153 } 154 } 155 } 156 157 161 public static String getMozillaGreHome() { 162 return nativeGetMozillaGreHome(); 163 } 164 165 public static void enableDebugMessages(boolean b) { 166 isDebugOn = b; 167 } 168 169 174 public static void trace(String msg) { 175 if (isDebugOn) 176 System.out.println("*** Jtrace: " + msg); 177 } 178 179 182 public static native void nativeSetEnv(); 183 } 184 | Popular Tags |