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

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

Introduction

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

Prototype

public boolean isTypePortlet();

Source Link

Usage

From source file:com.liferay.exportimport.controller.PortletExportController.java

License:Open Source License

protected File doExport(PortletDataContext portletDataContext) throws Exception {

    boolean exportPermissions = MapUtil.getBoolean(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.PERMISSIONS);

    if (_log.isDebugEnabled()) {
        _log.debug("Export permissions " + exportPermissions);
    }//  ww  w  . ja v a2  s.c o  m

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();

    Layout layout = _layoutLocalService.getLayout(portletDataContext.getPlid());

    if (!layout.isTypeControlPanel() && !layout.isTypePanel() && !layout.isTypePortlet()) {

        StringBundler sb = new StringBundler(4);

        sb.append("Unable to export layout ");
        sb.append(layout.getPlid());
        sb.append(" because it has an invalid type: ");
        sb.append(layout.getType());

        throw new LayoutImportException(sb.toString());
    }

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    if (serviceContext == null) {
        serviceContext = new ServiceContext();

        serviceContext.setCompanyId(layout.getCompanyId());
        serviceContext.setSignedIn(false);

        long defaultUserId = _userLocalService.getDefaultUserId(layout.getCompanyId());

        serviceContext.setUserId(defaultUserId);

        ServiceContextThreadLocal.pushServiceContext(serviceContext);
    }

    long layoutSetBranchId = MapUtil.getLong(portletDataContext.getParameterMap(), "layoutSetBranchId");

    serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId);

    long scopeGroupId = portletDataContext.getGroupId();

    javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil
            .getLayoutPortletSetup(layout, portletDataContext.getPortletId());

    String scopeType = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeType", null));
    String scopeLayoutUuid = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeLayoutUuid", null));

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

        if (scopeType.equals("company")) {
            scopeGroup = _groupLocalService.getCompanyGroup(layout.getCompanyId());
        } else if (Validator.isNotNull(scopeLayoutUuid)) {
            scopeGroup = layout.getScopeGroup();
        }

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

    portletDataContext.setScopeType(scopeType);
    portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("root");

    portletDataContext.setExportDataRootElement(rootElement);

    Element headerElement = rootElement.addElement("header");

    headerElement.addAttribute("available-locales", StringUtil.merge(
            LanguageUtil.getAvailableLocales(_portal.getSiteGroupId(portletDataContext.getScopeGroupId()))));
    headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber()));
    headerElement.addAttribute("export-date", Time.getRFC822());

    if (portletDataContext.hasDateRange()) {
        headerElement.addAttribute("start-date", String.valueOf(portletDataContext.getStartDate()));
        headerElement.addAttribute("end-date", String.valueOf(portletDataContext.getEndDate()));
    }

    headerElement.addAttribute("type", portletDataContext.getType());
    headerElement.addAttribute("company-id", String.valueOf(portletDataContext.getCompanyId()));
    headerElement.addAttribute("company-group-id", String.valueOf(portletDataContext.getCompanyGroupId()));
    headerElement.addAttribute("group-id", String.valueOf(scopeGroupId));
    headerElement.addAttribute("user-personal-site-group-id",
            String.valueOf(portletDataContext.getUserPersonalSiteGroupId()));
    headerElement.addAttribute("private-layout", String.valueOf(layout.isPrivateLayout()));
    headerElement.addAttribute("root-portlet-id", portletDataContext.getRootPortletId());
    headerElement.addAttribute("schema-version", ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION);

    Element missingReferencesElement = rootElement.addElement("missing-references");

    portletDataContext.setMissingReferencesElement(missingReferencesElement);

    Map<String, Boolean> exportPortletControlsMap = _exportImportHelper.getExportPortletControlsMap(
            layout.getCompanyId(), portletDataContext.getPortletId(), portletDataContext.getParameterMap());

    exportPortlet(portletDataContext, layout.getPlid(), rootElement, exportPermissions,
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS),
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA),
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP),
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES));
    exportService(portletDataContext, rootElement,
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP));

    exportAssetLinks(portletDataContext);
    exportExpandoTables(portletDataContext);
    exportLocks(portletDataContext);

    portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(StagedAssetLink.class));

    _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext);

    if (exportPermissions) {
        _permissionExporter.exportPortletDataPermissions(portletDataContext);
    }

    _exportImportHelper.writeManifestSummary(document, portletDataContext.getManifestSummary());

    if (_log.isInfoEnabled()) {
        _log.info("Exporting portlet took " + stopWatch.getTime() + " ms");
    }

    try {
        portletDataContext.addZipEntry("/manifest.xml", document.formattedString());
    } catch (IOException ioe) {
        throw new SystemException("Unable to create the export LAR manifest file for portlet "
                + portletDataContext.getPortletId(), ioe);
    }

    ZipWriter zipWriter = portletDataContext.getZipWriter();

    return zipWriter.getFile();
}

