1 38 package com.gargoylesoftware.htmlunit; 39 40 41 57 public class BrowserVersion { 58 private String applicationCodeName_ = APP_CODE_NAME; 59 private String applicationMinorVersion_ = "0"; 60 private String applicationName_; 61 private String applicationVersion_; 62 private String browserLanguage_ = LANGUAGE_ENGLISH_US; 63 private String cpuClass_ = CPU_CLASS_X86; 64 private boolean onLine_ = true; 65 private String platform_ = PLATFORM_WIN32; 66 private String systemLanguage_ = LANGUAGE_ENGLISH_US; 67 private String userAgent_; 68 private String userLanguage_ = LANGUAGE_ENGLISH_US; 69 private String javaScriptVersion_; 70 private float javaScriptVersionNumeric_; 71 private float browserVersionNumeric_; 72 73 74 public static final String APP_CODE_NAME = "Mozilla"; 75 76 77 public static final String INTERNET_EXPLORER = "Microsoft Internet Explorer"; 78 79 80 public static final String NETSCAPE = "Netscape"; 81 82 83 public static final String LANGUAGE_ENGLISH_US = "en-us"; 84 85 86 public static final String CPU_CLASS_X86 = "x86"; 87 88 89 public static final String PLATFORM_WIN32 = "Win32"; 90 91 95 public static final BrowserVersion FULL_FEATURED_BROWSER = new BrowserVersion( 96 INTERNET_EXPLORER, "4.0 (compatible; MSIE 6.0b; Windows 98)", 97 "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)", "1.2", 6); 98 99 100 public static final BrowserVersion MOZILLA_1_0 = new BrowserVersion( 101 NETSCAPE, "5.0 (Windows; en-US)", 102 "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.0) Gecko/20020530", "1.2", 6); 103 104 105 public static final BrowserVersion NETSCAPE_4_7_9 = new BrowserVersion( 106 NETSCAPE, "4.79 [en] (Windows NT 5.0; U)", 107 "Mozilla/4.79 [en] (Windows NT 5.0; U)", "1.2", 4.79f); 108 109 110 public static final BrowserVersion NETSCAPE_6_2_3 = new BrowserVersion( 111 NETSCAPE, "5.0 (Windows; en-US)", 112 "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US;rv:0.9.4.1) Gecko/20020508 Netscape6/6.2.3", 113 "1.2", 6); 114 115 116 public static final BrowserVersion INTERNET_EXPLORER_6_0 = new BrowserVersion( 117 INTERNET_EXPLORER, "4.0 (compatible; MSIE 6.0b; Windows 98)", 118 "4.0 (compatible; MSIE 6.0; Windows 98)", "1.2", 6); 119 120 private static BrowserVersion DefaultBrowserVersion_ = FULL_FEATURED_BROWSER; 121 122 123 132 public BrowserVersion( final String applicationName, final String applicationVersion, 133 final String userAgent, final String javaScriptVersion, final float browserVersionNumeric) { 134 135 applicationName_ = applicationName; 136 setApplicationVersion(applicationVersion); 137 userAgent_ = userAgent; 138 setJavaScriptVersion(javaScriptVersion); 139 browserVersionNumeric_ = browserVersionNumeric; 140 } 141 142 143 147 public static BrowserVersion getDefault() { 148 return DefaultBrowserVersion_; 149 } 150 151 152 156 public static void setDefault( final BrowserVersion newBrowserVersion ) { 157 Assert.notNull("newBrowserVersion", newBrowserVersion); 158 DefaultBrowserVersion_ = newBrowserVersion; 159 } 160 161 162 167 public final boolean isIE() { 168 return INTERNET_EXPLORER.equals( getApplicationName() ); 169 } 170 171 172 177 public final boolean isNetscape() { 178 return NETSCAPE.equals( getApplicationName() ); 179 } 180 181 182 189 public String getApplicationCodeName() { 190 return applicationCodeName_; 191 } 192 193 194 201 public String getApplicationMinorVersion() { 202 return applicationMinorVersion_; 203 } 204 205 206 212 public String getApplicationName() { 213 return applicationName_; 214 } 215 216 217 223 public String getApplicationVersion() { 224 return applicationVersion_; 225 } 226 227 228 235 public String getBrowserLanguage() { 236 return browserLanguage_; 237 } 238 239 240 247 public String getCpuClass() { 248 return cpuClass_; 249 } 250 251 252 259 public boolean isOnLine() { 260 return onLine_; 261 } 262 263 264 271 public String getPlatform() { 272 return platform_; 273 } 274 275 276 283 public String getSystemLanguage() { 284 return systemLanguage_; 285 } 286 287 288 292 public String getUserAgent() { 293 return userAgent_; 294 } 295 296 297 304 public String getUserLanguage() { 305 return userLanguage_; 306 } 307 308 309 313 public String getJavaScriptVersion() { 314 return javaScriptVersion_; 315 } 316 317 320 public void setApplicationCodeName(final String applicationCodeName) { 321 applicationCodeName_ = applicationCodeName; 322 } 323 324 327 public void setApplicationMinorVersion(final String applicationMinorVersion) { 328 applicationMinorVersion_ = applicationMinorVersion; 329 } 330 331 334 public void setApplicationName(final String applicationName) { 335 applicationName_ = applicationName; 336 } 337 338 341 public void setApplicationVersion(final String applicationVersion) { 342 applicationVersion_ = applicationVersion; 343 } 344 345 348 public void setBrowserLanguage(final String browserLanguage) { 349 browserLanguage_ = browserLanguage; 350 } 351 352 355 public void setCpuClass(final String cpuClass) { 356 cpuClass_ = cpuClass; 357 } 358 359 362 public void setJavaScriptVersion(final String javaScriptVersion) { 363 javaScriptVersion_ = javaScriptVersion; 364 javaScriptVersionNumeric_ = Float.parseFloat(javaScriptVersion); 365 } 366 367 370 public void setOnLine(final boolean onLine) { 371 onLine_ = onLine; 372 } 373 374 377 public void setPlatform(final String platform) { 378 platform_ = platform; 379 } 380 381 384 public void setSystemLanguage(final String systemLanguage) { 385 systemLanguage_ = systemLanguage; 386 } 387 388 391 public void setUserAgent(final String userAgent) { 392 userAgent_ = userAgent; 393 } 394 395 398 public void setUserLanguage(final String userLanguage) { 399 userLanguage_ = userLanguage; 400 } 401 404 public void setBrowserVersion(float browserVersion) { 405 browserVersionNumeric_ = browserVersion; 406 } 407 410 public float getBrowserVersionNumeric() { 411 return browserVersionNumeric_; 412 } 413 416 public float getJavaScriptVersionNumeric() { 417 return javaScriptVersionNumeric_; 418 } 419 } 420 | Popular Tags |