views:

1146

answers:

2

Does anyone know of a great library in java for parsing user agent strings? We have written a custom one, but this seems like a common problem for many people. I would guess there is a good library available somewhere.

For example, the user agent string...

"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.21 Safari/532.0"

... cryptically announces the arrival of a Windows Vista PC using Chrome on our site.

I've seen libraries in python and ruby. Anything in java out there?

+2  A: 

As far as I know (and why shouldn't I, it's one of the services company I work at provides with its products), detecting user agents when done properly is actually a good business in itself.

There are several free databases such as WURFL containing some rudimentary identification patterns for user agents but those mainly focus on for example mobile phones so in the end you may have to keep using the one you've made and just add the capability to import from/export to various related formats related to current state of user agent identification metadata.

If you're not going to steer away from desktop/PC world, you won't have much to worry about though since there's only four major layout engines out there with of course a set of versions with varying capabilities. The four big ones are the one in Trident in IE, Mozilla's Gecko, KDE's WebKit (at least in Safari and Chrome) and Opera's Presto.

Esko
+5  A: 

There's also: http://code.google.com/p/user-agent-utils/

shadenite