@Test public void constructorNormalDeviceOverride() { String[] normalDevices = new String[] { "android", "iphone" }; LiteDeviceResolver resolver2 = new LiteDeviceResolver( Arrays.asList(normalDevices)); request.setUserAgentHeader(UserAgent.IPHONE_IOS5_STRING); Device device = resolver2.resolveDevice(request); assertTrue(device.isNormal()); assertFalse(device.isMobile()); assertFalse(device.isTablet()); assertEquals(device.toString(), NORMAL_TO_STRING); assertIOSPlatform(request); }
public Device resolveDevice(HttpServletRequest request) { String userAgent = request.getHeader("User-Agent"); if (userAgent != null) { userAgent = userAgent.toLowerCase(); for (String keyword : normalUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveFallback(request); } } } if (userAgent != null) { userAgent = userAgent.toLowerCase(); if (userAgent.contains("android") && !userAgent.contains("mobile")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.ANDROID); } if (userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.IOS); } if (userAgent.contains("silk") && !userAgent.contains("mobile")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.UNKNOWN); } for (String keyword : tabletUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.UNKNOWN); } } } if (request.getHeader("x-wap-profile") != null || request.getHeader("Profile") != null) { if (userAgent != null) { if (userAgent.contains("android")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.ANDROID); } if (userAgent.contains("iphone") || userAgent.contains("ipod") || userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.IOS); } } return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } if (userAgent != null && userAgent.length() >= 4) { String prefix = userAgent.substring(0, 4).toLowerCase(); if (mobileUserAgentPrefixes.contains(prefix)) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } String accept = request.getHeader("Accept"); if (accept != null && accept.contains("wap")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } if (userAgent != null) { if (userAgent.contains("android")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.ANDROID); } if (userAgent.contains("iphone") || userAgent.contains("ipod") || userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.IOS); } for (String keyword : mobileUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } } @SuppressWarnings("rawtypes") Enumeration headers = request.getHeaderNames(); while (headers.hasMoreElements()) { String header = (String) headers.nextElement(); if (header.contains("OperaMini")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } return resolveFallback(request); }
LiteDeviceResolver implements DeviceResolver { public Device resolveDevice(HttpServletRequest request) { String userAgent = request.getHeader("User-Agent"); if (userAgent != null) { userAgent = userAgent.toLowerCase(); for (String keyword : normalUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveFallback(request); } } } if (userAgent != null) { userAgent = userAgent.toLowerCase(); if (userAgent.contains("android") && !userAgent.contains("mobile")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.ANDROID); } if (userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.IOS); } if (userAgent.contains("silk") && !userAgent.contains("mobile")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.UNKNOWN); } for (String keyword : tabletUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.UNKNOWN); } } } if (request.getHeader("x-wap-profile") != null || request.getHeader("Profile") != null) { if (userAgent != null) { if (userAgent.contains("android")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.ANDROID); } if (userAgent.contains("iphone") || userAgent.contains("ipod") || userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.IOS); } } return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } if (userAgent != null && userAgent.length() >= 4) { String prefix = userAgent.substring(0, 4).toLowerCase(); if (mobileUserAgentPrefixes.contains(prefix)) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } String accept = request.getHeader("Accept"); if (accept != null && accept.contains("wap")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } if (userAgent != null) { if (userAgent.contains("android")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.ANDROID); } if (userAgent.contains("iphone") || userAgent.contains("ipod") || userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.IOS); } for (String keyword : mobileUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } } @SuppressWarnings("rawtypes") Enumeration headers = request.getHeaderNames(); while (headers.hasMoreElements()) { String header = (String) headers.nextElement(); if (header.contains("OperaMini")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } return resolveFallback(request); } }
LiteDeviceResolver implements DeviceResolver { public Device resolveDevice(HttpServletRequest request) { String userAgent = request.getHeader("User-Agent"); if (userAgent != null) { userAgent = userAgent.toLowerCase(); for (String keyword : normalUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveFallback(request); } } } if (userAgent != null) { userAgent = userAgent.toLowerCase(); if (userAgent.contains("android") && !userAgent.contains("mobile")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.ANDROID); } if (userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.IOS); } if (userAgent.contains("silk") && !userAgent.contains("mobile")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.UNKNOWN); } for (String keyword : tabletUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.UNKNOWN); } } } if (request.getHeader("x-wap-profile") != null || request.getHeader("Profile") != null) { if (userAgent != null) { if (userAgent.contains("android")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.ANDROID); } if (userAgent.contains("iphone") || userAgent.contains("ipod") || userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.IOS); } } return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } if (userAgent != null && userAgent.length() >= 4) { String prefix = userAgent.substring(0, 4).toLowerCase(); if (mobileUserAgentPrefixes.contains(prefix)) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } String accept = request.getHeader("Accept"); if (accept != null && accept.contains("wap")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } if (userAgent != null) { if (userAgent.contains("android")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.ANDROID); } if (userAgent.contains("iphone") || userAgent.contains("ipod") || userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.IOS); } for (String keyword : mobileUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } } @SuppressWarnings("rawtypes") Enumeration headers = request.getHeaderNames(); while (headers.hasMoreElements()) { String header = (String) headers.nextElement(); if (header.contains("OperaMini")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } return resolveFallback(request); } LiteDeviceResolver();  LiteDeviceResolver(List<String> normalUserAgentKeywords); }
LiteDeviceResolver implements DeviceResolver { public Device resolveDevice(HttpServletRequest request) { String userAgent = request.getHeader("User-Agent"); if (userAgent != null) { userAgent = userAgent.toLowerCase(); for (String keyword : normalUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveFallback(request); } } } if (userAgent != null) { userAgent = userAgent.toLowerCase(); if (userAgent.contains("android") && !userAgent.contains("mobile")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.ANDROID); } if (userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.IOS); } if (userAgent.contains("silk") && !userAgent.contains("mobile")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.UNKNOWN); } for (String keyword : tabletUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.UNKNOWN); } } } if (request.getHeader("x-wap-profile") != null || request.getHeader("Profile") != null) { if (userAgent != null) { if (userAgent.contains("android")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.ANDROID); } if (userAgent.contains("iphone") || userAgent.contains("ipod") || userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.IOS); } } return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } if (userAgent != null && userAgent.length() >= 4) { String prefix = userAgent.substring(0, 4).toLowerCase(); if (mobileUserAgentPrefixes.contains(prefix)) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } String accept = request.getHeader("Accept"); if (accept != null && accept.contains("wap")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } if (userAgent != null) { if (userAgent.contains("android")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.ANDROID); } if (userAgent.contains("iphone") || userAgent.contains("ipod") || userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.IOS); } for (String keyword : mobileUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } } @SuppressWarnings("rawtypes") Enumeration headers = request.getHeaderNames(); while (headers.hasMoreElements()) { String header = (String) headers.nextElement(); if (header.contains("OperaMini")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } return resolveFallback(request); } LiteDeviceResolver();  LiteDeviceResolver(List<String> normalUserAgentKeywords); Device resolveDevice(HttpServletRequest request); }
LiteDeviceResolver implements DeviceResolver { public Device resolveDevice(HttpServletRequest request) { String userAgent = request.getHeader("User-Agent"); if (userAgent != null) { userAgent = userAgent.toLowerCase(); for (String keyword : normalUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveFallback(request); } } } if (userAgent != null) { userAgent = userAgent.toLowerCase(); if (userAgent.contains("android") && !userAgent.contains("mobile")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.ANDROID); } if (userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.IOS); } if (userAgent.contains("silk") && !userAgent.contains("mobile")) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.UNKNOWN); } for (String keyword : tabletUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveWithPlatform(DeviceType.TABLET, DevicePlatform.UNKNOWN); } } } if (request.getHeader("x-wap-profile") != null || request.getHeader("Profile") != null) { if (userAgent != null) { if (userAgent.contains("android")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.ANDROID); } if (userAgent.contains("iphone") || userAgent.contains("ipod") || userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.IOS); } } return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } if (userAgent != null && userAgent.length() >= 4) { String prefix = userAgent.substring(0, 4).toLowerCase(); if (mobileUserAgentPrefixes.contains(prefix)) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } String accept = request.getHeader("Accept"); if (accept != null && accept.contains("wap")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } if (userAgent != null) { if (userAgent.contains("android")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.ANDROID); } if (userAgent.contains("iphone") || userAgent.contains("ipod") || userAgent.contains("ipad")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.IOS); } for (String keyword : mobileUserAgentKeywords) { if (userAgent.contains(keyword)) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } } @SuppressWarnings("rawtypes") Enumeration headers = request.getHeaderNames(); while (headers.hasMoreElements()) { String header = (String) headers.nextElement(); if (header.contains("OperaMini")) { return resolveWithPlatform(DeviceType.MOBILE, DevicePlatform.UNKNOWN); } } return resolveFallback(request); } LiteDeviceResolver();  LiteDeviceResolver(List<String> normalUserAgentKeywords); Device resolveDevice(HttpServletRequest request);  }