/*
 * 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.
 */
package org.apache.wicket.protocol.http.request;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.util.string.Strings;

/**
 * UserAgent
 */
enum UserAgent {

	MOZILLA("Opera,AppleWebKit,Konqueror", Arrays.asList("Mozilla", "Gecko")),

	FIREFOX("Opera,AppleWebKit,Konqueror", Arrays.asList("Mozilla", "Gecko", "Firefox")),

	INTERNET_EXPLORER("Opera", Arrays.asList("Mozilla", "MSIE", "Windows"), Arrays.asList(
		"Mozilla", "MSIE", "Trident"), Arrays.asList("Mozilla", "MSIE", "Mac_PowerPC")),

	OPERA(Arrays.asList("Opera")),

	CHROME(Arrays.asList("Mozilla", "Chrome", "AppleWebKit", "Safari")),

	SAFARI("Chrome", Arrays.asList("Mozilla", "AppleWebKit", "Safari")),

	KONQUEROR(Arrays.asList("Konqueror"));

	/**
	 * Comma separated list with values which are not allowed in the user agent.
	 */
	private final String notAllowed;

	/**
	 * A list with strings which has to be in the user agent string.
	 */
	private final List<String>[] detectionStrings;

	/**
	 * Construct.
	 * 
	 * @param notAllowed
	 *            comma separated list with values which are not allowed in the user agent
	 * @param detectionStrings
	 *            a list with strings which has to be in the user agent string
	 */
	UserAgent(String notAllowed, List<String>... detectionStrings)
	{
		this.notAllowed = notAllowed;
		this.detectionStrings = detectionStrings;
	}

	/**
	 * Construct.
	 * 
	 * @param detectionStrings
	 *            list with string which has to be in the user agent string
	 */
	UserAgent(List<String>... detectionStrings)
	{
		this(null, detectionStrings);
	}

	/**
	 * @param userAgent
	 *            The user agent string
	 * @return Whether the user agent matches this enum or not
	 */
	public boolean matches(String userAgent)
	{
		if (Strings.isEmpty(notAllowed) == false)
		{
			String[] notAllowedList = Strings.split(notAllowed, ',');
			for (String value : notAllowedList)
			{
				if (userAgent.contains(value))
				{
					return false;
				}
			}
		}

		for (List<String> detectionGroup : detectionStrings)
		{
			for (String detectionString : detectionGroup)
			{
				if (!userAgent.contains(detectionString))
				{
					return false;
				}
			}

			return true;
		}

		return false;
	}
}
@@ -1547,33 +1547,11 @@
 %09 * 
-Comma separated list with
+The
  val
@@ -1617,24 +1617,26 @@
 final String
+%5B%5D
  notAllowed;
@@ -1634,16 +1634,20 @@
 tAllowed
+List
 ;%0A%0A%09/**%0A
@@ -2079,21 +2079,16 @@
 s)%0A%09%7B%0A%09%09
-this.
 notAllow
@@ -2089,19 +2089,37 @@
 tAllowed
- = 
+List = Strings.split(
 notAllow
@@ -2120,16 +2120,22 @@
 tAllowed
+, ',')
 ;%0A%09%09this
@@ -2574,62 +2574,8 @@
 if (
-Strings.isEmpty(notAllowed) == false)%0A%09%09%7B%0A%09%09%09String%5B%5D 
 notA
@@ -2589,41 +2589,20 @@
 ist 
+!
 = 
-Strings.split(notAllowed, ',');
+null)%0A%09%09%7B
 %0A%09%09%09

WICKET-3713 org/apache/wicket/protocol/http/request/UserAgent matches method is not correct