Convert a string to relative locale.

@param localeString the locale string
@return the locale
357277
public static Locale read(String localeString) {
		if (localeString == null)
			return null;
		if (localeString.toLowerCase().equals("default"))
			return Locale.getDefault();
		int languageIndex = localeString.indexOf('_');
		if (languageIndex == -1)
			return null;
		int countryIndex = localeString.indexOf('_', languageIndex + 1);
		String country = null;
		if (countryIndex == -1) {
			if (localeString.length() > languageIndex) {
				country = localeString.substring(languageIndex + 1, localeString.length());
			} else {
				return null;
			}
		}
		int variantIndex = -1;
		if (countryIndex != -1)
			countryIndex = localeString.indexOf('_', countryIndex + 1);
		String language = localeString.substring(0, languageIndex);
		String variant = null;
		if (variantIndex != -1) {

			variant = localeString.substring(variantIndex + 1, localeString.length());
		}
		if (variant != null) {
			return new Locale(language, country, variant);
		} else {
			return new Locale(language, country);
		}

	}
210381
public String toStringValue(ResourceTable resourceTable, Locale locale) {
        if (resourceTableMaps.length > 0) {
            return resourceTableMaps[0].toString();
        } else {
            return null;
        }
    }
1045031
public static String getLocalDisplayName(String locale) {
		String desc = "" + locale;
		if (locale != null) {
			String[] langArray = locale.split("_");
	        Locale loc = null;
	        if (langArray.length == 1) {
	            loc = new Locale(langArray[0]);
	        } else if (langArray.length == 2) {
	            loc = new Locale(langArray[0], langArray[1]);
	        } else if (langArray.length == 3) {
	            loc = new Locale(langArray[0], langArray[1], langArray[2]);
	        }
	        if (loc != null) {
	        	desc = loc.getDisplayLanguage(loc);
	        }
		}
		return desc;
	}
1130658
public static String toTitleCase(String string)
    {
        Check.notNull(string);

        final int length = string.length();
        final StringBuilder result = new StringBuilder(length);
        for (int i = 0; i < length; i++)
        {
            final String next = string.substring(i, i + 1);
            if (i == 0)
            {
                result.append(next.toUpperCase(Locale.ENGLISH));
            }
            else
            {
                result.append(next.toLowerCase(Locale.ENGLISH));
            }
        }
        return result.toString();
    }
1009411
public String getLocaleName(final Locale locale) {
        return messageResolver.getMessage(locale, String.format("color.%d.name", index));
    }
473604
private Locale getLocale(FacesContext context) {

        // PENDING(craigmcc) - JSTL localization context?
        Locale locale = this.locale;
        if (locale == null) {
            locale = context.getViewRoot().getLocale();
        }
        return (locale);

    }
1341259
public static JKLocale valueOf(final String localeString) {
		return localeString.equals(ARABIC.shortName) ? ARABIC : ENGLISH;
	}
902415
public static String toLowerCase(final String s) {
        if (s == null) {
            return null;
        } else {
            return s.toLowerCase(Locale.ENGLISH);
        }
    }
891232
private static Locale parseLocale(final String str) {
        if (isISO639LanguageCode(str)) {
            return new Locale(str);
        }

        final String[] segments = str.split("_", -1);
        final String language = segments[0];
        if (segments.length == 2) {
            final String country = segments[1];
            if (isISO639LanguageCode(language) && isISO3166CountryCode(country) ||
                    isNumericAreaCode(country)) {
                return new Locale(language, country);
            }
        } else if (segments.length == 3) {
            final String country = segments[1];
            final String variant = segments[2];
            if (isISO639LanguageCode(language) &&
                    (country.length() == 0 || isISO3166CountryCode(country) || isNumericAreaCode(country)) &&
                    variant.length() > 0) {
                return new Locale(language, country, variant);
            }
        }
        throw new IllegalArgumentException("Invalid locale format: " + str);
    }
