Example usage for com.liferay.portal.kernel.portlet PortletBag getResourceBundle

List of usage examples for com.liferay.portal.kernel.portlet PortletBag getResourceBundle

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.portlet PortletBag getResourceBundle.

Prototype

public ResourceBundle getResourceBundle(Locale locale);

Source Link

Usage

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;
        }/*from w w w . j  a v  a2s  . c  o  m*/

        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;
}