Given a string representing a Locale, returns the Locale object for that string.

@return A Locale object built from the string provided
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);
    }
  }
1169605
@Deprecated
    public static Locale getLocale() {
        Locale locale = null;
        FacesContext facesContext = FacesContext.getCurrentInstance();

        if (facesContext != null && facesContext.getViewRoot() != null) {
            locale = facesContext.getViewRoot().getLocale();

            if (locale == null) {
                locale = Locale.getDefault();
            }
        }
        else {
            locale = Locale.getDefault();
        }
        return locale;
    }
1223683
String getLocalName() {

        if (!locale_set) {
            setLocale(Locale.getDefault());
        }

        String key = this.getTypeName();

        return BundleHandler.getString(hnd_local_names, key);
    }
186428
public static String getJavaName(Locale locale)
  {
    if (locale == null)
      return null;

    return getJavaName(getMimeName(locale));
  }
673150
public static Locale getLocaleFromString(String localeString) {
        if (localeString == null) {
            return null;
        }
        localeString = localeString.trim();
        if (localeString.toLowerCase().equals("default")) {
            return Locale.getDefault();
        }

        // Extract language
        int languageIndex = localeString.indexOf('_');
        String language = null;
        if (languageIndex == -1) {
            // No further "_" so is "{language}" only
            return new Locale(localeString, "");
        } else {
            language = localeString.substring(0, languageIndex);
        }

        // Extract country
        int countryIndex = localeString.indexOf('_', languageIndex + 1);
        String country = null;
        if (countryIndex == -1) {
            // No further "_" so is "{language}_{country}"
            country = localeString.substring(languageIndex + 1);
            return new Locale(language, country);
        } else {
            // Assume all remaining is the variant so is "{language}_{country}_{variant}"
            country = localeString.substring(languageIndex + 1, countryIndex);
            String variant = localeString.substring(countryIndex + 1);
            return new Locale(language, country, variant);
        }
    }
563166
private Locale extractLocale() {

        Locale loc = null;
        int underscore = m_name.lastIndexOf("_");
        if (underscore > -1) {
            String localeName = m_name.substring(underscore + 1);
            if (localeName.lastIndexOf(".") > -1) {
                localeName = localeName.substring(0, localeName.lastIndexOf("."));
            }
            loc = CmsLocaleManager.getLocale(localeName);
        }

        return loc;
    }
1042925
public static Locale getLocaleFromName(String name) {
        String language = "";
        String country = "";
        String variant = "";

        int i1 = name.indexOf('_');
        if (i1 < 0) {
            language = name;
        } else {
            language = name.substring(0, i1);
            ++i1;
            int i2 = name.indexOf('_', i1);
            if (i2 < 0) {
                country = name.substring(i1);
            } else {
                country = name.substring(i1, i2);
                variant = name.substring(i2+1);
            }
        }

        return new Locale(language, country, variant);
    }
1092631
public Locale getElementLocale() {

        if (m_elementLocale == null) {
            if (CmsStringUtil.isNotEmpty(getParamElementlanguage()) && !"null".equals(getParamElementlanguage())) {
                m_elementLocale = CmsLocaleManager.getLocale(getParamElementlanguage());
            } else {
                initElementLanguage();
                m_elementLocale = CmsLocaleManager.getLocale(getParamElementlanguage());
            }
        }
        return m_elementLocale;
    }
120470
public Locale parseLocale(String localeString) {
        String language = null;
        String country = null;
        String variant = null;

        // Sometimes people specify "en-US" instead of "en_US", so
        // we'll try to clean that up.
        localeString = localeString.replaceAll("-", "_");

        StringTokenizer st = new StringTokenizer(localeString, "_");

        if (st.hasMoreTokens()) {
            language = st.nextToken();
        }
        if (st.hasMoreTokens()) {
            country = st.nextToken();
        }
        if (st.hasMoreTokens()) {
            variant = st.nextToken();
        }

        Locale locale = null;

        if (variant != null) {
            locale = new Locale(language, country, variant);
        } else if (country != null) {
            locale = new Locale(language, country);
        } else if (language != null) {
            locale = new Locale(language);
        }

        return locale;
    }