From source file:com.liferay.exportimport.resources.importer.test.ResourcesImporterTest.java

License:Open Source License

protected void validateLayouts(Group importedGroup) throws Exception {
    long privateLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(importedGroup, true);

    Assert.assertEquals(1, privateLayoutsCount);

    long publicLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false);

    Assert.assertEquals(9, publicLayoutsCount);

    Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(importedGroup.getGroupId(), false, "/home");

    Map<Locale, String> nameMap = layout.getNameMap();

    Assert.assertTrue(nameMap.containsValue("Bienvenue"));

    Assert.assertTrue(layout.isTypePortlet());

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

    List<Portlet> portlets = layoutTypePortlet.getAllPortlets();

    Assert.assertEquals(portlets.toString(), 7, portlets.size());

    UnicodeProperties layoutTypeSettingsProperties = layout.getTypeSettingsProperties();

    String nestedColumnIds = layoutTypeSettingsProperties.get(LayoutTypePortletConstants.NESTED_COLUMN_IDS);

    Assert.assertTrue((nestedColumnIds != null) && nestedColumnIds.contains("column-1")
            && nestedColumnIds.contains("column-2"));

    layout = LayoutLocalServiceUtil.getFriendlyURLLayout(importedGroup.getGroupId(), false,
            "/layout-prototypes-page-1");

    Assert.assertTrue(layout.isLayoutPrototypeLinkActive());
    Assert.assertEquals("371647ba-3649-4039-bfe6-ae32cf404737", layout.getLayoutPrototypeUuid());

    layout = LayoutLocalServiceUtil.getFriendlyURLLayout(importedGroup.getGroupId(), false,
            "/layout-prototypes-page-2");

    Assert.assertFalse(layout.isLayoutPrototypeLinkActive());
    Assert.assertEquals("c98067d0-fc10-9556-7364-238d39693bc4", layout.getLayoutPrototypeUuid());

    layout = LayoutLocalServiceUtil.getFriendlyURLLayout(importedGroup.getGroupId(), false, "/url-page");

    Assert.assertTrue(layout.isTypeURL());

    layout = LayoutLocalServiceUtil.getFriendlyURLLayout(importedGroup.getGroupId(), false, "/hidden-page");

    Assert.assertTrue(layout.isHidden());
}

From source file:com.liferay.layout.admin.web.internal.control.menu.CustomizationSettingsProductNavigationControlMenuEntry.java

License:Open Source License

protected boolean isCustomizableLayout(ThemeDisplay themeDisplay) throws PortalException {

    Layout layout = themeDisplay.getLayout();

    Group group = layout.getGroup();

    if (group.isLayoutPrototype() || group.isLayoutSetPrototype() || group.isStagingGroup()
            || group.isUserGroup()) {/* w  w  w  .j  av  a2  s  . c  om*/

        return false;
    }

    LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

    if (!layout.isTypePortlet() || (layoutTypePortlet == null)) {
        return false;
    }

    if (layout.isCustomizable() && hasUpdateLayoutPermission(themeDisplay)) {

        return true;
    }

    if (!layoutTypePortlet.isCustomizable()) {
        return false;
    }

    if (!LayoutPermissionUtil.containsWithoutViewableGroup(themeDisplay.getPermissionChecker(), layout, false,
            ActionKeys.CUSTOMIZE)) {

        return false;
    }

    return true;
}

From source file:com.liferay.layout.admin.web.internal.control.menu.ToggleControlsProductNavigationControlMenuEntry.java

License:Open Source License

