Example usage for com.liferay.portal.kernel.theme ThemeDisplay getLocale

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getLocale

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getLocale.

Prototype

public Locale getLocale() 

Source Link

Document

Returns the locale used for displaying content.

Usage

From source file:com.liferay.asset.publisher.web.internal.portlet.toolbar.contributor.AssetPublisherPortletToolbarContributor.java

License:Open Source License

protected void addPortletTitleAddAssetEntryMenuItems(List<MenuItem> menuItems, PortletRequest portletRequest,
        PortletResponse portletResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    AssetPublisherCustomizer assetPublisherCustomizer = (AssetPublisherCustomizer) portletRequest
            .getAttribute(AssetPublisherWebKeys.ASSET_PUBLISHER_CUSTOMIZER);

    AssetPublisherDisplayContext assetPublisherDisplayContext = new AssetPublisherDisplayContext(
            assetPublisherCustomizer, portletRequest, portletResponse, portletRequest.getPreferences());

    if (!_isVisible(assetPublisherDisplayContext, portletRequest)) {
        return;//www  . j  a  v a  2 s .  c om
    }

    Map<Long, List<AssetPublisherAddItemHolder>> scopeAssetPublisherAddItemHolders = assetPublisherDisplayContext
            .getScopeAssetPublisherAddItemHolders(1);

    if (MapUtil.isEmpty(scopeAssetPublisherAddItemHolders)) {
        return;
    }

    if (scopeAssetPublisherAddItemHolders.size() == 1) {
        Set<Map.Entry<Long, List<AssetPublisherAddItemHolder>>> entrySet = scopeAssetPublisherAddItemHolders
                .entrySet();

        Iterator<Map.Entry<Long, List<AssetPublisherAddItemHolder>>> iterator = entrySet.iterator();

        Map.Entry<Long, List<AssetPublisherAddItemHolder>> scopeAddPortletURL = iterator.next();

        long groupId = scopeAddPortletURL.getKey();

        List<AssetPublisherAddItemHolder> assetPublisherAddItemHolders = scopeAddPortletURL.getValue();

        for (AssetPublisherAddItemHolder assetPublisherAddItemHolder : assetPublisherAddItemHolders) {

            URLMenuItem urlMenuItem = _getPortletTitleAddAssetEntryMenuItem(themeDisplay,
                    assetPublisherDisplayContext, groupId, assetPublisherAddItemHolder);

            menuItems.add(urlMenuItem);
        }

        return;
    }

    URLMenuItem urlMenuItem = new URLMenuItem();

    Map<String, Object> data = new HashMap<>();

    data.put("id", HtmlUtil.escape(portletDisplay.getNamespace()) + "editAsset");

    ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", themeDisplay.getLocale(),
            getClass());

    String title = LanguageUtil.get(resourceBundle, "add-content-select-scope-and-type");

    data.put("title", title);

    urlMenuItem.setData(data);

    urlMenuItem.setLabel(title);

    LiferayPortletResponse liferayPortletResponse = _portal.getLiferayPortletResponse(portletResponse);

    PortletURL portletURL = liferayPortletResponse.createRenderURL();

    portletURL.setParameter("mvcPath", "/add_asset_selector.jsp");
    portletURL.setParameter("redirect", themeDisplay.getURLCurrent());
    portletURL.setWindowState(LiferayWindowState.POP_UP);

    urlMenuItem.setURL(portletURL.toString());

    urlMenuItem.setUseDialog(true);

    menuItems.add(urlMenuItem);
}

From source file:com.liferay.asset.publisher.web.internal.portlet.toolbar.contributor.AssetPublisherPortletToolbarContributor.java

License:Open Source License