672592
private static String toLanguageTag(Locale locale) {
        if (locale == null) {
            return null;
        }
        StringBuilder tag = new StringBuilder();

        tag.append(locale.getLanguage().toLowerCase());

        if (!locale.getCountry().isEmpty()) {
            tag.append("-");
            tag.append(locale.getCountry().toUpperCase());
        }

        return tag.toString();
    }
1176626
@Override
    public String getEncodingFromLocale(Locale locale) {
        if (null == locale) {
            return null;
        }
        if (locale.equals(this.cachedLocale)) {
            return this.cachedEncoding;
        }

        String encoding = localeMap.get(locale.toString());
        if (null == encoding) {
            final String lang = locale.getLanguage();
            encoding = localeMap.get(lang + '_' + locale.getCountry());
            if (null == encoding) {
                encoding = localeMap.get(lang);
            }
        }

        this.cachedEncoding = encoding;
        this.cachedLocale = locale;

        return encoding;
    }
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;
        }
    }
473604
private Locale getLocale(FacesContext context) {

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

    }
622236
public static Locale getLocale(final String anEncoding) {
        Locale aLocale = null;
        String country = null;
        String language = null;
        String variant;

        //Tokenize the string using "-" as the token string as per IETF RFC4646 (superceeds RFC3066).

        final StringTokenizer tokenizer = new StringTokenizer(anEncoding, "-");

        //We need to know how many tokens we have so we can create a Locale object with the proper constructor.
        final int numberOfTokens = tokenizer.countTokens();

        if (numberOfTokens == 1) {
            final String tempString = tokenizer.nextToken().toLowerCase();

            //Note: Newer XML parsers should throw an error if the xml:lang value contains
            //underscore. But this is not guaranteed.

            //Check to see if some one used "en_US" instead of "en-US".
            //If so, the first token will contain "en_US" or "xxx_YYYYYYYY". In this case,
            //we will only grab the value for xxx.
            final int underscoreIndex = tempString.indexOf("_");

            if (underscoreIndex == -1) {
                language = tempString;
            } else if (underscoreIndex == 2 || underscoreIndex == 3) {
                //check is first subtag is two or three characters in length.
                language = tempString.substring(0, underscoreIndex);
            }

            aLocale = new Locale(language);
        } else if (numberOfTokens == 2) {

            language = tokenizer.nextToken().toLowerCase();

            final String subtag2 = tokenizer.nextToken();
            //All country tags should be three characters or less.
            //If the subtag is longer than three characters, it assumes that
            //is a dialect or variant.
            if (subtag2.length() <= 3) {
                country = subtag2.toUpperCase();
                aLocale = new Locale(language, country);
            } else if (subtag2.length() > 3 && subtag2.length() <= 8) {
                variant = subtag2;
                aLocale = new Locale(language, "", variant);
            } else if (subtag2.length() > 8) {
                //return an error!
            }



        } else if (numberOfTokens >= 3) {

            language = tokenizer.nextToken().toLowerCase();
            final String subtag2 = tokenizer.nextToken();
            if (subtag2.length() <= 3) {
                country = subtag2.toUpperCase();
            } else if (subtag2.length() > 3 && subtag2.length() <= 8) {
            } else if (subtag2.length() > 8) {
                //return an error!
            }
            variant = tokenizer.nextToken();

            aLocale = new Locale(language, country, variant);

        } else {
            //return an warning or do nothing.
            //The xml:lang attribute is empty.
            aLocale = new Locale(LANGUAGE_EN,
                    COUNTRY_US);

        }

        return aLocale;
    }
718615
public Locale getLocale() {
		Locale l = wbRequest.getLocale();
		if (l == null) {
			l = Locale.getAvailableLocales()[0];
		}
		return l;
	}
891245
public Locale getLocale() {
        UI currentUI = UI.getCurrent();
        Locale locale = currentUI == null ? null : currentUI.getLocale();
        if (locale == null) {
            locale = Locale.getDefault();
        }
        return locale;
    }
847047
public static String getLanguage(final String localeString) {
        if (localeString.length() >= LANG_END) {
            return localeString.substring(LANG_START, LANG_END);
        }

        return "";
    }