Example usage for com.liferay.portal.kernel.util LocaleThreadLocal getDefaultLocale

List of usage examples for com.liferay.portal.kernel.util LocaleThreadLocal getDefaultLocale

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util LocaleThreadLocal getDefaultLocale.

Prototype

public static Locale getDefaultLocale() 

Source Link

Usage

From source file:com.liferay.journal.internal.upgrade.v0_0_3.UpgradeJournalArticleType.java

License:Open Source License

protected void updateArticleType() throws Exception {
    try (LoggingTimer loggingTimer = new LoggingTimer()) {
        if (!hasSelectedArticleTypes()) {
            return;
        }//from w  ww. j a  va2  s .c  om

        List<String> types = getArticleTypes();

        if (types.size() <= 0) {
            return;
        }

        Locale localeThreadLocalDefaultLocale = LocaleThreadLocal.getDefaultLocale();

        try {
            List<Company> companies = _companyLocalService.getCompanies();

            for (Company company : companies) {
                LocaleThreadLocal.setDefaultLocale(company.getLocale());

                Set<Locale> locales = LanguageUtil.getAvailableLocales(company.getGroupId());

                Locale defaultLocale = LocaleUtil
                        .fromLanguageId(UpgradeProcessUtil.getDefaultLanguageId(company.getCompanyId()));

                Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(locales, defaultLocale,
                        "type");

                AssetVocabulary assetVocabulary = addAssetVocabulary(company.getGroupId(),
                        company.getCompanyId(), "type", nameMap, new HashMap<Locale, String>());

                Map<String, Long> journalArticleTypesToAssetCategoryIds = new HashMap<>();

                for (String type : types) {
                    AssetCategory assetCategory = addAssetCategory(company.getGroupId(), company.getCompanyId(),
                            type, assetVocabulary.getVocabularyId());

                    journalArticleTypesToAssetCategoryIds.put(type, assetCategory.getCategoryId());
                }

                updateArticles(company.getCompanyId(), journalArticleTypesToAssetCategoryIds);
            }
        } finally {
            LocaleThreadLocal.setDefaultLocale(localeThreadLocalDefaultLocale);
        }
    }
}

From source file:com.liferay.staging.test.StagingLocalizationTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    _availableLocales = LanguageUtil.getAvailableLocales(TestPropsValues.getCompanyId());
    _defaultLocale = LocaleThreadLocal.getDefaultLocale();

    CompanyTestUtil.resetCompanyLocales(TestPropsValues.getCompanyId(), _locales, Locale.US);

    _sourceGroup = GroupTestUtil.addGroup();
    _targetGroup = GroupTestUtil.addGroup();
}

From source file:com.rcs.service.service.impl.MessageSourceLocalServiceImpl.java

License:Open Source License

private Locale getDefaultLocale() {
    //get default locale as default locale of request
    Locale locale = LocaleThreadLocal.getThemeDisplayLocale();

    //get default locale as default locale of portal
    if (locale == null) {
        locale = LocaleThreadLocal.getDefaultLocale();
    }//  www .  j a  v a2 s  .  co m

    //get default locale as default locale of server
    if (locale == null) {
        locale = Locale.getDefault();
    }

    return locale;

}