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.categories.admin.web.internal.portlet.configuration.icon.AssetCategoryPermissionsPortletConfigurationIcon.java

License:Open Source License

@Override
public String getURL(PortletRequest portletRequest, PortletResponse portletResponse) {

    long categoryId = ParamUtil.getLong(portletRequest, "categoryId", 0);

    if (categoryId <= 0) {
        return StringPool.BLANK;
    }/*from   w ww . j  a va2s  .  c  o m*/

    String url = StringPool.BLANK;

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

    AssetCategory assetCategory = _assetCategoryLocalService.fetchCategory(categoryId);

    try {
        url = PermissionsURLTag.doTag(StringPool.BLANK, AssetCategory.class.getName(),
                assetCategory.getTitle(themeDisplay.getLocale()), null,
                String.valueOf(assetCategory.getCategoryId()), LiferayWindowState.POP_UP.toString(), null,
                themeDisplay.getRequest());
    } catch (Exception e) {
    }

    return url;
}

From source file:com.liferay.asset.categories.admin.web.internal.util.AssetCategoryUtil.java

License:Open Source License

public static void addPortletBreadcrumbEntry(AssetVocabulary vocabulary, AssetCategory category,
        HttpServletRequest request, RenderResponse renderResponse) throws PortalException {

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

    PortletURL portletURL = renderResponse.createRenderURL();

    portletURL.setParameter("mvcPath", "/view.jsp");

    PortalUtil.addPortletBreadcrumbEntry(request, LanguageUtil.get(request, "vocabularies"),
            portletURL.toString());/*from   ww w.ja  v a  2  s . com*/

    if (category == null) {
        PortalUtil.addPortletBreadcrumbEntry(request, vocabulary.getTitle(themeDisplay.getLocale()), null);

        return;
    }

    portletURL.setParameter("mvcPath", "/view_categories.jsp");

    String navigation = ParamUtil.getString(request, "navigation");

    if (Validator.isNotNull(navigation)) {
        portletURL.setParameter("navigation", navigation);
    }

    portletURL.setParameter("vocabularyId", String.valueOf(vocabulary.getVocabularyId()));

    PortalUtil.addPortletBreadcrumbEntry(request, vocabulary.getTitle(themeDisplay.getLocale()),
            portletURL.toString());

    List<AssetCategory> ancestorsCategories = category.getAncestors();

    Collections.reverse(ancestorsCategories);

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

        PortalUtil.addPortletBreadcrumbEntry(request, curCategory.getTitle(themeDisplay.getLocale()),
                portletURL.toString());
    }

    PortalUtil.addPortletBreadcrumbEntry(request, category.getTitle(themeDisplay.getLocale()), null);
}

From source file:com.liferay.asset.categories.selector.web.display.context.AssetCategoriesSelectorDisplayContext.java

License:Open Source License

public JSONArray getCategoriesJSONArray() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    JSONArray jsonArray = _getCategoriesJSONArray();

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("children", jsonArray);
    jsonObject.put("disabled", true);
    jsonObject.put("expanded", true);
    jsonObject.put("icon", "folder");
    jsonObject.put("id", "0");
    jsonObject.put("name", LanguageUtil.get(themeDisplay.getLocale(), "vocabularies"));

    JSONArray rootJSONArray = JSONFactoryUtil.createJSONArray();

    rootJSONArray.put(jsonObject);/*from   w  w w.ja v  a 2  s  . co m*/

    return rootJSONArray;
}

From source file:com.liferay.asset.categories.selector.web.display.context.AssetCategoriesSelectorDisplayContext.java

License:Open Source License

public String getVocabularyTitle(long vocabularyId) throws PortalException {
    ThemeDisplay themeDisplay = (ThemeDisplay) _renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    AssetVocabulary assetVocabulary = AssetVocabularyLocalServiceUtil.fetchAssetVocabulary(vocabularyId);

    StringBundler sb = new StringBundler(4);

    String title = assetVocabulary.getTitle(themeDisplay.getLocale());

    sb.append(HtmlUtil.escape(title));//w w w  .  j  a va 2  s. com

    sb.append(StringPool.OPEN_PARENTHESIS);

    if (assetVocabulary.getGroupId() == themeDisplay.getCompanyGroupId()) {
        sb.append(LanguageUtil.get(_request, "global"));
    } else {
        Group group = GroupLocalServiceUtil.fetchGroup(assetVocabulary.getGroupId());

        sb.append(group.getDescriptiveName(themeDisplay.getLocale()));
    }

    sb.append(StringPool.CLOSE_PARENTHESIS);

    return sb.toString();
}

From source file:com.liferay.asset.categories.selector.web.display.context.AssetCategoriesSelectorDisplayContext.java

License:Open Source License

