List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getCompanyId
public long getCompanyId()
From source file:com.liferay.journal.web.util.JournalRSSUtil.java
License:Open Source License
public byte[] getRSS(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); JournalFeed feed = null;/* w w w . j a v a 2 s .co m*/ long id = ParamUtil.getLong(resourceRequest, "id"); if (id > 0) { try { feed = _journalFeedLocalService.getFeed(id); } catch (NoSuchFeedException nsfe) { // Backward compatibility with old URLs feed = _journalFeedLocalService.getFeed(themeDisplay.getScopeGroupId(), String.valueOf(id)); } } else { long groupId = ParamUtil.getLong(resourceRequest, "groupId"); String feedId = ParamUtil.getString(resourceRequest, "feedId"); feed = _journalFeedLocalService.getFeed(groupId, feedId); } String languageId = LanguageUtil.getLanguageId(resourceRequest); long plid = _portal.getPlidFromFriendlyURL(themeDisplay.getCompanyId(), feed.getTargetLayoutFriendlyUrl()); Layout layout = null; if (plid > 0) { layout = _layoutLocalService.fetchLayout(plid); } if (layout == null) { layout = themeDisplay.getLayout(); } String rss = exportToRSS(resourceRequest, resourceResponse, feed, languageId, layout, themeDisplay); return rss.getBytes(StringPool.UTF8); }
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(); }/*from ww w .j ava2 s . c o m*/ 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.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;/* w w w .j a v a2 s . com*/ 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.AddSimpleLayoutMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { 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(actionRequest, "parentLayoutId"); String name = ParamUtil.getString(actionRequest, "name"); String type = ParamUtil.getString(actionRequest, "type"); Map<Locale, String> nameMap = new HashMap<>(); nameMap.put(themeDisplay.getLocale(), name); ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest); UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest, "TypeSettingsProperties--"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); try {// w ww. j av a 2s .c o m Layout layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, new HashMap<Locale, String>(), new HashMap<Locale, String>(), new HashMap<Locale, String>(), new HashMap<Locale, String>(), type, typeSettingsProperties.toString(), false, new HashMap<Locale, String>(), serviceContext); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID); _layoutService.updateLayout(groupId, privateLayout, layout.getLayoutId(), layout.getTypeSettings()); _actionUtil.updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId, privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties()); jsonObject.put("redirectURL", getRedirectURL(actionResponse)); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } catch (PortalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(themeDisplay.getLocale()); jsonObject.put("error", LanguageUtil.get(resourceBundle, "an-unexpected-error-occurred")); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } }
From source file:com.liferay.layout.admin.web.internal.portlet.action.DeleteOrphanPortletsMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long selPlid = ParamUtil.getLong(actionRequest, "selPlid"); String[] portletIds = null;/*from w ww . j av a2 s . c o m*/ String portletId = ParamUtil.getString(actionRequest, "portletId"); if (Validator.isNotNull(portletId)) { portletIds = new String[] { portletId }; } else { portletIds = ParamUtil.getStringValues(actionRequest, "rowIds"); } if (portletIds.length > 0) { _portletLocalService.deletePortlets(themeDisplay.getCompanyId(), portletIds, selPlid); } }
From source file:com.liferay.layout.admin.web.internal.portlet.action.EditLayoutMVCActionCommand.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 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()); }//from www.ja v a 2 s .com ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest); Layout layout = _layoutLocalService.getLayout(groupId, privateLayout, layoutId); String currentType = layout.getType(); layout = _layoutService.updateLayout(groupId, privateLayout, layoutId, layout.getParentLayoutId(), nameMap, titleMap, descriptionMap, keywordsMap, robotsMap, type, hidden, friendlyURLMap, !deleteLogo, iconBytes, serviceContext); themeDisplay.clearLayoutFriendlyURL(layout); UnicodeProperties layoutTypeSettingsProperties = layout.getTypeSettingsProperties(); UnicodeProperties formTypeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest, "TypeSettingsProperties--"); String linkToLayoutUuid = ParamUtil.getString(actionRequest, "linkToLayoutUuid"); if (Validator.isNotNull(linkToLayoutUuid)) { Layout linkToLayout = _layoutLocalService.getLayoutByUuidAndGroupId(linkToLayoutUuid, groupId, privateLayout); formTypeSettingsProperties.put("linkToLayoutId", String.valueOf(linkToLayout.getLayoutId())); } 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); boolean layoutCustomizable = GetterUtil .getBoolean(layoutTypeSettingsProperties.get(LayoutConstants.CUSTOMIZABLE_LAYOUT)); if (!layoutCustomizable) { layoutTypePortlet.removeCustomization(layoutTypeSettingsProperties); } layout = _layoutService.updateLayout(groupId, privateLayout, layoutId, layoutTypeSettingsProperties.toString()); if (!currentType.equals(LayoutConstants.TYPE_PORTLET)) { _portletPreferencesLocalService.deletePortletPreferences(0, PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid()); } } else { layoutTypeSettingsProperties.putAll(formTypeSettingsProperties); layoutTypeSettingsProperties.putAll(layout.getTypeSettingsProperties()); layout = _layoutService.updateLayout(groupId, privateLayout, layoutId, layoutTypeSettingsProperties.toString()); } HttpServletResponse response = _portal.getHttpServletResponse(actionResponse); EventsProcessorUtil.process(PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE, layoutTypePortlet.getConfigurationActionUpdate(), uploadPortletRequest, response); _actionUtil.updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId, privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties()); String redirect = ParamUtil.getString(actionRequest, "redirect"); if (Validator.isNull(redirect)) { redirect = _portal.getLayoutFullURL(layout, themeDisplay); } String portletResource = ParamUtil.getString(actionRequest, "portletResource"); MultiSessionMessages.add(actionRequest, portletResource + "layoutUpdated", layout); actionRequest.setAttribute(WebKeys.REDIRECT, redirect); }
From source file:com.liferay.layout.admin.web.internal.portlet.action.EditLayoutSetMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long layoutSetId = ParamUtil.getLong(actionRequest, "layoutSetId"); long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId"); long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId"); boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout"); LayoutSet layoutSet = _layoutSetLocalService.getLayoutSet(layoutSetId); updateLogo(actionRequest, liveGroupId, stagingGroupId, privateLayout); updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId, privateLayout, layoutSet.getSettingsProperties()); updateMergePages(actionRequest, liveGroupId); updateRobots(actionRequest, liveGroupId, privateLayout); updateSettings(actionRequest, liveGroupId, stagingGroupId, privateLayout, layoutSet.getSettingsProperties()); }
From source file:com.liferay.layout.admin.web.internal.servlet.taglib.ui.LayoutCustomFieldsFormNavigatorEntry.java
License:Open Source License
@Override public boolean isVisible(User user, Layout layout) { boolean hasCustomAttributesAvailable = false; try {/*from w ww. j a v a2 s. co m*/ ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); ThemeDisplay themeDisplay = serviceContext.getThemeDisplay(); long classPK = 0; if (layout != null) { classPK = layout.getPlid(); } hasCustomAttributesAvailable = CustomAttributesUtil.hasCustomAttributes(themeDisplay.getCompanyId(), Layout.class.getName(), classPK, null); } catch (Exception e) { } return hasCustomAttributesAvailable; }
From source file:com.liferay.layout.prototype.web.internal.display.context.LayoutPrototypeDisplayContext.java
License:Open Source License
public SearchContainer getSearchContainer() { ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); SearchContainer searchContainer = new SearchContainer(_renderRequest, _renderResponse.createRenderURL(), null, "there-are-no-page-templates"); if (isShowAddButton()) { searchContainer//ww w .j a v a2 s . c om .setEmptyResultsMessageCssClass("there-are-no-page-templates.-you-can-add-a-page-template-by-" + "clicking-the-plus-button-on-the-bottom-right-corner"); searchContainer.setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn"); } searchContainer.setId("layoutPrototype"); searchContainer.setRowChecker(new EmptyOnClickRowChecker(_renderResponse)); boolean orderByAsc = false; if (getOrderByType().equals("asc")) { orderByAsc = true; } OrderByComparator<LayoutPrototype> orderByComparator = new LayoutPrototypeCreateDateComparator(orderByAsc); searchContainer.setOrderByCol(getOrderByCol()); searchContainer.setOrderByComparator(orderByComparator); searchContainer.setOrderByType(getOrderByType()); searchContainer.setTotal(getTotal()); List results = LayoutPrototypeLocalServiceUtil.search(themeDisplay.getCompanyId(), getActive(), searchContainer.getStart(), searchContainer.getEnd(), searchContainer.getOrderByComparator()); searchContainer.setResults(results); return searchContainer; }
From source file:com.liferay.layout.prototype.web.internal.display.context.LayoutPrototypeDisplayContext.java
License:Open Source License
protected int getTotal() { ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); return LayoutPrototypeLocalServiceUtil.searchCount(themeDisplay.getCompanyId(), getActive()); }