/*
 *  Copyright 2011 Eric F. Savage, code@efsavage.com
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package com.ajah.http;

/**
 * Enum of browser types. Note that this class is currently incomplete and only
 * does some basic tests for Chrome.
 * 
 * @author <a href="http://efsavage.com">Eric F. Savage</a>, <a
 *         href="mailto:code@efsavage.com">code@efsavage.com</a>.
 * 
 */
public enum Browser {

	/**
	 * Internet Explorer
	 */
	IE,
	/**
	 * Mozilla Firefox
	 */
	FIREFOX,
	/**
	 * Google Chrome
	 */
	CHROME,
	/**
	 * Opera
	 */
	OPERA,
	/**
	 * Unknown
	 */
	UNKNOWN;

	/**
	 * Looks at user agent string and extracts browser.
	 * 
	 * @param userAgent
	 *            The user agent string
	 * @return The browser, if one can be deduced, or {@link #UNKNOWN}.
	 */
	public static Browser get(final String userAgent) {
		if (userAgent.contains("(KHTML, like Gecko) Chrome/")) {
			return CHROME;
		} else if (userAgent.contains("(KHTML,like Gecko) Chrome/")) {
			return CHROME;
		} else if (userAgent.contains("(KHTML, like Gecko) Slackware/Chrome/")) {
			return CHROME;
		} else if (userAgent.contains("(KHTML, like Gecko) Ubuntu/10.10 Chrome/")) {
			return CHROME;
		} else if (userAgent.contains("Chrome/4.")) {
			return CHROME;
		} else if (userAgent.contains("Gecko/2009032609 Chrome/")) {
			return CHROME;
		} else if (userAgent.contains("Chromium/")) {
			return CHROME;
		}
		return UNKNOWN;
	}

}

@@ -14,16 +14,21 @@
 ght 2011
+-2012
  Eric F.
@@ -979,16 +979,46 @@
 %09 */%0A%09IE
+(1, %22Internet Explorer%22, %22IE%22)
 ,%0A%09/**%0A%09
@@ -1049,16 +1049,36 @@
 %09FIREFOX
+(2, %22Firefox%22, %22FF%22)
 ,%0A%09/**%0A%09
@@ -1106,16 +1106,36 @@
 %0A%09CHROME
+(3, %22Chrome%22, %22CHR%22)
 ,%0A%09/**%0A%09
@@ -1158,41 +1158,354 @@
 PERA
-,%0A%09/**%0A%09 * Unknown%0A%09 */%0A%09UNKNOWN;
+(4, %22Opera%22, %22OP%22),%0A%09/**%0A%09 * Safari%0A%09 */%0A%09SAFARI(5, %22Safari%22, %22SAF%22),%0A%09/**%0A%09 * Unknown%0A%09 */%0A%09UNKNOWN(0, %22Unknown%22, %22?%22);%0A%0A%09private final int id;%0A%09private final String name;%0A%09private final String abbreviation;%0A%0A%09private Browser(int id, String name, String abbreviation) %7B%0A%09%09this.id = id;%0A%09%09this.name = name;%0A%09%09this.abbreviation = abbreviation;%0A%0A%09%7D
 %0A%0A%09/
@@ -2340,10 +2340,628 @@
 WN;%0A%09%7D%0A%0A
+%09/**%0A%09 * Returns the unique ID of this browser. Note that this value is arbitrary%0A%09 * and does not come from the browser itself.%0A%09 * %0A%09 * @return the id The unique internal ID of the browser.%0A%09 */%0A%09public int getId() %7B%0A%09%09return this.id;%0A%09%7D%0A%0A%09/**%0A%09 * Returns the common name of the browser. E.G. %22Internet Explorer%22.%0A%09 * %0A%09 * @return the common name of the browser.%0A%09 */%0A%09public String getName() %7B%0A%09%09return this.name;%0A%09%7D%0A%0A%09/**%0A%09 * Returns the common abbreviation of the browser. E.G. %22IE%22.%0A%09 * %0A%09 * @return the common abbreviation of the browser.%0A%09 */%0A%09public String getAbbreviation() %7B%0A%09%09return this.abbreviation;%0A%09%7D%0A%0A
 %7D%0A

Add Safari, name & id properties