/**
 * Copyright (c) 2014-2016 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.eclipse.smarthome.io.rest;

import java.util.Locale;

import org.eclipse.smarthome.io.rest.internal.RESTActivator;

/**
 * {@link LocaleUtil} provides helper method for working with locales in REST
 * resources.
 *
 * @author Dennis Nobel - Initial contribution
 * @author Markus Rathgeb - Use locale provider
 */
public class LocaleUtil {

    /**
     * Returns the locale in respect to the given "Accept-Language" HTTP header.
     *
     * @param language
     *            value of the "Accept-Language" HTTP header (can be null).
     * @return Locale for the "Accept-Language" HTTP header or default locale if
     *         header is not set or can not be parsed.
     */
    public static Locale getLocale(String acceptLanguageHttpHeader) {
        Locale locale = RESTActivator.getLocale();
        if (acceptLanguageHttpHeader != null) {
            String[] split = acceptLanguageHttpHeader.split("-");
            if (split.length == 2) {
                locale = new Locale(split[0], split[1]);
            } else {
                locale = new Locale(split[0]);
            }
        }
        return locale;
    }

}

@@ -633,16 +633,93 @@
 rovider%0A
+ * @author Martin Herbst - Support of different language definition variants%0A
  */%0Apubl
@@ -1265,61 +1265,287 @@
     
-String%5B%5D split = acceptLanguageHttpHeader.split(%22-%22);
+int pos = acceptLanguageHttpHeader.indexOf(',');%0A            String%5B%5D split;%0A            if (pos %3E -1) %7B%0A                split = acceptLanguageHttpHeader.substring(0, pos).split(%22-%22);%0A            %7D else %7B%0A                split = acceptLanguageHttpHeader.split(%22-%22);%0A            %7D
 %0A   

Support of different Accept-Language HTTP header variants (#2699)