Newsflash

Turning off ipv6 is helpful in some circumstances. For example if your network is slow. If your router is only IPv4 enabled,  the IPv6 Protokoll is tunneled via IPv4.

 

Syndicate

Using Windows shell folders with java PDF Print
Saturday, 05 April 2008

windowsWizard.png There's a really annoying weakness in the Java virtual machine on Windows: the Java user.home system property is based on the location of the Windows Desktop folder not the Windows USERPROFILE variable. The user.home system property is useful for iX-Systems but worthless for Windows.  In reality you want to know the location of " My Documents". What is required to locate this folders ? Yepp, just a short lookup in the Windows Registry. It is time to close this gap without JNI.

Sun disinvest the Java Platform from the Windows Registry. The registry is bound to Windows and worthless for platform independent programing. Nevertheless, it may not be overlooked that  more than 90% all PC windows use. SUN´s recommendationthe is to use the native WIN32 API by the means of  the JAVA JNI interface. The programmer can either use a homebrew DLL or a commercial solutions.
So far so good.
But just what is the Java Perferences? The Windows Java implementation uses the registry for the implementation of the interface.

Example: 

Preferences prefsRoot = Preferences.userRoot();
Preferences test = prefsRoot.node("test");
test.put("KEY_A""a value");
test.put("KEY_B""a other value");
test.put("KEY_C""my value");  

While debugging this Example with Eclipse you´ll discopver the WindowsPreferences Class, wich is internal and not visible in the JAVA API. The souce code is public available, here vor example. A little research with google brought the fundamental idea in lenkite´s WebLog.

To extend the boilerplate was easy, see the following codefragment from a JUnit Test on howto use the windows shell folders.

   
       windowsPreferencesWrapper = WindowsPreferencesWrapper.getInstance()
        String test = windowsPreferencesWrapper.getHKCUKeyValue("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Local Settings");
        assertNotNull(test);
        System.out.println(test);
        String test = windowsPreferencesWrapper.getHKLMKeyValue("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName");
        assertNotNull(test);
        System.out.println(test);
        test = windowsPreferencesWrapper.getHKLMKeyValue("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "CurrentVersion");
        System.out.println(test);
        assertNotNull(test);

You can download the complete class from the download area .

 
< Prev   Next >