private URLMenuItem _getPortletTitleAddAssetEntryMenuItem(ThemeDisplay themeDisplay,
        AssetPublisherDisplayContext assetPublisherDisplayContext, long groupId,
        AssetPublisherAddItemHolder assetPublisherAddItemHolder) {

    URLMenuItem urlMenuItem = new URLMenuItem();

    Map<String, Object> data = new HashMap<>();

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    data.put("id", HtmlUtil.escape(portletDisplay.getNamespace()) + "editAsset");

    String message = assetPublisherAddItemHolder.getModelResource();

    String title = LanguageUtil.format(themeDisplay.getLocale(), "new-x", message, false);

    data.put("title", title);

    urlMenuItem.setData(data);//ww w. j  a va2s .c  o  m

    urlMenuItem.setLabel(HtmlUtil.escape(message));

    long curGroupId = groupId;

    Group group = _groupLocalService.fetchGroup(groupId);

    if (!group.isStagedPortlet(assetPublisherAddItemHolder.getPortletId()) && !group.isStagedRemotely()) {

        curGroupId = group.getLiveGroupId();
    }

    boolean addDisplayPageParameter = _assetPublisherWebUtil.isDefaultAssetPublisher(themeDisplay.getLayout(),
            portletDisplay.getId(), assetPublisherDisplayContext.getPortletResource());

    String url = _assetHelper.getAddURLPopUp(curGroupId, themeDisplay.getPlid(),
            assetPublisherAddItemHolder.getPortletURL(), addDisplayPageParameter, themeDisplay.getLayout());

    urlMenuItem.setURL(url);

    urlMenuItem.setUseDialog(true);

    return urlMenuItem;
}

From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java

License:Open Source License

public Map<String, String> getEmailDefinitionTerms(PortletRequest portletRequest, String emailFromAddress,
        String emailFromName) {//from  w w w  . j av  a2 s. com

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Map<String, String> definitionTerms = new LinkedHashMap<>();

    definitionTerms.put("[$ASSET_ENTRIES$]", LanguageUtil.get(themeDisplay.getLocale(), "the-list-of-assets"));
    definitionTerms.put("[$COMPANY_ID$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-id-associated-with-the-assets"));
    definitionTerms.put("[$COMPANY_MX$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-mx-associated-with-the-assets"));
    definitionTerms.put("[$COMPANY_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-name-associated-with-the-assets"));
    definitionTerms.put("[$FROM_ADDRESS$]", HtmlUtil.escape(emailFromAddress));
    definitionTerms.put("[$FROM_NAME$]", HtmlUtil.escape(emailFromName));

    Company company = themeDisplay.getCompany();

    definitionTerms.put("[$PORTAL_URL$]", company.getVirtualHostname());

    definitionTerms.put("[$PORTLET_NAME$]", HtmlUtil.escape(
            _portal.getPortletTitle(AssetPublisherPortletKeys.ASSET_PUBLISHER, themeDisplay.getLocale())));

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    definitionTerms.put("[$PORTLET_TITLE$]", HtmlUtil.escape(portletDisplay.getTitle()));

    definitionTerms.put("[$SITE_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-site-name-associated-with-the-assets"));
    definitionTerms.put("[$TO_ADDRESS$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-address-of-the-email-recipient"));
    definitionTerms.put("[$TO_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-name-of-the-email-recipient"));

    return definitionTerms;
}

From source file:com.liferay.asset.publisher.web.portlet.AssetPublisherPortlet.java

License:Open Source License

