views:

988

answers:

4

I am writing a CSV exporter in Java that should respect the user's custom settings, especially the "List separator" to use as a delimiter.

In Windows, one can set this List separator in

Control Panel -> Regional and Language Options -> Regional Options -> Customize

I don't know about the other operating systems, but I'm pretty sure that you can change that on other OSes, too.

What is the best way to get this custom setting from the OS into Java? I am in an Eclipse RCP environment, so I might use RCP-related solutions if there is something available.

A: 

For windows it's stored in the registry at:

"HKEY_CURRENT_USER\\Control Panel\\International"

so you can use something like this

private void setDelimiterProperties(String delimiter) {
    Properties p = new Properties();
    String key = "HKEY_CURRENT_USER\\Control Panel\\International\\sList";
    p.setProperty(key, delimiter);
}
darko.topolsek
Um, wasn't the question about *getting* the "custom setting from the OS into Java". (Also, just creating a Properties object and setting it in that surely won't write anything in Windows Registry either)
Jonik
ok, so then you use getProperty(key) instead of setProperty(key, value). and you're wrong about not writing it to windows registry. in fact, that's all that needs to be done to write it to registry.
darko.topolsek
About reading from/writing to Windows Registry: http://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java
Jonik
Hmm, if Properties is java.util.Properties, then I find it impossible to believe your setDelimiterProperties() as it now stands will write to Registry. Maybe you confuse it with java.util.prefs.Preferences
Jonik
+3  A: 

Without resorting to a platform specific solution I think that the best approach to take is going to be to allow users to specify their preference of list separator within your own application. Either in a preferences panel, a dialog box on export or via an optional command line argument.

ninesided
Yeah; I don't think all OSs have such "List separator" setting. (At least never heard about it on Linux, for example)
Jonik
Reading the OS-specific setting is a need I *have* to meet. Otherwise you are right, that would be a more platform-independent way, definitely.
Simon07
+3  A: 

From comments of this answer:

Reading the OS-specific setting is a need I have to meet.

So what if OSs other than Windows don't have such a setting?

I suggest you read it from registry on Windows (as alluded here): Read/write to Windows Registry using Java. On other platforms just use a good default, and perhaps, at least on Unix, also support configuring it via a custom environment variable (which you document well): How can my java code read OS environment variables?.

My gut feeling that OSs universally do not have a (system-wide or user-specific) "List separator" setting may be wrong, of course, but I doubt that.

Jonik
I agree, if other OSs don't have such a setting, the best bet is to fall back to a default value in these cases. In the windows case, I'll use the registry reading option.
Simon07
+2  A: 

Out of curiosity, I searched a bit the topic, and indeed Java seems to have not such notion out of the box.

The Locales Demo gives a fairly complete listing of locale settings and there is no list separator there.

I saw a forum question referring to sun.text.resources package, which is private and deprecated. You won't find much other references to this package, looks like it lives in jre/lib/ext/localedata.jar although my recent copy of this one lists mostly Asian locales.

The above advices are sound, or you might research and use a private list per locale. I would look perhaps at IBM's ICU library (C language I think) which seems to have a fairly big list of locale settings. According to a remark, ICU itself gets its information from a an ISO standard, which should be researched as primary information provider.

PhiLho