Skip to content
This repository has been archived by the owner on Jan 9, 2018. It is now read-only.

Commit

Permalink
Support of different Accept-Language HTTP header variants (eclipse-ar…
Browse files Browse the repository at this point in the history
…chived#2699)

The content of the Accept-Language HTTP header variants my contain
comma-separated values. In this case the created Locale was not valid.
Now only the first parameter passed in the header is used.

Signed-off-by: Martin Herbst <[email protected]>
  • Loading branch information
MHerbst authored and chaton78 committed May 7, 2017
1 parent ae845d3 commit c4b22d7
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* @author Dennis Nobel - Initial contribution
* @author Markus Rathgeb - Use locale provider
* @author Martin Herbst - Support of different language definition variants
*/
public class LocaleUtil {

Expand All @@ -31,7 +32,13 @@ public class LocaleUtil {
public static Locale getLocale(String acceptLanguageHttpHeader) {
Locale locale = RESTActivator.getLocale();
if (acceptLanguageHttpHeader != null) {
String[] split = acceptLanguageHttpHeader.split("-");
int pos = acceptLanguageHttpHeader.indexOf(',');
String[] split;
if (pos > -1) {
split = acceptLanguageHttpHeader.substring(0, pos).split("-");
} else {
split = acceptLanguageHttpHeader.split("-");
}
if (split.length == 2) {
locale = new Locale(split[0], split[1]);
} else {
Expand Down

0 comments on commit c4b22d7

Please sign in to comment.