public void getFieldValue(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    try {/*from w ww . j a v  a 2 s. c  o  m*/
        ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest);

        long structureId = ParamUtil.getLong(resourceRequest, "structureId");

        Fields fields = (Fields) serviceContext.getAttribute(Fields.class.getName() + structureId);

        if (fields == null) {
            String fieldsNamespace = ParamUtil.getString(resourceRequest, "fieldsNamespace");

            fields = DDMUtil.getFields(structureId, fieldsNamespace, serviceContext);
        }

        String fieldName = ParamUtil.getString(resourceRequest, "name");

        Field field = fields.get(fieldName);

        Serializable fieldValue = field.getValue(themeDisplay.getLocale(), 0);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        if (fieldValue != null) {
            jsonObject.put("success", true);
        } else {
            jsonObject.put("success", false);

            writeJSON(resourceRequest, resourceResponse, jsonObject);

            return;
        }

        DDMStructure ddmStructure = field.getDDMStructure();

        String type = ddmStructure.getFieldType(fieldName);

        Serializable displayValue = DDMUtil.getDisplayFieldValue(themeDisplay, fieldValue, type);

        jsonObject.put("displayValue", String.valueOf(displayValue));

        if (fieldValue instanceof Boolean) {
            jsonObject.put("value", (Boolean) fieldValue);
        } else if (fieldValue instanceof Date) {
            DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMM ddHHmmss");

            jsonObject.put("value", dateFormat.format(fieldValue));
        } else if (fieldValue instanceof Double) {
            jsonObject.put("value", (Double) fieldValue);
        } else if (fieldValue instanceof Float) {
            jsonObject.put("value", (Float) fieldValue);
        } else if (fieldValue instanceof Integer) {
            jsonObject.put("value", (Integer) fieldValue);
        } else if (fieldValue instanceof Number) {
            jsonObject.put("value", String.valueOf(fieldValue));
        } else {
            jsonObject.put("value", (String) fieldValue);
        }

        writeJSON(resourceRequest, resourceResponse, jsonObject);
    } catch (Exception e) {
        throw new PortletException(e);
    }
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static Map<String, String> getEmailDefinitionTerms(PortletRequest portletRequest,
        String emailFromAddress, String emailFromName) {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Map<String, String> definitionTerms = new LinkedHashMap<>();

    definitionTerms.put("[$ASSET_ENTRIES$]", LanguageUtil.get(themeDisplay.getLocale(), "the-list-of-assets"));
    definitionTerms.put("[$COMPANY_ID$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-id-associated-with-the-assets"));
    definitionTerms.put("[$COMPANY_MX$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-mx-associated-with-the-assets"));
    definitionTerms.put("[$COMPANY_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-name-associated-with-the-assets"));
    definitionTerms.put("[$FROM_ADDRESS$]", HtmlUtil.escape(emailFromAddress));
    definitionTerms.put("[$FROM_NAME$]", HtmlUtil.escape(emailFromName));

    Company company = themeDisplay.getCompany();

    definitionTerms.put("[$PORTAL_URL$]", company.getVirtualHostname());

    definitionTerms.put("[$PORTLET_NAME$]", HtmlUtil.escape(
            PortalUtil.getPortletTitle(AssetPublisherPortletKeys.ASSET_PUBLISHER, themeDisplay.getLocale())));

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    definitionTerms.put("[$PORTLET_TITLE$]", HtmlUtil.escape(portletDisplay.getTitle()));

    definitionTerms.put("[$SITE_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-site-name-associated-with-the-assets"));
    definitionTerms.put("[$TO_ADDRESS$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-address-of-the-email-recipient"));
    definitionTerms.put("[$TO_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-name-of-the-email-recipient"));

    return definitionTerms;
}

From source file:com.liferay.asset.taglib.internal.util.AssetCategoryUtil.java

License:Open Source License

public static void addPortletBreadcrumbEntries(long assetCategoryId, HttpServletRequest request,
        PortletURL portletURL, boolean portletBreadcrumbEntry) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    AssetCategory assetCategory = AssetCategoryLocalServiceUtil.getCategory(assetCategoryId);

    List<AssetCategory> ancestorCategories = assetCategory.getAncestors();

    Collections.reverse(ancestorCategories);

    for (AssetCategory ancestorCategory : ancestorCategories) {
        portletURL.setParameter("categoryId", String.valueOf(ancestorCategory.getCategoryId()));

        PortalUtil.addPortletBreadcrumbEntry(request, ancestorCategory.getTitle(themeDisplay.getLocale()),
                portletURL.toString(), null, portletBreadcrumbEntry);
    }//from ww  w . j  a va2 s  .  c  o m

    portletURL.setParameter("categoryId", String.valueOf(assetCategoryId));

    PortalUtil.addPortletBreadcrumbEntry(request, assetCategory.getTitle(themeDisplay.getLocale()),
            portletURL.toString(), null, portletBreadcrumbEntry);
}