private JSONArray _getCategoriesJSONArray(long vocabularyId, long categoryId) throws Exception {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

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

    List<AssetCategory> categories = AssetCategoryServiceUtil.getVocabularyCategories(categoryId, vocabularyId,
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (AssetCategory category : categories) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        JSONArray children = _getCategoriesJSONArray(vocabularyId, category.getCategoryId());

        if (children.length() > 0) {
            jsonObject.put("children", children);
        }//from   w w  w .j  a  va2s.  co m

        jsonObject.put("icon", "page");
        jsonObject.put("id", category.getCategoryId());
        jsonObject.put("name", category.getTitle(themeDisplay.getLocale()));

        if (getSelectedCategories().contains(String.valueOf(category.getCategoryId()))) {

            jsonObject.put("selected", true);
        }

        jsonArray.put(jsonObject);
    }

    return jsonArray;
}

From source file:com.liferay.asset.internal.util.AssetHelperImpl.java

License:Open Source License

@Override
public List<AssetPublisherAddItemHolder> getAssetPublisherAddItemHolders(
        LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse,
        long groupId, long[] classNameIds, long[] classTypeIds, long[] allAssetCategoryIds,
        String[] allAssetTagNames, String redirect) throws Exception {

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

    Locale locale = themeDisplay.getLocale();

    List<AssetPublisherAddItemHolder> assetPublisherAddItemHolders = new ArrayList<>();

    for (long classNameId : classNameIds) {
        String className = _portal.getClassName(classNameId);

        AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(className);

        if (Validator.isNull(assetRendererFactory.getPortletId())) {
            continue;
        }//  w w w .  ja v a  2s .  c om

        Portlet portlet = _portletLocalService.getPortletById(themeDisplay.getCompanyId(),
                assetRendererFactory.getPortletId());

        if (!portlet.isActive()) {
            continue;
        }

        PortletBag portletBag = PortletBagPool.get(portlet.getRootPortletId());

        if (portletBag == null) {
            continue;
        }

        ResourceBundle resourceBundle = portletBag.getResourceBundle(locale);

        ClassTypeReader classTypeReader = assetRendererFactory.getClassTypeReader();

        List<ClassType> classTypes = Collections.emptyList();

        if (!(classTypeReader instanceof NullClassTypeReader)) {
            classTypes = classTypeReader.getAvailableClassTypes(
                    _portal.getCurrentAndAncestorSiteGroupIds(groupId), themeDisplay.getLocale());
        }

        if (classTypes.isEmpty()) {
            PortletURL addPortletURL = getAddPortletURL(liferayPortletRequest, liferayPortletResponse, groupId,
                    className, 0, allAssetCategoryIds, allAssetTagNames, redirect);

            if (addPortletURL != null) {
                assetPublisherAddItemHolders.add(new AssetPublisherAddItemHolder(portlet.getPortletId(),
                        className, resourceBundle, locale, addPortletURL));
            }
        }

        for (ClassType classType : classTypes) {
            long classTypeId = classType.getClassTypeId();

            if (ArrayUtil.contains(classTypeIds, classTypeId) || (classTypeIds.length == 0)) {

                PortletURL addPortletURL = getAddPortletURL(liferayPortletRequest, liferayPortletResponse,
                        groupId, className, classTypeId, allAssetCategoryIds, allAssetTagNames, redirect);

                if (addPortletURL != null) {
                    assetPublisherAddItemHolders.add(new AssetPublisherAddItemHolder(portlet.getPortletId(),
                            classType.getName(), resourceBundle, locale, addPortletURL));
                }
            }
        }
    }

    if (assetPublisherAddItemHolders.size() <= 1) {
        return assetPublisherAddItemHolders;
    }

    assetPublisherAddItemHolders.sort(null);

    return assetPublisherAddItemHolders;
}

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

public AssetEntryQuery getAssetEntryQuery() throws Exception {
    if (_assetEntryQuery != null) {
        return _assetEntryQuery;
    }/*  w  w  w .  ja v  a  2s  . c  o m*/

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

    _assetEntryQuery = AssetPublisherUtil.getAssetEntryQuery(_portletPreferences,
            themeDisplay.getScopeGroupId(), themeDisplay.getLayout(), getAllAssetCategoryIds(),
            getAllAssetTagNames());

    _assetEntryQuery.setEnablePermissions(isEnablePermissions());

    configureSubtypeFieldFilter(_assetEntryQuery, themeDisplay.getLocale());

    _assetEntryQuery.setPaginationType(getPaginationType());

    _assetPublisherWebUtil.processAssetEntryQuery(themeDisplay.getUser(), _portletPreferences,
            _assetEntryQuery);

    _assetPublisherCustomizer.setAssetEntryQueryOptions(_assetEntryQuery, _request);

    return _assetEntryQuery;
}

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

