15-Jul megacz HTTP.java: implemented isInNet(), weekdayRange(), now
checks environment vars for proxies
-15-Jul megacz PNG.java: fixed 8bpp bug
\ No newline at end of file
+15-Jul megacz PNG.java: fixed 8bpp bug
+
+15-Jul megacz Platform.java, Win32.cc, Win32.java, POSIX.java:
+ getEnv(), engine knows its own build-id
/** the result of proxy autodetection */
static HTTP.ProxyInfo cachedProxyInfo = null;
+ /** the current build */
+ public static String build = "unknown";
+
// VM Detection Logic /////////////////////////////////////////////////////////////////////
/** do-nothing method that forces <clinit> to run */
platform.init();
}
+ try {
+ build = (String)Class.forName("org.xwt.Build").getField("build").get(null);
+ } catch (ClassNotFoundException cnfe) {
+ } catch (Exception e) {
+ if (Log.on) Log.log(Platform.class, "exception while detecting build:");
+ if (Log.on) Log.log(Platform.class, e);
+ }
+ if (Log.on) Log.log(Platform.class, "XWT build: " + build);
+
if (Log.on) Log.log(Platform.class, "XWT VM detection: vendor = " + vendor);
if (Log.on) Log.log(Platform.class, " version = " + version);
if (Log.on) Log.log(Platform.class, " os = " + os_name);
+ if (Log.on && Main.applet != null) Log.log(Platform.class, " browser = " + Main.applet.getParameter("browser"));
if (platform_class == null) {
if (Log.on) Log.log(Platform.class, "Unable to detect JVM");
if (Log.on) Log.log(Platform.class, " platform = " + platform.getDescriptiveName());
if (Log.on) Log.log(Platform.class, " class = " + platform.getClass().getName());
+ platform.postInit();
} catch (Exception e) {
if (Log.on) Log.log(Platform.class, "Exception while trying to detect JVM");
/** this initializes the platform; code in here can invoke methods on Platform since Platform.platform has already been set */
protected void init() { }
+ protected void postInit() { }
/** creates and returns a doublebuffer 'belonging' to <tt>owner</tt>; we need to associate DoubleBuffers to surfaces
* due to AWT 1.1 requirements (definately for Navigator, possibly also for MSJVM).
System.exit(0);
} else {
// just block ourselves forever
- // FIXME: implement this with an exit variable for MessageQueue and plat.*.eventThread
+ // FIXME
new Semaphore().block();
}
}
/** returns true iff the platform has a case-sensitive filesystem */
protected boolean _isCaseSensitive() { return true; }
+ /** returns the value of the environment variable key, or null if no such key exists */
+ protected String _getEnv(String key) {
+ try {
+ String os = System.getProperty("os.name").toLowerCase();
+ Process p;
+ if (os.indexOf("windows 9") > -1) {
+ p = Runtime.getRuntime().exec("command.com /c set");
+ } else if ( (os.indexOf("nt") > -1) || (os.indexOf("windows 2000") > -1) ) {
+ p = Runtime.getRuntime().exec("cmd.exe /c set");
+ } else {
+ p = Runtime.getRuntime().exec("env");
+ }
+ BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String s;
+ while ((s = br.readLine()) != null)
+ if (s.startsWith(key + "="))
+ return s.substring(0, key.length() + 1);
+ } catch (Exception e) {
+ if (Log.on) Log.log(this, "Exception while reading from environment:");
+ if (Log.on) Log.log(this, e);
+ }
+ return null;
+ }
// Static methods -- thunk to the instance /////////////////////////////////////////////////////////////////////////
/** returns true iff the platform has a case-sensitive filesystem */
public static boolean isCaseSensitive() { return platform._isCaseSensitive(); }
+ /** returns the value of the environment variable key, or null if no such key exists */
+ public static String getEnv(String key) { return platform._getEnv(key); }
+
/** displays a platform-specific "open file" dialog and returns the chosen filename, or null if the user hit cancel */
public static String fileDialog(String suggestedFileName, boolean write) {
if (!ThreadMessage.suspendThread()) return null;
if (alreadyDetectedProxy) return null;
alreadyDetectedProxy = true;
- if (Log.on) Log.log(Platform.class, "attempting xwt-proxy DNS proxy detection");
+ if (Log.on) Log.log(Platform.class, "attempting environment-variable DNS proxy detection");
cachedProxyInfo = HTTP.ProxyInfo.detectProxyViaManual();
if (cachedProxyInfo != null) return cachedProxyInfo;
protected native void eventThread();
private native void natInit();
- /** returns the $BROWSER environment variable, since System.getEnv() is useless */
- private static native String getEnv(String key);
-
+ /** returns the value of the environment variable key, or null if no such key exists */
+ protected native String _getEnv(String key);
+
/** spawns a process which is immune to SIGHUP */
private static native void spawnChildProcess(String[] command);
- protected synchronized HTTP.ProxyInfo _detectProxy() {
-
- HTTP.ProxyInfo ret = new HTTP.ProxyInfo();
-
- ret.httpProxyHost = getEnv("http_proxy");
- if (ret.httpProxyHost != null) {
- if (ret.httpProxyHost.startsWith("http://")) ret.httpProxyHost = ret.httpProxyHost.substring(7);
- if (ret.httpProxyHost.endsWith("/")) ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.length() - 1);
- if (ret.httpProxyHost.indexOf(':') != -1) {
- ret.httpProxyPort = Integer.parseInt(ret.httpProxyHost.substring(ret.httpProxyHost.indexOf(':') + 1));
- ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.indexOf(':'));
- } else {
- ret.httpProxyPort = 80;
- }
- }
-
- ret.httpsProxyHost = getEnv("https_proxy");
- if (ret.httpsProxyHost != null) {
- if (ret.httpsProxyHost.startsWith("https://")) ret.httpsProxyHost = ret.httpsProxyHost.substring(7);
- if (ret.httpsProxyHost.endsWith("/")) ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.length() - 1);
- if (ret.httpsProxyHost.indexOf(':') != -1) {
- ret.httpsProxyPort = Integer.parseInt(ret.httpsProxyHost.substring(ret.httpsProxyHost.indexOf(':') + 1));
- ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.indexOf(':'));
- } else {
- ret.httpsProxyPort = 80;
- }
- }
-
- ret.socksProxyHost = getEnv("socks_proxy");
- if (ret.socksProxyHost != null) {
- if (ret.socksProxyHost.startsWith("socks://")) ret.socksProxyHost = ret.socksProxyHost.substring(7);
- if (ret.socksProxyHost.endsWith("/")) ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.length() - 1);
- if (ret.socksProxyHost.indexOf(':') != -1) {
- ret.socksProxyPort = Integer.parseInt(ret.socksProxyHost.substring(ret.socksProxyHost.indexOf(':') + 1));
- ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.indexOf(':'));
- } else {
- ret.socksProxyPort = 80;
- }
- }
-
- String noproxy = getEnv("no_proxy");
- if (noproxy != null) {
- StringTokenizer st = new StringTokenizer(noproxy, ",");
- ret.excluded = new String[st.countTokens()];
- for(int i=0; st.hasMoreTokens(); i++) ret.excluded[i] = st.nextToken();
- }
-
- if (ret.httpProxyHost == null && ret.socksProxyHost == null) return null;
- return ret;
- }
-
protected void _newBrowserWindow(String url) {
String browserString = getEnv("BROWSER");
if (browserString == null) {
// Platform Methods ///////////////////////////////////////////////////////////////////
+jstring org::xwt::plat::Win32::_getEnv(jstring key) {
+ int len = JvGetStringUTFLength(key);
+ char buf[len + 1];
+ JvGetStringUTFRegion(key, 0, len, buf);
+ buf[len] = '\0';
+ char buf2[1024];
+ DWORD ret = GetEnvironmentVariable(buf, buf2, 1024);
+ if (ret > 0 && ret < 1024) return JvNewStringLatin1(buf2);
+ return NULL;
+}
+
jstring org::xwt::plat::Win32::_fileDialog(jstring suggestedFileName, jboolean write) {
char buf[1024];
hdc = (jint)GetDC((HWND)hwnd);
}
-void org::xwt::plat::Win32$Win32Surface::finalize() { /* DeleteObject((void*)hwnd); */ }
+void org::xwt::plat::Win32$Win32Surface::finalize() { DeleteObject((void*)hwnd); }
void org::xwt::plat::Win32$Win32Surface::toFront() { BringWindowToTop((HWND)hwnd); }
void org::xwt::plat::Win32$Win32Surface::toBack() { SetWindowPos((HWND)hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); }
void org::xwt::plat::Win32$Win32Surface::_dispose() { PostMessage((HWND)hwnd, WM_USER_DISPOSE, 0, 0); }
// Implementation of Platform methods /////////////////////////////////////////////////////////
+ protected native String _getEnv(String key);
protected boolean _needsAutoClick() { return true; }
protected String getDescriptiveName() { return "GCJ Win32 Binary"; }
protected Surface _createSurface(Box b, boolean framed) { return new Win32Surface(b, framed); }