191760
public static String getEncodingFromLocale(Locale locale) {
    	init();
        if (locale == cachedLocale) {
            return cachedEncoding;
        }

        String encoding = null;
        /*(String) _localeMap.get(locale.toString());

        if (encoding == null) {
            encoding = (String) _localeMap.get(locale.getLanguage() + "_" + locale.getCountry());

            if (encoding == null) {
                encoding = (String) _localeMap.get(locale.getLanguage());
            }            
        }*/
        if (encoding == null) {
            //check the com.ibm.wsspi.http.EncodingUtils
            com.ibm.wsspi.http.EncodingUtils encodingUtils = com.ibm.ws.webcontainer.osgi.WebContainer.getEncodingUtils();
            if (encodingUtils!=null) {
                encoding = encodingUtils.getEncodingFromLocale(locale);
            }
        }

        cachedEncoding = encoding;
        cachedLocale = locale;

        return encoding;
    }
17369
public static Locale parseLocale(String localeString) {
    if (localeString == null) {
      return Locale.US;
    }
    String[] groups = localeString.split("[-_]");
    switch (groups.length) {
      case 1:
        return new Locale(groups[0]);
      case 2:
        return new Locale(groups[0], Ascii.toUpperCase(groups[1]));
      case 3:
        return new Locale(groups[0], Ascii.toUpperCase(groups[1]), groups[2]);
      default:
        throw new IllegalArgumentException("Malformed localeString: " + localeString);
    }
  }
1251589
@Override
    public Locale getLocale() {
        ServletRESTRequestImpl ret = castRequest();
        if (ret != null)
            return ret.getLocale();
        return null;
    }
668365
public static String getLocalizedString(String key, Object ... args) {
        return JavacMessages.getDefaultLocalizedString(PrefixKind.COMPILER_MISC.key(key), args);
    }
514247
public static void setLocale(@NonNull Locale locale) {
        if (!locale.equals(Locale.getDefault())) {
            LocalizationHelper.locale = locale;
            Locale.setDefault(locale);
        }
    }
924960
public static Locale getLocale() {
        final Locale ret = LOCALE.get();
        if (null == ret) {
            return Latkes.getLocale();
        }

        return ret;
    }
758188
private Locale getLocale(String localeName) throws ToolException {
        Locale userlocale = null;
        if (localeName == null || localeName.isEmpty()) {
            return Locale.getDefault();
        }
        int firstuscore = localeName.indexOf('_');
        int seconduscore = -1;
        String language = null;
        String country = null;
        String variant = null;
        if (firstuscore == 2) {
            language = localeName.substring(0, firstuscore);
            seconduscore = localeName.indexOf('_', firstuscore + 1);
            if (seconduscore > 0) {
                if (seconduscore != firstuscore + 3
                        || localeName.length() <= seconduscore + 1) {
                    String text = messager.getText("main.malformed_locale_name", localeName);
                    throw new ToolException(CMDERR, text);
                }
                country = localeName.substring(firstuscore + 1,
                        seconduscore);
                variant = localeName.substring(seconduscore + 1);
            } else if (localeName.length() == firstuscore + 3) {
                country = localeName.substring(firstuscore + 1);
            } else {
                String text = messager.getText("main.malformed_locale_name", localeName);
                throw new ToolException(CMDERR, text);
            }
        } else if (firstuscore == -1 && localeName.length() == 2) {
            language = localeName;
        } else {
            String text = messager.getText("main.malformed_locale_name", localeName);
            throw new ToolException(CMDERR, text);
        }
        userlocale = searchLocale(language, country, variant);
        if (userlocale == null) {
            String text = messager.getText("main.illegal_locale_name", localeName);
            throw new ToolException(CMDERR, text);
        } else {
            return userlocale;
        }
    }
1293719
public static String toUpperCase(String string, Locale locale) {

    if (locale == null) {
      return toUpperCase(string, STANDARD_LOCALE);
    }
    return string.toUpperCase(locale);
  }