From source file:com.liferay.asset.taglib.internal.util.AssetCategoryUtil.java

License:Open Source License

public static String[] getCategoryIdsTitles(String categoryIds, String categoryNames, long vocabularyId,
        ThemeDisplay themeDisplay) {

    if (Validator.isNotNull(categoryIds)) {
        long[] categoryIdsArray = GetterUtil.getLongValues(StringUtil.split(categoryIds));

        if (vocabularyId > 0) {
            categoryIdsArray = filterCategoryIds(vocabularyId, categoryIdsArray);
        }/*from   w w  w . j a  v  a  2  s.  c  om*/

        categoryIds = StringPool.BLANK;
        categoryNames = StringPool.BLANK;

        if (categoryIdsArray.length > 0) {
            StringBundler categoryIdsSB = new StringBundler(categoryIdsArray.length * 2);
            StringBundler categoryNamesSB = new StringBundler(categoryIdsArray.length * 2);

            for (long categoryId : categoryIdsArray) {
                AssetCategory category = AssetCategoryLocalServiceUtil.fetchCategory(categoryId);

                if (category == null) {
                    continue;
                }

                categoryIdsSB.append(categoryId);
                categoryIdsSB.append(StringPool.COMMA);

                categoryNamesSB.append(category.getTitle(themeDisplay.getLocale()));
                categoryNamesSB.append(CATEGORY_SEPARATOR);
            }

            if (categoryIdsSB.index() > 0) {
                categoryIdsSB.setIndex(categoryIdsSB.index() - 1);
                categoryNamesSB.setIndex(categoryNamesSB.index() - 1);

                categoryIds = categoryIdsSB.toString();
                categoryNames = categoryNamesSB.toString();
            }
        }
    }

    return new String[] { categoryIds, categoryNames };
}

From source file:com.liferay.blade.samples.portlet.toolbar.contributor.BladePortletToolbarContributor.java

License:Apache License

protected Locale getLocale(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    return themeDisplay.getLocale();
}

From source file:com.liferay.blogs.editor.configuration.internal.BlogsContentEditorConfigContributor.java

License:Open Source License

protected void populateFileBrowserURL(JSONObject jsonObject, ThemeDisplay themeDisplay,
        RequestBackedPortletURLFactory requestBackedPortletURLFactory, String eventName) {

    List<ItemSelectorReturnType> blogsContentEditorDesiredItemSelectorReturnTypes = new ArrayList<>();

    blogsContentEditorDesiredItemSelectorReturnTypes.add(new FileEntryItemSelectorReturnType());

    blogsContentEditorDesiredItemSelectorReturnTypes.add(new URLItemSelectorReturnType());

    ItemSelectorCriterion blogsItemSelectorCriterion = new BlogsItemSelectorCriterion();

    blogsItemSelectorCriterion/*from   ww w.  j  a v a2s  .  c  o  m*/
            .setDesiredItemSelectorReturnTypes(blogsContentEditorDesiredItemSelectorReturnTypes);

    ItemSelectorCriterion imageItemSelectorCriterion = new ImageItemSelectorCriterion();

    imageItemSelectorCriterion
            .setDesiredItemSelectorReturnTypes(blogsContentEditorDesiredItemSelectorReturnTypes);

    ItemSelectorCriterion urlItemSelectorCriterion = new URLItemSelectorCriterion();

    List<ItemSelectorReturnType> urlDesiredItemSelectorReturnTypes = new ArrayList<>();

    urlDesiredItemSelectorReturnTypes.add(new URLItemSelectorReturnType());

    urlItemSelectorCriterion.setDesiredItemSelectorReturnTypes(urlDesiredItemSelectorReturnTypes);

    PortletURL uploadURL = requestBackedPortletURLFactory.createActionURL(PortletKeys.BLOGS);

    uploadURL.setParameter(ActionRequest.ACTION_NAME, "/blogs/upload_image");

    ItemSelectorCriterion uploadItemSelectorCriterion = new UploadItemSelectorCriterion(uploadURL.toString(),
            LanguageUtil.get(themeDisplay.getLocale(), "blog-images"), PropsValues.BLOGS_IMAGE_MAX_SIZE);

    List<ItemSelectorReturnType> uploadDesiredItemSelectorReturnTypes = new ArrayList<>();

    uploadDesiredItemSelectorReturnTypes.add(new FileEntryItemSelectorReturnType());

    uploadItemSelectorCriterion.setDesiredItemSelectorReturnTypes(uploadDesiredItemSelectorReturnTypes);

    PortletURL itemSelectorURL = _itemSelector.getItemSelectorURL(requestBackedPortletURLFactory, eventName,
            blogsItemSelectorCriterion, imageItemSelectorCriterion, urlItemSelectorCriterion,
            uploadItemSelectorCriterion);

    jsonObject.put("filebrowserImageBrowseLinkUrl", itemSelectorURL.toString());
    jsonObject.put("filebrowserImageBrowseUrl", itemSelectorURL.toString());
}

