mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
Bug WISE-205 fixed.
Fix IE 11 browser detection.
This commit is contained in:
parent
a70dd1e52e
commit
d0e07269c4
@ -47,7 +47,7 @@ public class SupportedUserAgent implements Serializable {
|
||||
|
||||
boolean result = browser == Browser.FIREFOX && majorVersion >= 10;
|
||||
result = result || browser == Browser.FIREFOX2 && majorVersion >= 17;
|
||||
result = result || browser == Browser.IE8 || browser == Browser.IE9;
|
||||
result = result || browser == Browser.IE8 || browser == Browser.IE9 || browser == Browser.IE11 ;
|
||||
result = result || browser == Browser.IE && majorVersion >= 8;
|
||||
result = result || browser == Browser.OPERA10 && majorVersion >= 11;
|
||||
result = result || browser == Browser.CHROME && majorVersion >= 18;
|
||||
|
@ -44,8 +44,8 @@ import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Enum constants for most common browsers, including e-mail clients and bots.
|
||||
* @author harald
|
||||
*
|
||||
* @author harald
|
||||
*/
|
||||
|
||||
public enum Browser {
|
||||
@ -73,6 +73,11 @@ public enum Browser {
|
||||
*/
|
||||
OUTLOOK2010(Manufacturer.MICROSOFT, Browser.OUTLOOK, 108, "Outlook 2010", new String[]{"MSOffice 14"}, null, BrowserType.EMAIL_CLIENT, RenderingEngine.WORD, null), // before IE7
|
||||
|
||||
/**
|
||||
* Family of Internet Explorer browsers
|
||||
*/
|
||||
IE11(Manufacturer.MICROSOFT, null, 1, "Internet Explorer", new String[]{") like Gecko"}, null, BrowserType.WEB_BROWSER, RenderingEngine.TRIDENT, "Mozilla/5.0 (([\\d]+)\\.([\\w]+))"), // before Mozilla
|
||||
|
||||
/**
|
||||
* Family of Internet Explorer browsers
|
||||
*/
|
||||
@ -155,8 +160,6 @@ public enum Browser {
|
||||
DOWNLOAD(Manufacturer.OTHER, null, 16, "Downloading Tool", new String[]{"cURL", "wget"}, null, BrowserType.TEXT_BROWSER, RenderingEngine.OTHER, null),
|
||||
|
||||
UNKNOWN(Manufacturer.OTHER, null, 14, "Unknown", new String[0], null, BrowserType.UNKNOWN, RenderingEngine.OTHER, null);
|
||||
|
||||
|
||||
private final short id;
|
||||
private final String name;
|
||||
private final String[] aliases;
|
||||
@ -172,7 +175,7 @@ public enum Browser {
|
||||
this.id = (short) ((manufacturer.getId() << 8) + (byte) versionId);
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
this.children = new ArrayList<Browser>();
|
||||
this.children = new ArrayList<>();
|
||||
if (this.parent != null) {
|
||||
this.parent.children.add(this);
|
||||
}
|
||||
@ -186,6 +189,45 @@ public enum Browser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over all Browsers to compare the browser signature with
|
||||
* the user agent string. If no match can be found Browser.UNKNOWN will
|
||||
* be returned.
|
||||
*
|
||||
* @param agentString
|
||||
* @return Browser
|
||||
*/
|
||||
public static Browser parseUserAgentString(String agentString) {
|
||||
for (Browser browser : Browser.values()) {
|
||||
// only check top level objects
|
||||
if (browser.parent == null) {
|
||||
Browser match = browser.checkUserAgent(agentString);
|
||||
if (match != null) {
|
||||
return match; // either current operatingSystem or a child object
|
||||
}
|
||||
}
|
||||
}
|
||||
return Browser.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enum constant of this type with the specified id.
|
||||
* Throws IllegalArgumentException if the value does not exist.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static Browser valueOf(short id) {
|
||||
for (Browser browser : Browser.values()) {
|
||||
if (browser.getId() == id)
|
||||
return browser;
|
||||
}
|
||||
|
||||
// same behavior as standard valueOf(string) method
|
||||
throw new IllegalArgumentException(
|
||||
"No enum const for id " + id);
|
||||
}
|
||||
|
||||
public short getId() {
|
||||
return id;
|
||||
}
|
||||
@ -207,6 +249,7 @@ public enum Browser {
|
||||
/**
|
||||
* Detects the detailed version information of the browser. Depends on the userAgent to be available.
|
||||
* Returns null if it can not detect the version information.
|
||||
*
|
||||
* @return Version
|
||||
*/
|
||||
public Version getVersion(String userAgentString) {
|
||||
@ -260,10 +303,8 @@ public enum Browser {
|
||||
* Checks if the given user-agent string matches to the browser.
|
||||
* Only checks for one specific browser.
|
||||
*/
|
||||
public boolean isInUserAgentString(String agentString)
|
||||
{
|
||||
for (String alias : aliases)
|
||||
{
|
||||
public boolean isInUserAgentString(String agentString) {
|
||||
for (String alias : aliases) {
|
||||
if (agentString.toLowerCase().indexOf(alias.toLowerCase()) != -1)
|
||||
return true;
|
||||
}
|
||||
@ -273,11 +314,11 @@ public enum Browser {
|
||||
/**
|
||||
* Checks if the given user-agent does not contain one of the tokens which should not match.
|
||||
* In most cases there are no excluding tokens, so the impact should be small.
|
||||
*
|
||||
* @param agentString
|
||||
* @return
|
||||
*/
|
||||
private boolean containsExcludeToken(String agentString)
|
||||
{
|
||||
private boolean containsExcludeToken(String agentString) {
|
||||
if (excludeList != null) {
|
||||
for (String exclude : excludeList) {
|
||||
if (agentString.toLowerCase().indexOf(exclude.toLowerCase()) != -1)
|
||||
@ -306,47 +347,5 @@ public enum Browser {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over all Browsers to compare the browser signature with
|
||||
* the user agent string. If no match can be found Browser.UNKNOWN will
|
||||
* be returned.
|
||||
* @param agentString
|
||||
* @return Browser
|
||||
*/
|
||||
public static Browser parseUserAgentString(String agentString)
|
||||
{
|
||||
for (Browser browser : Browser.values())
|
||||
{
|
||||
// only check top level objects
|
||||
if (browser.parent == null) {
|
||||
Browser match = browser.checkUserAgent(agentString);
|
||||
if (match != null) {
|
||||
return match; // either current operatingSystem or a child object
|
||||
}
|
||||
}
|
||||
}
|
||||
return Browser.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enum constant of this type with the specified id.
|
||||
* Throws IllegalArgumentException if the value does not exist.
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static Browser valueOf(short id)
|
||||
{
|
||||
for (Browser browser : Browser.values())
|
||||
{
|
||||
if (browser.getId() == id)
|
||||
return browser;
|
||||
}
|
||||
|
||||
// same behavior as standard valueOf(string) method
|
||||
throw new IllegalArgumentException(
|
||||
"No enum const for id " + id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -49,6 +49,9 @@ public class UserAgentTest {
|
||||
final SupportedUserAgent mediapartners = SupportedUserAgent.create("Mediapartners-Google/2.1");
|
||||
Assert.assertEquals(mediapartners.isBrowserSupported(), true);
|
||||
|
||||
final SupportedUserAgent ie11 = SupportedUserAgent.create("Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko");
|
||||
Assert.assertEquals(ie11.isBrowserSupported(), true);
|
||||
|
||||
final SupportedUserAgent firefox20 = SupportedUserAgent.create("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20121215 Firefox/20.0 AppEngine-Google; (+http://code.google.com/appengine; appid: slubuntuk)");
|
||||
Assert.assertEquals(firefox20.isBrowserSupported(), true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user