Example usage for org.apache.commons.lang LocaleUtils toLocale

List of usage examples for org.apache.commons.lang LocaleUtils toLocale

Introduction

In this page you can find the example usage for org.apache.commons.lang LocaleUtils toLocale.

Prototype

public static Locale toLocale(String str) 

Source Link

Document

Converts a String to a Locale.

This method takes the string format of a locale and creates the locale object from it.

 LocaleUtils.toLocale("en")         = new Locale("en", "") LocaleUtils.toLocale("en_GB")      = new Locale("en", "GB") LocaleUtils.toLocale("en_GB_xxx")  = new Locale("en", "GB", "xxx")   (#) 

(#) The behaviour of the JDK variant constructor changed between JDK1.3 and JDK1.4.

Usage

From source file:org.xwiki.search.solr.internal.reference.SolrEntityReferenceResolver.java

private EntityReference getDocumentReferenceWithLocale(SolrDocument solrDocument, EntityReference parent,
        Object... parameters) {/*from   www.  j  a v a2 s  .c o m*/
    EntityReference documentReference = getDocumentReference(solrDocument, parent, parameters);
    String localeString = getFieldStringValue(solrDocument, FieldUtils.DOCUMENT_LOCALE);
    if (!StringUtils.isEmpty(localeString)) {
        documentReference = new DocumentReference(documentReference, LocaleUtils.toLocale(localeString));
    }
    return documentReference;
}

From source file:reconf.infra.i18n.LocaleHolder.java

public static Locale value() {
    if (StringUtils.isNotBlank(providedLocale)) {
        try {//from   w  w  w. ja va  2 s .  c o m
            return LocaleUtils.toLocale(providedLocale);
        } catch (IllegalArgumentException e) {
            LoggerHolder.getLog().error(String.format("invalid locale [%s]. assuming default [%s]",
                    providedLocale, Locale.getDefault()));
        }
    }
    return Locale.getDefault();
}