Java Code Examples for nl.basjes.parse.useragent.UserAgentAnalyzer#parse()
The following examples show how to use
nl.basjes.parse.useragent.UserAgentAnalyzer#parse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBuilder.java From yauaa with Apache License 2.0 | 6 votes |
@Test public void testLoadAdditionalRules() { UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer .newBuilder() .withField("DeviceClass") .withoutCache() .hideMatcherLoadStats() .addResources("ExtraLoadedRule1.yaml") .withField("ExtraValue2") .withField("ExtraValue1") .addResources("ExtraLoadedRule2.yaml") .build(); UserAgent parsedAgent = userAgentAnalyzer.parse("Mozilla/5.0 (Linux; Android 7.0; Nexus 6 Build/NBD90Z) " + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.124 Mobile Safari/537.36"); // The requested fields assertEquals("Phone", parsedAgent.getValue("DeviceClass" )); assertEquals("One", parsedAgent.getValue("ExtraValue1" )); assertEquals("Two", parsedAgent.getValue("ExtraValue2" )); }
Example 2
Source File: TestBuilder.java From yauaa with Apache License 2.0 | 6 votes |
@Test public void testLoadOnlyCustomRules() { UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer .newBuilder() .withoutCache() .hideMatcherLoadStats() .addResources("ExtraLoadedRule1.yaml") .withField("ExtraValue2") .withField("ExtraValue1") .addResources("ExtraLoadedRule2.yaml") .build(); UserAgent parsedAgent = userAgentAnalyzer.parse("Mozilla/5.0 (Linux; Android 7.0; Nexus 6 Build/NBD90Z) " + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.124 Mobile Safari/537.36"); // The requested fields assertEquals("One", parsedAgent.getValue("ExtraValue1" )); assertEquals("Two", parsedAgent.getValue("ExtraValue2" )); }
Example 3
Source File: TestBuilder.java From yauaa with Apache License 2.0 | 6 votes |
@Test public void testLoadOnlyCompanyCustomFormatRules() { UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer .newBuilder() .withoutCache() .hideMatcherLoadStats() .dropDefaultResources() .addResources("CompanyInternalUserAgents.yaml") .withFields("ApplicationName", "ApplicationVersion") .withFields(Arrays.asList("ApplicationInstance", "ApplicationGitCommit")) .withField("ServerName") .build(); UserAgent parsedAgent = userAgentAnalyzer.parse( "TestApplication/1.2.3 (node123.datacenter.example.nl; 1234; d71922715c2bfe29343644b14a4731bf5690e66e)"); // The requested fields assertEquals("TestApplication", parsedAgent.getValue("ApplicationName")); assertEquals("1.2.3", parsedAgent.getValue("ApplicationVersion")); assertEquals("1234", parsedAgent.getValue("ApplicationInstance")); assertEquals("d71922715c2bfe29343644b14a4731bf5690e66e", parsedAgent.getValue("ApplicationGitCommit")); assertEquals("node123.datacenter.example.nl", parsedAgent.getValue("ServerName")); }