Example usage for com.liferay.portal.kernel.model Layout isSupportsEmbeddedPortlets

List of usage examples for com.liferay.portal.kernel.model Layout isSupportsEmbeddedPortlets

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Layout isSupportsEmbeddedPortlets.

Prototype

public boolean isSupportsEmbeddedPortlets();

Source Link

Document

Returns true if the current layout can hold embedded portlets.

Usage

From source file:com.liferay.layout.admin.web.internal.display.context.LayoutsAdminDisplayContext.java

License:Open Source License

public boolean showOrphanPortletsAction(Layout layout) {
    if (StagingUtil.isIncomplete(layout)) {
        return false;
    }/*from w w  w .j  a va2s  .com*/

    if (!layout.isSupportsEmbeddedPortlets()) {
        return false;
    }

    OrphanPortletsDisplayContext orphanPortletsDisplayContext = new OrphanPortletsDisplayContext(
            _liferayPortletRequest, _liferayPortletResponse);

    if (ListUtil.isEmpty(orphanPortletsDisplayContext.getOrphanPortlets(layout))) {

        return false;
    }

    return true;
}

From source file:com.liferay.layout.admin.web.internal.display.context.OrphanPortletsDisplayContext.java

License:Open Source License

public List<Portlet> getOrphanPortlets(Layout layout) {
    if (!layout.isSupportsEmbeddedPortlets()) {
        return Collections.emptyList();
    }//  w  ww  .j a  v a 2s . com

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

    LayoutTypePortlet selLayoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    List<Portlet> explicitlyAddedPortlets = selLayoutTypePortlet.getExplicitlyAddedPortlets();

    List<String> explicitlyAddedPortletIds = new ArrayList<>();

    for (Portlet explicitlyAddedPortlet : explicitlyAddedPortlets) {
        explicitlyAddedPortletIds.add(explicitlyAddedPortlet.getPortletId());
    }

    List<Portlet> orphanPortlets = new ArrayList<>();

    List<PortletPreferences> portletPreferences = PortletPreferencesLocalServiceUtil.getPortletPreferences(
            PortletKeys.PREFS_OWNER_ID_DEFAULT, PortletKeys.PREFS_OWNER_TYPE_LAYOUT, getSelPlid());

    for (PortletPreferences portletPreference : portletPreferences) {
        String portletId = portletPreference.getPortletId();

        Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId);

        if (portlet.isSystem()) {
            continue;
        }

        if (explicitlyAddedPortletIds.contains(portletId)) {
            continue;
        }

        orphanPortlets.add(portlet);
    }

    HttpServletRequest request = PortalUtil.getHttpServletRequest(_liferayPortletRequest);

    PortletTitleComparator portletTitleComparator = new PortletTitleComparator(request.getServletContext(),
            themeDisplay.getLocale());

    orphanPortlets = ListUtil.sort(orphanPortlets, portletTitleComparator);

    return orphanPortlets;
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

protected Map<String, Object[]> getPortletids(PortletDataContext portletDataContext, Layout layout)
        throws Exception {

    if (!LayoutStagingUtil.prepareLayoutStagingHandler(portletDataContext, layout)
            || !layout.isSupportsEmbeddedPortlets()) {

        // Only portlet type layouts support page scoping

        return Collections.emptyMap();
    }// w w w.j  a  v  a2s .  c  o m

    Map<String, Object[]> portletIds = new HashMap<>();

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    // The getAllPortlets method returns all effective nonsystem portlets
    // for any layout type, including embedded portlets, or in the case of
    // panel type layout, selected portlets

    for (Portlet portlet : layoutTypePortlet.getAllPortlets(false)) {
        String portletId = portlet.getPortletId();

        Settings portletInstanceSettings = SettingsFactoryUtil
                .getSettings(new PortletInstanceSettingsLocator(layout, portletId));

        String scopeType = portletInstanceSettings.getValue("lfrScopeType", null);
        String scopeLayoutUuid = portletInstanceSettings.getValue("lfrScopeLayoutUuid", null);

        long scopeGroupId = portletDataContext.getScopeGroupId();

        if (Validator.isNotNull(scopeType)) {
            Group scopeGroup = null;

            if (scopeType.equals("company")) {
                scopeGroup = _groupLocalService.getCompanyGroup(layout.getCompanyId());
            } else if (scopeType.equals("layout")) {
                Layout scopeLayout = null;

                scopeLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(scopeLayoutUuid,
                        portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());

                if (scopeLayout == null) {
                    continue;
                }

                scopeGroup = scopeLayout.getScopeGroup();
            } else {
                throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
            }

            if (scopeGroup != null) {
                scopeGroupId = scopeGroup.getGroupId();
            }
        }

        String key = PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portletId);

        portletIds.put(key, new Object[] { portletId, scopeGroupId, scopeType, scopeLayoutUuid });
    }

    return portletIds;
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.PortletConfigurationPortlet.java

License:Open Source License

protected PortletPreferences getPortletPreferences(ThemeDisplay themeDisplay, String portletId,
        String settingsScope) {/*from  ww  w  .  j  a  v  a2  s  .com*/

    Layout layout = themeDisplay.getLayout();

    if (!layout.isSupportsEmbeddedPortlets()) {
        return null;
    }

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    if (!layoutTypePortlet.isPortletEmbedded(portletId)) {
        return null;
    }

    PortletPreferencesIds portletPreferencesIds = new PortletPreferencesIds(themeDisplay.getCompanyId(),
            layout.getGroupId(), PortletKeys.PREFS_OWNER_TYPE_LAYOUT, PortletKeys.PREFS_PLID_SHARED, portletId);

    return _portletPreferencesLocalService.getPreferences(portletPreferencesIds);
}