From source file:com.liferay.blogs.util.BlogsUtil.java

License:Open Source License

public static Map<String, String> getEmailDefinitionTerms(PortletRequest portletRequest,
        String emailFromAddress, String emailFromName) {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Map<String, String> definitionTerms = new LinkedHashMap<>();

    definitionTerms.put("[$BLOGS_ENTRY_CONTENT$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-blog-entry-content"));
    definitionTerms.put("[$BLOGS_ENTRY_CREATE_DATE$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-date-the-blog-entry-was-created"));
    definitionTerms.put("[$BLOGS_ENTRY_DESCRIPTION$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-blog-entry-description"));
    definitionTerms.put("[$BLOGS_ENTRY_SITE_NAME$]", LanguageUtil.get(themeDisplay.getLocale(),
            "the-name-of-the-site-where-the-blog-entry-was-created"));
    definitionTerms.put("[$BLOGS_ENTRY_STATUS_BY_USER_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-user-who-updated-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_TITLE$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-blog-entry-title"));
    definitionTerms.put("[$BLOGS_ENTRY_UPDATE_COMMENT$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-comment-of-the-user-who-updated-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_USER_ADDRESS$]", LanguageUtil.get(themeDisplay.getLocale(),
            "the-email-address-of-the-user-who-added-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_USER_PORTRAIT_URL$]", LanguageUtil.get(themeDisplay.getLocale(),
            "the-portrait-url-of-the-user-who-added-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_USER_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-user-who-added-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_USER_URL$]", LanguageUtil.get(themeDisplay.getLocale(),
            "the-public-site-url-of-the-user-who-added-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_URL$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-blog-entry-url"));
    definitionTerms.put("[$COMPANY_ID$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-id-associated-with-the-blog"));
    definitionTerms.put("[$COMPANY_MX$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-mx-associated-with-the-blog"));
    definitionTerms.put("[$COMPANY_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-name-associated-with-the-blog"));
    definitionTerms.put("[$FROM_ADDRESS$]", HtmlUtil.escape(emailFromAddress));
    definitionTerms.put("[$FROM_NAME$]", HtmlUtil.escape(emailFromName));

    Company company = themeDisplay.getCompany();

    definitionTerms.put("[$PORTAL_URL$]", company.getVirtualHostname());

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    definitionTerms.put("[$PORTLET_NAME$]", HtmlUtil.escape(portletDisplay.getTitle()));

    definitionTerms.put("[$SITE_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-site-name-associated-with-the-blog"));
    definitionTerms.put("[$TO_ADDRESS$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-address-of-the-email-recipient"));
    definitionTerms.put("[$TO_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-name-of-the-email-recipient"));
    definitionTerms.put("[$UNSUBSCRIBE_URL$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-url-to-unsubscribe-the-user"));

    return definitionTerms;
}