Looking for a Java User Agent String Parser [close

2019-01-11 00:33发布

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条回答
Fickle 薄情
2楼-- · 2019-01-11 00:59

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.

查看更多
虎瘦雄心在
3楼-- · 2019-01-11 01:08

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.

查看更多
登录 后发表回答