Example usage for com.liferay.portal.kernel.util WebKeys AVAILABLE_LOCALES

List of usage examples for com.liferay.portal.kernel.util WebKeys AVAILABLE_LOCALES

Introduction

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

Prototype

String AVAILABLE_LOCALES

To view the source code for com.liferay.portal.kernel.util WebKeys AVAILABLE_LOCALES.

Click Source Link

Usage

From source file:com.liferay.journal.web.internal.portlet.action.ActionUtil.java

License:Open Source License

protected static String getLanguageId(RenderRequest renderRequest, long groupId, String articleId,
        double sourceVersion, double targetVersion) throws Exception {

    JournalArticle sourceArticle = JournalArticleLocalServiceUtil.fetchArticle(groupId, articleId,
            sourceVersion);/* ww w.j a v a  2 s .co m*/

    JournalArticle targetArticle = JournalArticleLocalServiceUtil.fetchArticle(groupId, articleId,
            targetVersion);

    Set<Locale> locales = new HashSet<>();

    for (String locale : sourceArticle.getAvailableLanguageIds()) {
        locales.add(LocaleUtil.fromLanguageId(locale));
    }

    for (String locale : targetArticle.getAvailableLanguageIds()) {
        locales.add(LocaleUtil.fromLanguageId(locale));
    }

    String languageId = ParamUtil.get(renderRequest, "languageId", targetArticle.getDefaultLanguageId());

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    if (!locales.contains(locale)) {
        languageId = targetArticle.getDefaultLanguageId();
    }

    renderRequest.setAttribute(WebKeys.AVAILABLE_LOCALES, locales);
    renderRequest.setAttribute(WebKeys.LANGUAGE_ID, languageId);

    return languageId;
}