1 package org.jmage.util; 2 3 import javax.servlet.http.HttpServletRequest; 4 5 /*** 6 * UserAgentUtil detects Browser and OS 7 */ 8 public class UserAgentUtil { 9 private static final String USER_AGENT = "user-agent"; 10 private static final String USER_AGENT_INICAPS = "User-Agent"; 11 private static final String WINDOWS = "windows"; 12 private static final String INTERNET_EXPLORER_5 = "msie 5."; 13 private static final String INTERNET_EXPLORER_6 = "msie 6."; 14 15 public boolean detectWindows(HttpServletRequest request) { 16 if (request == null) { 17 return false; 18 } 19 return (this.detectWindows(request.getHeader(USER_AGENT)) || 20 (this.detectWindows(request.getHeader(USER_AGENT_INICAPS)))); 21 } 22 23 public boolean detectWindows(String userAgent) { 24 if (userAgent != null) { 25 userAgent = userAgent.toLowerCase(); 26 return userAgent.indexOf(WINDOWS) > -1; 27 } else { 28 return false; 29 } 30 } 31 32 public boolean detectInternetExplorer5Or6(HttpServletRequest request) { 33 if (request == null) { 34 return false; 35 } 36 return (this.detectInternetExplorer5Or6(request.getHeader(USER_AGENT))) || 37 (this.detectInternetExplorer5Or6(request.getHeader(USER_AGENT_INICAPS))); 38 } 39 40 public boolean detectInternetExplorer5Or6(String userAgent) { 41 if (userAgent != null) { 42 userAgent = userAgent.toLowerCase(); 43 return (userAgent.indexOf(INTERNET_EXPLORER_6) > -1) || (userAgent.indexOf(INTERNET_EXPLORER_5) > -1); 44 } else { 45 return false; 46 } 47 } 48 }