protected boolean hasCustomizePermission(ThemeDisplay themeDisplay) throws PortalException {

    Layout layout = themeDisplay.getLayout();
    LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

    if (!layout.isTypePortlet() || (layoutTypePortlet == null)) {
        return false;
    }/*from ww  w  . ja  va 2s .c o m*/

    if (!layoutTypePortlet.isCustomizable() || !layoutTypePortlet.isCustomizedView()) {

        return false;
    }

    if (LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout, ActionKeys.CUSTOMIZE)) {

        return true;
    }

    return false;
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.AddLayoutMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

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

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
    long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long parentLayoutId = ParamUtil.getLong(uploadPortletRequest, "parentLayoutId");
    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description");
    Map<Locale, String> keywordsMap = LocalizationUtil.getLocalizationMap(actionRequest, "keywords");
    Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(actionRequest, "robots");
    String type = ParamUtil.getString(uploadPortletRequest, "type");
    boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden");
    Map<Locale, String> friendlyURLMap = LocalizationUtil.getLocalizationMap(actionRequest, "friendlyURL");

    long layoutPrototypeId = ParamUtil.getLong(uploadPortletRequest, "layoutPrototypeId");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest);

    Layout layout = null;//from www  .  jav  a2s.c om

    boolean inheritFromParentLayoutId = ParamUtil.getBoolean(uploadPortletRequest, "inheritFromParentLayoutId");

    UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest,
            "TypeSettingsProperties--");

    String linkToLayoutUuid = ParamUtil.getString(actionRequest, "linkToLayoutUuid");

    if (Validator.isNotNull(linkToLayoutUuid)) {
        Layout linkToLayout = _layoutLocalService.getLayoutByUuidAndGroupId(linkToLayoutUuid, groupId,
                privateLayout);

        typeSettingsProperties.put("linkToLayoutId", String.valueOf(linkToLayout.getLayoutId()));
    }

    if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
        Layout parentLayout = _layoutLocalService.getLayout(groupId, privateLayout, parentLayoutId);

        layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                parentLayout.getDescriptionMap(), parentLayout.getKeywordsMap(), parentLayout.getRobotsMap(),
                parentLayout.getType(), parentLayout.getTypeSettings(), hidden, friendlyURLMap, serviceContext);

        inheritMobileRuleGroups(layout, serviceContext);

        if (parentLayout.isTypePortlet()) {
            com.liferay.portlet.sites.action.ActionUtil.copyPreferences(actionRequest, layout, parentLayout);

            SitesUtil.copyLookAndFeel(layout, parentLayout);
        }
    } else if (layoutPrototypeId > 0) {
        LayoutPrototype layoutPrototype = _layoutPrototypeService.getLayoutPrototype(layoutPrototypeId);

        boolean layoutPrototypeLinkEnabled = ParamUtil.getBoolean(uploadPortletRequest,
                "layoutPrototypeLinkEnabled" + layoutPrototype.getUuid());

        serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled);

        serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototype.getUuid());

        layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                descriptionMap, keywordsMap, robotsMap, LayoutConstants.TYPE_PORTLET,
                typeSettingsProperties.toString(), hidden, friendlyURLMap, serviceContext);

        // Force propagation from page template to page. See LPS-48430.

        SitesUtil.mergeLayoutPrototypeLayout(layout.getGroup(), layout);
    } else {
        long copyLayoutId = ParamUtil.getLong(uploadPortletRequest, "copyLayoutId");

        Layout copyLayout = null;

        String layoutTemplateId = ParamUtil.getString(uploadPortletRequest, "layoutTemplateId",
                PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);

        if (copyLayoutId > 0) {
            copyLayout = _layoutLocalService.fetchLayout(groupId, privateLayout, copyLayoutId);

            if ((copyLayout != null) && copyLayout.isTypePortlet()) {
                LayoutTypePortlet copyLayoutTypePortlet = (LayoutTypePortlet) copyLayout.getLayoutType();

                layoutTemplateId = copyLayoutTypePortlet.getLayoutTemplateId();

                typeSettingsProperties = copyLayout.getTypeSettingsProperties();
            }
        }

        layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                descriptionMap, keywordsMap, robotsMap, type, typeSettingsProperties.toString(), hidden,
                friendlyURLMap, serviceContext);

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

        layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId);

        _layoutService.updateLayout(groupId, privateLayout, layout.getLayoutId(), layout.getTypeSettings());

        if ((copyLayout != null) && copyLayout.isTypePortlet()) {
            com.liferay.portlet.sites.action.ActionUtil.copyPreferences(actionRequest, layout, copyLayout);

            SitesUtil.copyLookAndFeel(layout, copyLayout);
        }
    }

    _actionUtil.updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId,
            privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties());

    String portletResource = ParamUtil.getString(uploadPortletRequest, "portletResource");

    MultiSessionMessages.add(actionRequest, portletResource + "layoutAdded", layout);

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    if (Validator.isNull(redirect)) {
        redirect = _portal.getLayoutFullURL(layout, themeDisplay);

        if (layout.isTypeURL()) {
            redirect = _portal.getGroupFriendlyURL(layout.getLayoutSet(), themeDisplay);
        }
    }

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.CopyApplicationsMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long layoutId = ParamUtil.getLong(actionRequest, "layoutId");

    Layout layout = _layoutLocalService.getLayout(groupId, privateLayout, layoutId);

    String layoutType = layout.getType();

    if (!layoutType.equals(LayoutConstants.TYPE_PORTLET)) {
        return;//from w  ww . j a v a  2 s . c  o m
    }

    long copyLayoutId = ParamUtil.getLong(actionRequest, "copyLayoutId");

    if ((copyLayoutId == 0) || (copyLayoutId == layout.getLayoutId())) {
        return;
    }

    Layout copyLayout = _layoutLocalService.fetchLayout(groupId, privateLayout, copyLayoutId);

    if ((copyLayout == null) || !copyLayout.isTypePortlet()) {
        return;
    }

    UnicodeProperties sourceLayoutTypeSettingsProperties = copyLayout.getTypeSettingsProperties();

    ActionUtil.removePortletIds(actionRequest, layout);

    ActionUtil.copyPreferences(actionRequest, layout, copyLayout);

    SitesUtil.copyLookAndFeel(layout, copyLayout);

    _layoutService.updateLayout(groupId, privateLayout, layoutId,
            sourceLayoutTypeSettingsProperties.toString());
}

