Wednesday, January 26, 2011

Encoding URL delimiters (for GWT)

This is what I do to encode a parameter for my querystring:


public static String encodeUrlDelimiters(String s) {
    if (s == null) {
      return null;
    }
 
    s = s.replaceAll(";", "%2F");
    s = s.replaceAll("/", "%2F");
    s = s.replaceAll(":", "%3A");
    s = s.replaceAll("\\?", "%3F");
    s = s.replaceAll("&", "%26");
    s = s.replaceAll("\\=", "%3D");
    s = s.replaceAll("\\+", "%2B");
    s = s.replaceAll("\\$", "%24");
    s = s.replaceAll(",", "%2C");
    s = s.replaceAll("#", "%23");
 
    return s;
}

This is how I use it:
private String getGoogleLoginUrl() {
    if (cp.getAccessToken() == null && cp.getAccessToken().getThirdPartyLoginData() == null) {
      return null;
    }
    
    String domain = GWT.getHostPageBaseURL();
    String path = Window.Location.getPath();
    String qs = Window.Location.getQueryString();
    String historyToken = History.getToken();
    if (qs == null) {
      qs = "";
    }
    if (domain.matches(".*/") == true) {
      domain = domain.substring(0,domain.length()-1);
    }
    
    String url = domain + path + qs + "#" + historyToken;
    url = URL.encode(url);
    url = Global_String.encodeUrlDelimiters(url);

    String baseUrl = cp.getAccessToken().getThirdPartyLoginData().getGoogleLoginUrl();
    baseUrl = baseUrl.replaceAll("=%2F.*", "=" + url);
    
    return baseUrl;
}

javax-usb deployment

Control USB using Java. Observe and Listen to USB Events with Java.

1. download http://sourceforge.net/projects/javax-usb/files/ ri-linux
2. $ export JAVA_HOME=/usr/lib/jvm/java-6-sun ;echo $JAVA_HOME
3. /usr/lib/jvm/java-6-sun/include/linux$ sudo ln -s ../jni.h
4. compile the c interface $ ./javax-usb-ri-linux/jni/make


Reference
http://javax-usb.org/ - main site
http://javax-usb.cvs.sourceforge.net/javax-usb/javax-usb-ri-linux/ - source

Trying out the Dart Analysis Server

I wanted to see how the Dart Analysis Server was put together and worked. I started looking to see how I could wire it up and try out the co...