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?
The User-Agent (UA) string is contained in the HTTP headers and is intended to identify devices requesting online content. The User-Agent tells the server what the visiting device is (among many other things) and this information can be used to determine what content to return.
One of the main use cases of a user agent parser is to identify and handle requests from certain types of traffic. By checking device capabilities or browser capabilities, you can decide which content to send down to the requesting device, or even adapt the content on the fly.
A browser's User-Agent string (UA) helps identify which browser is being used, what version, and on which operating system. When feature detection APIs are not available, use the UA to customize behavior or content to specific browser versions.
Described in the HTTP standard, the User-Agent string contains a number of tokens that refer to various aspects of the request, including the browser's name and version, rendering engine, device's model number, operating system and its version, etc.
Yet try a new library that is updated monthly and available in The Central Repository: http://uadetector.sourceforge.net/
It is another wrapper for user-agent-string.info, but with a much more solid and tested implementation compared to the other ones.
I'm working on a stable API 1.0 which I want to release at the end of this year. After the release of API 1.0 you don't have to recompile anything. You only switch the uadetector-resources.jar in your applications lib dir. The feature 'updated monthly' means, if you want an integration tested 'UAS data' file, for which you have the guarantee that it runs with the defined core, than this one fit your needs. But if you are not interested in updating a JAR (that is tested by me), then you can use the OnlineUserAgentStringParser with the risk, that the implementation doesn't fit to run with the automatically downloaded XML. I'm not interested in releasing more 'uadetector-core' bundles as needed, especially when the API in version 1.0 is released.
Another solution for a client might be that he maintains the 'UAS data' for it's own, when he works with the OnlineUserAgentStringParser and customize the properties file to set the right URL.
As far as I know (and why shouldn't I, it's one of the services company I used to 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With