From source file:com.liferay.layout.admin.web.internal.servlet.taglib.ui.LayoutCustomizationSettingsFormNavigatorEntry.java

License:Open Source License

@Override
public boolean isVisible(User user, Layout layout) {
    Group group = layout.getGroup();

    if (group == null) {
        _log.error("Unable to display form for customization settings");
    }//from w w w  .  ja v  a2s.com

    if (!group.isUser() && layout.isTypePortlet()) {
        return true;
    }

    return false;
}

From source file:com.liferay.mobile.device.rules.rule.group.action.LayoutTemplateModificationActionHandler.java

License:Open Source License

@Override
public void applyAction(MDRAction mdrAction, HttpServletRequest request, HttpServletResponse response) {

    UnicodeProperties mdrActionTypeSettingsProperties = mdrAction.getTypeSettingsProperties();

    String layoutTemplateId = GetterUtil
            .getString(mdrActionTypeSettingsProperties.getProperty("layoutTemplateId"));

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

    Layout layout = themeDisplay.getLayout();

    if (layout.isTypePortlet()) {
        LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

        layoutTypePortlet.setLayoutTemplateId(0, layoutTemplateId, false);
    }//from  w  w w. j av a 2s  . com
}

From source file:com.liferay.portlet.configuration.icon.maximize.internal.MaximizePortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!GetterUtil.getBoolean(themeDisplay.getThemeSetting("show-maximize-minimize-application-links"))) {

        return false;
    }/*from  ww w. ja va  2s  .c  o  m*/

    Layout layout = themeDisplay.getLayout();

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

    LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

    LayoutTypeController layoutTypeController = layoutTypePortlet.getLayoutTypeController();

    if (layoutTypeController.isFullPageDisplayable()) {
        return false;
    }

    Portlet portlet = (Portlet) portletRequest.getAttribute(WebKeys.RENDER_PORTLET);

    if (!portlet.hasWindowState(portletRequest.getResponseContentType(), WindowState.MAXIMIZED)) {

        return false;
    }

    Group group = themeDisplay.getScopeGroup();

    if (!themeDisplay.isSignedIn() || (group.hasStagingGroup() && !group.isStagingGroup())
            || !hasUpdateLayoutPermission(themeDisplay)) {

        if (!PropsValues.LAYOUT_GUEST_SHOW_MAX_ICON) {
            return false;
        }
    }

    return true;
}

From source file:com.liferay.portlet.configuration.icon.minimize.internal.MinimizePortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!GetterUtil.getBoolean(themeDisplay.getThemeSetting("show-maximize-minimize-application-links"))) {

        return false;
    }//from  www  .j av  a 2s  . c o m

    Layout layout = themeDisplay.getLayout();

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

    LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

    LayoutTypeController layoutTypeController = layoutTypePortlet.getLayoutTypeController();

    if (layoutTypeController.isFullPageDisplayable()) {
        return false;
    }

    Portlet portlet = (Portlet) portletRequest.getAttribute(WebKeys.RENDER_PORTLET);

    if (!portlet.hasWindowState(portletRequest.getResponseContentType(), WindowState.MINIMIZED)) {

        return false;
    }

    Group group = themeDisplay.getScopeGroup();

    if (!themeDisplay.isSignedIn() || (group.hasStagingGroup() && !group.isStagingGroup())
            || !hasUpdateLayoutPermission(themeDisplay)) {

        if (!PropsValues.LAYOUT_GUEST_SHOW_MIN_ICON) {
            return false;
        }
    }

    return true;
}