public JSONArray getAutoFieldRulesJSONArray() {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    String queryLogicIndexesParam = ParamUtil.getString(_request, "queryLogicIndexes");

    int[] queryLogicIndexes = null;

    if (Validator.isNotNull(queryLogicIndexesParam)) {
        queryLogicIndexes = StringUtil.split(queryLogicIndexesParam, 0);
    } else {//from  w ww  . ja v a2s .  c o  m
        queryLogicIndexes = new int[0];

        for (int i = 0; true; i++) {
            String queryValues = PrefsParamUtil.getString(_portletPreferences, _request, "queryValues" + i);

            if (Validator.isNull(queryValues)) {
                break;
            }

            queryLogicIndexes = ArrayUtil.append(queryLogicIndexes, i);
        }

        if (queryLogicIndexes.length == 0) {
            queryLogicIndexes = ArrayUtil.append(queryLogicIndexes, -1);
        }
    }

    JSONArray rulesJSONArray = JSONFactoryUtil.createJSONArray();

    for (int queryLogicIndex : queryLogicIndexes) {
        JSONObject ruleJSONObject = JSONFactoryUtil.createJSONObject();

        boolean queryAndOperator = PrefsParamUtil.getBoolean(_portletPreferences, _request,
                "queryAndOperator" + queryLogicIndex);

        ruleJSONObject.put("queryAndOperator", queryAndOperator);

        boolean queryContains = PrefsParamUtil.getBoolean(_portletPreferences, _request,
                "queryContains" + queryLogicIndex, true);

        ruleJSONObject.put("queryContains", queryContains);

        String queryValues = StringUtil
                .merge(_portletPreferences.getValues("queryValues" + queryLogicIndex, new String[0]));

        String queryName = PrefsParamUtil.getString(_portletPreferences, _request,
                "queryName" + queryLogicIndex, "assetTags");

        if (Objects.equals(queryName, "assetTags")) {
            queryValues = ParamUtil.getString(_request, "queryTagNames" + queryLogicIndex, queryValues);

            queryValues = _assetPublisherWebUtil.filterAssetTagNames(themeDisplay.getScopeGroupId(),
                    queryValues);
        } else {
            queryValues = ParamUtil.getString(_request, "queryCategoryIds" + queryLogicIndex, queryValues);

            JSONArray categoryIdsTitles = JSONFactoryUtil.createJSONArray();

            long[] categoryIds = GetterUtil.getLongValues(queryValues.split(","));

            for (long categoryId : categoryIds) {
                AssetCategory category = AssetCategoryLocalServiceUtil.fetchAssetCategory(categoryId);

                categoryIdsTitles.put(category.getTitle(themeDisplay.getLocale()));
            }

            ruleJSONObject.put("categoryIdsTitles", categoryIdsTitles);
        }

        ruleJSONObject.put("queryValues", queryValues);
        ruleJSONObject.put("type", queryName);

        rulesJSONArray.put(ruleJSONObject);
    }

    return rulesJSONArray;
}

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

public Locale getLocale() {
    if (_locale != null) {
        return _locale;
    }/*from www  .jav a 2 s .c  o m*/

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

    _locale = themeDisplay.getLocale();

    return _locale;
}

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

protected void setDDMStructure() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    _ddmStructureDisplayFieldValue = StringPool.BLANK;
    _ddmStructureFieldLabel = StringPool.BLANK;
    _ddmStructureFieldName = StringPool.BLANK;
    _ddmStructureFieldValue = null;/*from www. j  av  a 2s .c  om*/

    long[] classNameIds = getClassNameIds();
    long[] classTypeIds = getClassTypeIds();

    if (!isSubtypeFieldsFilterEnabled() || (classNameIds.length != 1) || (classTypeIds.length != 1)) {

        return;
    }

    _ddmStructureDisplayFieldValue = ParamUtil.getString(_request, "ddmStructureDisplayFieldValue",
            _portletPreferences.getValue("ddmStructureDisplayFieldValue", StringPool.BLANK));
    _ddmStructureFieldName = ParamUtil.getString(_request, "ddmStructureFieldName",
            _portletPreferences.getValue("ddmStructureFieldName", StringPool.BLANK));
    _ddmStructureFieldValue = ParamUtil.getString(_request, "ddmStructureFieldValue",
            _portletPreferences.getValue("ddmStructureFieldValue", StringPool.BLANK));

    if (Validator.isNotNull(_ddmStructureFieldName) && Validator.isNotNull(_ddmStructureFieldValue)) {

        AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassNameId(classNameIds[0]);

        ClassTypeReader classTypeReader = assetRendererFactory.getClassTypeReader();

        ClassType classType = classTypeReader.getClassType(classTypeIds[0], themeDisplay.getLocale());

        ClassTypeField classTypeField = classType.getClassTypeField(_ddmStructureFieldName);

        _ddmStructureFieldLabel = classTypeField.getLabel();
    }
}