You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2010/03/29 15:13:49 UTC
svn commit: r928764 - in /myfaces/tobago/trunk/core/src:
main/java/org/apache/myfaces/tobago/context/UserAgent.java
test/java/org/apache/myfaces/tobago/context/UserAgentUnitTest.java
Author: lofwyr
Date: Mon Mar 29 13:13:48 2010
New Revision: 928764
URL: http://svn.apache.org/viewvc?rev=928764&view=rev
Log:
TOBAGO-866: Add some browsers and a unit test
Added:
myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/context/UserAgentUnitTest.java
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/UserAgent.java
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/UserAgent.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/UserAgent.java?rev=928764&r1=928763&r2=928764&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/UserAgent.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/UserAgent.java Mon Mar 29 13:13:48 2010
@@ -25,7 +25,7 @@ import java.util.Locale;
public class UserAgent implements Serializable {
- private static final long serialVersionUID = -3138810465122379395L;
+ private static final long serialVersionUID = 2L;
public static final String DEFAULT_NAME = "standard";
@@ -34,36 +34,64 @@ public class UserAgent implements Serial
public static final UserAgent MSIE = new UserAgent("msie", null);
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static final UserAgent MSIE_5_0 = new UserAgent("msie", "5_0");
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static final UserAgent MSIE_5_5 = new UserAgent("msie", "5_5");
public static final UserAgent MSIE_6_0 = new UserAgent("msie", "6_0");
- public static final UserAgent MSIE_7_O = new UserAgent("msie", "7_0");
+ public static final UserAgent MSIE_7_0 = new UserAgent("msie", "7_0");
+ /** @deprecated no longer supported, since Tobago 1.5. Misspelled */
+ @Deprecated
+ public static final UserAgent MSIE_7_O = MSIE_7_0;
+
+ public static final UserAgent MSIE_8_0 = new UserAgent("msie", "8_0");
+
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static final UserAgent MSIE_5_0_MAC = new UserAgent("msie", "5_0_mac");
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static final UserAgent MSIE_6_0_MAC = new UserAgent("msie", "6_0_mac");
public static final UserAgent OPERA = new UserAgent("opera", null);
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static final UserAgent OPERA_5_0 = new UserAgent("opera", "5_0");
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static final UserAgent OPERA_6_0 = new UserAgent("opera", "6_0");
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static final UserAgent OPERA_7_11 = new UserAgent("opera", "7_11");
public static final UserAgent MOZILLA = new UserAgent("mozilla", null);
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static final UserAgent MOZILLA_4_7 = new UserAgent("mozilla", "4_7");
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static final UserAgent MOZILLA_5_0 = new UserAgent("mozilla", "5_0");
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static final UserAgent MOZILLA_5_0_R1_6 = new UserAgent("mozilla", "5_0_r1_6");
+ public static final UserAgent GECKO = new UserAgent("gecko", null);
+
private String name;
@@ -108,43 +136,48 @@ public class UserAgent implements Serial
return DEFAULT;
}
+ // remove .replace('/', ' ')
header = header.toLowerCase(Locale.ENGLISH).replace('/', ' ');
- if (header.indexOf("opera") > -1) {
- if (header.indexOf("opera 5.0") > -1) {
+ if (header.contains("opera")) {
+ if (header.contains("opera 5.0")) {
return OPERA_5_0;
- } else if (header.indexOf("opera 6.0") > -1) {
+ } else if (header.contains("opera 6.0")) {
return OPERA_6_0;
- } else if (header.indexOf("opera 7.11") > -1) {
+ } else if (header.contains("opera 7.11")) {
return OPERA_7_11;
} else {
return OPERA;
}
- } else if (header.indexOf("msie") > -1) {
- if (header.indexOf("msie 5.0") > -1) {
- if (header.indexOf("mac") > -1) {
+ } else if (header.contains("msie")) {
+ if (header.contains("msie 5.0")) {
+ if (header.contains("mac")) {
return MSIE_5_0_MAC;
} else {
return MSIE_5_0;
}
- } else if (header.indexOf("msie 5.5") > -1) {
+ } else if (header.contains("msie 5.5")) {
return MSIE_5_5;
- } else if (header.indexOf("msie 6.0") > -1) {
- if (header.indexOf("mac") > -1) {
+ } else if (header.contains("msie 6.0")) {
+ if (header.contains("mac")) {
return MSIE_6_0_MAC;
} else {
return MSIE_6_0;
}
- } else if (header.indexOf("msie 7.0") > -1) {
- return MSIE_7_O;
+ } else if (header.contains("msie 7.0")) {
+ return MSIE_7_0;
+ } else if (header.contains("msie 8.0")) {
+ return MSIE_8_0;
} else {
return MSIE;
}
- } else if (header.indexOf("mozilla") > -1) {
- if (header.indexOf("mozilla 4.7") > -1) {
+ } else if (header.contains("mozilla")) {
+ if (header.contains("mozilla 4.7")) {
return MOZILLA_4_7;
- } else if (header.indexOf("mozilla 5.0") > -1) {
- if (header.indexOf("rv:1.6") > -1) {
+ } else if (header.contains("mozilla 5.0")) {
+ if (header.contains("rv:1.6")) {
return MOZILLA_5_0_R1_6;
+ } else if (header.contains("gecko")) {
+ return GECKO;
} else {
return MOZILLA_5_0;
}
@@ -156,6 +189,8 @@ public class UserAgent implements Serial
return DEFAULT;
}
+ /** @deprecated no longer supported, since Tobago 1.5 */
+ @Deprecated
public static UserAgent getInstanceForId(String id) {
if (id == null) {
return DEFAULT;
@@ -183,7 +218,7 @@ public class UserAgent implements Serial
} else if (id.equals("msie_6_0_mac")) {
return MSIE_6_0_MAC;
} else if (id.equals("msie_7_0")) {
- return MSIE_7_O;
+ return MSIE_7_0;
} else {
return MSIE;
}
@@ -204,8 +239,9 @@ public class UserAgent implements Serial
/**
- * @deprecated don't use toString() functionallity!
+ * @deprecated don't use toString() functionality!
*/
+ @Deprecated
public String toString() {
return version != null
? name + '_' + version
Added: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/context/UserAgentUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/context/UserAgentUnitTest.java?rev=928764&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/context/UserAgentUnitTest.java (added)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/context/UserAgentUnitTest.java Mon Mar 29 13:13:48 2010
@@ -0,0 +1,43 @@
+package org.apache.myfaces.tobago.context;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+public class UserAgentUnitTest {
+
+ private static final String IE_8_WINDOWS_XP
+ = "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727;"
+ + " .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
+ private static final String FIREFOX_3_6_UBUNTU_10_4
+ = "User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100308 Ubuntu/10.04 (lucid)"
+ + " Firefox/3.6";
+ private static final String OPERA_10_10_MACOSX
+ = "User-Agent: Opera/9.80 (Macintosh; Intel Mac OS X; U; de) Presto/2.2.15 Version/10.10";
+
+ @Test
+ public void test() {
+
+ Assert.assertEquals(UserAgent.MSIE_8_0, UserAgent.getInstance(IE_8_WINDOWS_XP));
+
+ Assert.assertEquals(UserAgent.GECKO, UserAgent.getInstance(FIREFOX_3_6_UBUNTU_10_4));
+
+ Assert.assertEquals(UserAgent.OPERA, UserAgent.getInstance(OPERA_10_10_MACOSX));
+ }
+}