public void addLayout(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.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; boolean inheritFromParentLayoutId = ParamUtil.getBoolean(uploadPortletRequest, "inheritFromParentLayoutId"); UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest, "TypeSettingsProperties--"); 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()) { 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()) { ActionUtil.copyPreferences(actionRequest, layout, copyLayout); SitesUtil.copyLookAndFeel(layout, copyLayout); } } updateLookAndFeel( actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId, privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties()); }
public void editLayout(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.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 layoutId = ParamUtil.getLong(actionRequest, "layoutId"); 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"); boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo"); byte[] iconBytes = null; long fileEntryId = ParamUtil.getLong(uploadPortletRequest, "fileEntryId"); if (fileEntryId > 0) { FileEntry fileEntry = dlAppLocalService.getFileEntry(fileEntryId); iconBytes = FileUtil.getBytes(fileEntry.getContentStream()); } ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest); Layout layout = layoutLocalService.getLayout(groupId, privateLayout, layoutId); layout = layoutService.updateLayout( groupId, privateLayout, layoutId, layout.getParentLayoutId(), nameMap, titleMap, descriptionMap, keywordsMap, robotsMap, type, hidden, friendlyURLMap, !deleteLogo, iconBytes, serviceContext); UnicodeProperties layoutTypeSettingsProperties = layout.getTypeSettingsProperties(); UnicodeProperties formTypeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest, "TypeSettingsProperties--"); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); if (type.equals(LayoutConstants.TYPE_PORTLET)) { String layoutTemplateId = ParamUtil.getString( uploadPortletRequest, "layoutTemplateId", PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID); layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId); layoutTypeSettingsProperties.putAll(formTypeSettingsProperties); layoutService.updateLayout( groupId, privateLayout, layoutId, layoutTypeSettingsProperties.toString()); } else { layout.setTypeSettingsProperties(formTypeSettingsProperties); layoutTypeSettingsProperties.putAll(layout.getTypeSettingsProperties()); layoutService.updateLayout(groupId, privateLayout, layoutId, layout.getTypeSettings()); } HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); EventsProcessorUtil.process( PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE, layoutTypePortlet.getConfigurationActionUpdate(), uploadPortletRequest, response); updateLookAndFeel( actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId, privateLayout, layout.getLayoutId(), layoutTypeSettingsProperties); }
@Override public String getActualURL( long companyId, long groupId, boolean privateLayout, String mainPath, String friendlyURL, Map<String, String[]> params, Map<String, Object> requestContext) throws PortalException { String urlTitle = friendlyURL.substring(JournalArticleConstants.CANONICAL_URL_SEPARATOR.length()); JournalArticle journalArticle = _journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle); Layout layout = getJournalArticleLayout(groupId, privateLayout, friendlyURL); String layoutActualURL = PortalUtil.getLayoutActualURL(layout, mainPath); InheritableMap<String, String[]> actualParams = new InheritableMap<>(); if (params != null) { actualParams.setParentMap(params); } UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties(); String defaultAssetPublisherPortletId = typeSettingsProperties.get(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID); String currentDefaultAssetPublisherPortletId = defaultAssetPublisherPortletId; if (Validator.isNull(defaultAssetPublisherPortletId)) { PortletInstance portletInstance = new PortletInstance(AssetPublisherPortletKeys.ASSET_PUBLISHER); defaultAssetPublisherPortletId = portletInstance.getPortletInstanceKey(); } HttpServletRequest request = (HttpServletRequest) requestContext.get("request"); if (Validator.isNull(currentDefaultAssetPublisherPortletId)) { String actualPortletAuthenticationToken = AuthTokenUtil.getToken(request, layout.getPlid(), defaultAssetPublisherPortletId); actualParams.put("p_p_auth", new String[] {actualPortletAuthenticationToken}); } actualParams.put("p_p_id", new String[] {defaultAssetPublisherPortletId}); actualParams.put("p_p_lifecycle", new String[] {"0"}); if (Validator.isNull(currentDefaultAssetPublisherPortletId)) { actualParams.put("p_p_state", new String[] {WindowState.MAXIMIZED.toString()}); } actualParams.put("p_p_mode", new String[] {"view"}); actualParams.put("p_j_a_id", new String[] {String.valueOf(journalArticle.getId())}); String namespace = PortalUtil.getPortletNamespace(defaultAssetPublisherPortletId); actualParams.put(namespace + "mvcPath", new String[] {"/view_content.jsp"}); AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName( JournalArticle.class.getName()); actualParams.put(namespace + "type", new String[] {assetRendererFactory.getType()}); actualParams.put(namespace + "urlTitle", new String[] {journalArticle.getUrlTitle()}); String queryString = HttpUtil.parameterMapToString(actualParams, false); if (layoutActualURL.contains(StringPool.QUESTION)) { layoutActualURL = layoutActualURL + StringPool.AMPERSAND + queryString; } else { layoutActualURL = layoutActualURL + StringPool.QUESTION + queryString; } Locale locale = PortalUtil.getLocale(request); PortalUtil.addPageSubtitle(journalArticle.getTitle(locale), request); PortalUtil.addPageDescription(journalArticle.getDescription(locale), request); List<AssetTag> assetTags = _assetTagLocalService.getTags( JournalArticle.class.getName(), journalArticle.getPrimaryKey()); if (!assetTags.isEmpty()) { PortalUtil.addPageKeywords(ListUtil.toString(assetTags, AssetTag.NAME_ACCESSOR), request); } return layoutActualURL; }