[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user svenmeier commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181308489 --- Diff: wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java --- @@ -46,14 +46,20 @@ /** * The user agent string from the User-Agent header, app. Theoretically, this might differ from -* {@link org.apache.wicket.protocol.http.ClientProperties#isNavigatorJavaEnabled()} property, which is -* not set until an actual reply from a browser (e.g. using {@link BrowserInfoPage} is set. +* {@link org.apache.wicket.protocol.http.ClientProperties#isNavigatorJavaEnabled()} property, +* which is not set until an actual reply from a browser (e.g. using {@link BrowserInfoPage} is +* set. */ private final String userAgent; /** Client properties object. */ private final ClientProperties properties; + private final static UserAgentAnalyzer UAA = UserAgentAnalyzer.newBuilder() --- End diff -- UserAgentAnalyzer#parse(UserAgent) is synchronized, please check its code. This is even mentioned on the project home page. ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user klopfdreh commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181303063 --- Diff: wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java --- @@ -59,9 +58,52 @@ public void before() } /** -* Test IE 6.x user-agent strings +* Test check check all user agents */ @Test + public void testBrowsersAndVersionsOfUserAgents() { + // Internet Explorers --- End diff -- Hehe me too ð - no hurry, because I think this is going to be released in a further version. ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user solomax commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181297750 --- Diff: wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java --- @@ -59,9 +58,52 @@ public void before() } /** -* Test IE 6.x user-agent strings +* Test check check all user agents */ @Test + public void testBrowsersAndVersionsOfUserAgents() { + // Internet Explorers --- End diff -- Will try to provide patch later tonight Have to do day time job right now :( ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user klopfdreh commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181296712 --- Diff: wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java --- @@ -59,9 +58,52 @@ public void before() } /** -* Test IE 6.x user-agent strings +* Test check check all user agents */ @Test + public void testBrowsersAndVersionsOfUserAgents() { + // Internet Explorers --- End diff -- May you have any other good idea to keep the tests individual. Just send a patch to me if something would fit the requirement and I am going to integrate it. ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user klopfdreh commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181295733 --- Diff: wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java --- @@ -59,9 +58,52 @@ public void before() } /** -* Test IE 6.x user-agent strings +* Test check check all user agents */ @Test + public void testBrowsersAndVersionsOfUserAgents() { + // Internet Explorers --- End diff -- Yes that is true, but I think if you change the code / the browser detection you are going to investigate why the test is failing and fix the integration as long as every test is back working again. @BeforeClass is not working, because WicketTestCase and at this stage no Application is attached to the main thread. ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user solomax commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181294275 --- Diff: wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java --- @@ -59,9 +58,52 @@ public void before() } /** -* Test IE 6.x user-agent strings +* Test check check all user agents */ @Test + public void testBrowsersAndVersionsOfUserAgents() { + // Internet Explorers --- End diff -- All subsequent lines will not be executed in case of failure ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user solomax commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181293918 --- Diff: wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java --- @@ -59,9 +58,52 @@ public void before() } /** -* Test IE 6.x user-agent strings +* Test check check all user agents */ @Test + public void testBrowsersAndVersionsOfUserAgents() { + // Internet Explorers --- End diff -- You can move init to `@BeforeClass` . ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user klopfdreh commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181293718 --- Diff: wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java --- @@ -59,9 +58,52 @@ public void before() } /** -* Test IE 6.x user-agent strings +* Test check check all user agents */ @Test + public void testBrowsersAndVersionsOfUserAgents() { + // Internet Explorers --- End diff -- You will see if something fails in the test results btw. ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user klopfdreh commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181293658 --- Diff: wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java --- @@ -59,9 +58,52 @@ public void before() } /** -* Test IE 6.x user-agent strings +* Test check check all user agents */ @Test + public void testBrowsersAndVersionsOfUserAgents() { + // Internet Explorers --- End diff -- This might slow down the test execution because of the init of YAUAA - try it out. ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user solomax commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181293591 --- Diff: wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java --- @@ -59,9 +58,52 @@ public void before() } /** -* Test IE 6.x user-agent strings +* Test check check all user agents */ @Test + public void testBrowsersAndVersionsOfUserAgents() { + // Internet Explorers --- End diff -- I would rather have all these as individual tests, to be able to see which one was failed And run all of them regardless failure state of others ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user solomax commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181293350 --- Diff: wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java --- @@ -147,6 +149,93 @@ private String getUserAgentStringLc() return (getUserAgent() != null) ? getUserAgent().toLowerCase() : ""; } + /** +* Initializes the {@link WebClientInfo} user agent detection. This can be overridden to choose +* a different detection as YAUAA (https://github.com/nielsbasjes/yauaa) - if you do so, you +* might exclude the maven dependency from your project in favor of a different framework. +*/ + public void initialize() + { + UserAgentAnalyzer userAgentAnalyzer = Application.get().getMetaData(UAA_META_DATA_KEY); + if (userAgentAnalyzer == null) + { + userAgentAnalyzer = UserAgentAnalyzer.newBuilder() + .hideMatcherLoadStats() + .withCache(25000) + .build(); + Application.get().setMetaData(UAA_META_DATA_KEY, userAgentAnalyzer); + } + detectBrowserProperties(userAgentAnalyzer); + } + + /** +* Detects browser properties like versions or the type of the browser and applies them to the +* {@link ClientProperties}, override this method if there are errors within the browser / +* version detection due to newer browsers +* +* @param userAgentAnalyzer +*the user agent analyzer to detect browsers and versions +*/ + protected void detectBrowserProperties(UserAgentAnalyzer userAgentAnalyzer) + { + + nl.basjes.parse.useragent.UserAgent parsedUserAgent = userAgentAnalyzer + .parse(getUserAgent()); + String userAgentName = parsedUserAgent.getValue("AgentName"); + + // Konqueror + properties.setBrowserKonqueror(UserAgent.KONQUEROR.getUaStrings().contains(userAgentName)); + + // Chrome + properties.setBrowserChrome(UserAgent.CHROME.getUaStrings().contains(userAgentName)); + + // Edge + properties.setBrowserEdge(UserAgent.EDGE.getUaStrings().contains(userAgentName)); + + // Safari + properties.setBrowserSafari(UserAgent.SAFARI.getUaStrings().contains(userAgentName)); + + // Opera + properties.setBrowserOpera(UserAgent.OPERA.getUaStrings().contains(userAgentName)); + + // Internet Explorer + properties.setBrowserInternetExplorer( + UserAgent.INTERNET_EXPLORER.getUaStrings().contains(userAgentName)); + + // FireFox + boolean isFireFox = UserAgent.FIREFOX.getUaStrings() + .contains(parsedUserAgent.getValue("AgentName")); + if (isFireFox) + { + properties.setBrowserMozillaFirefox(true); + properties.setBrowserMozilla(true); + } + else + { + properties.setBrowserMozilla( + UserAgent.MOZILLA.getUaStrings().contains(parsedUserAgent.getValue("AgentName"))); --- End diff -- `userAgentName` ---
[GitHub] wicket pull request #275: [WICKET-6544] mobile browser detection is improved...
Github user solomax commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181293318 --- Diff: wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java --- @@ -147,6 +149,93 @@ private String getUserAgentStringLc() return (getUserAgent() != null) ? getUserAgent().toLowerCase() : ""; } + /** +* Initializes the {@link WebClientInfo} user agent detection. This can be overridden to choose +* a different detection as YAUAA (https://github.com/nielsbasjes/yauaa) - if you do so, you +* might exclude the maven dependency from your project in favor of a different framework. +*/ + public void initialize() + { + UserAgentAnalyzer userAgentAnalyzer = Application.get().getMetaData(UAA_META_DATA_KEY); + if (userAgentAnalyzer == null) + { + userAgentAnalyzer = UserAgentAnalyzer.newBuilder() + .hideMatcherLoadStats() + .withCache(25000) + .build(); + Application.get().setMetaData(UAA_META_DATA_KEY, userAgentAnalyzer); + } + detectBrowserProperties(userAgentAnalyzer); + } + + /** +* Detects browser properties like versions or the type of the browser and applies them to the +* {@link ClientProperties}, override this method if there are errors within the browser / +* version detection due to newer browsers +* +* @param userAgentAnalyzer +*the user agent analyzer to detect browsers and versions +*/ + protected void detectBrowserProperties(UserAgentAnalyzer userAgentAnalyzer) + { + + nl.basjes.parse.useragent.UserAgent parsedUserAgent = userAgentAnalyzer + .parse(getUserAgent()); + String userAgentName = parsedUserAgent.getValue("AgentName"); + + // Konqueror + properties.setBrowserKonqueror(UserAgent.KONQUEROR.getUaStrings().contains(userAgentName)); + + // Chrome + properties.setBrowserChrome(UserAgent.CHROME.getUaStrings().contains(userAgentName)); + + // Edge + properties.setBrowserEdge(UserAgent.EDGE.getUaStrings().contains(userAgentName)); + + // Safari + properties.setBrowserSafari(UserAgent.SAFARI.getUaStrings().contains(userAgentName)); + + // Opera + properties.setBrowserOpera(UserAgent.OPERA.getUaStrings().contains(userAgentName)); + + // Internet Explorer + properties.setBrowserInternetExplorer( + UserAgent.INTERNET_EXPLORER.getUaStrings().contains(userAgentName)); + + // FireFox + boolean isFireFox = UserAgent.FIREFOX.getUaStrings() + .contains(parsedUserAgent.getValue("AgentName")); --- End diff -- `userAgentName` ---
[GitHub] wicket issue #275: [WICKET-6544] mobile browser detection is improved (with ...
Github user klopfdreh commented on the issue: https://github.com/apache/wicket/pull/275 Following changes have been made: * The init() method has been changed into gatherExtendedInfo() which is only be executed if org.apache.wicket.settings.RequestCycleSettings.setGatherExtendedBrowserInfo(boolean) is set to true * MetaDataKey has been used to initialize YAUAA * All browser specific methods have been moved into detectBrowserProperties * gatherExtendedInfo / detectBrowserProperties are protected / public so that the user may override them ---