List of usage examples for com.liferay.portal.kernel.service PortletLocalServiceUtil getPortletById
public static com.liferay.portal.kernel.model.Portlet getPortletById(long companyId, String portletId)
From source file:com.liferay.application.list.taglib.display.context.logic.PanelAppContentHelper.java
License:Open Source License
protected Portlet getPortlet() { if ((_portlet == null) && Validator.isNotNull(getPortletId())) { _portlet = PortletLocalServiceUtil.getPortletById(getCompanyId(), getPortletId()); }//from www . j a va 2 s . c o m return _portlet; }
From source file:com.liferay.application.list.taglib.servlet.taglib.PanelAppTag.java
License:Open Source License
@Override protected void setAttributes(HttpServletRequest request) { boolean active = false; ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); if (_active != null) { active = _active.booleanValue(); } else {//from ww w .j a v a 2s. com active = Objects.equals(themeDisplay.getPpid(), _panelApp.getPortletId()); } request.setAttribute("liferay-application-list:panel-app:active", active); if (_data == null) { _data = new HashMap<>(); } if (Validator.isNull(_label) && (_panelApp != null)) { Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), _panelApp.getPortletId()); _label = PortalUtil.getPortletTitle(portlet, servletContext, themeDisplay.getLocale()); if (!_data.containsKey("qa-id")) { _data.put("qa-id", "app"); } } if (!_data.containsKey("title")) { _data.put("title", _label); } request.setAttribute("liferay-application-list:panel-app:data", _data); if (Validator.isNull(_id)) { _id = "portlet_" + _panelApp.getPortletId(); } request.setAttribute("liferay-application-list:panel-app:id", _id); request.setAttribute("liferay-application-list:panel-app:label", _label); int notificationsCount = 0; if (_panelApp != null) { notificationsCount = _panelApp.getNotificationsCount(themeDisplay.getUser()); } request.setAttribute("liferay-application-list:panel-app:notificationsCount", notificationsCount); request.setAttribute("liferay-application-list:panel-app:panelApp", _panelApp); if (Validator.isNull(_url) && (_panelApp != null)) { PortletURL portletURL = null; try { portletURL = _panelApp.getPortletURL(request); } catch (PortalException pe) { _log.error("Unable to get portlet URL", pe); } _url = portletURL.toString(); } request.setAttribute("liferay-application-list:panel-app:url", _url); }
From source file:com.liferay.exportimport.test.LayoutSetPrototypePropagationTest.java
License:Open Source License
@Test public void testPortletPreferencesPropagationWithPreferencesUniquePerLayoutEnabled() throws Exception { Portlet portlet = PortletLocalServiceUtil.getPortletById(TestPropsValues.getCompanyId(), JournalContentPortletKeys.JOURNAL_CONTENT); boolean preferencesUniquePerLayout = portlet.getPreferencesUniquePerLayout(); try {/*from w w w.jav a2 s . com*/ portlet.setPreferencesUniquePerLayout(false); _layoutSetPrototypeLayout = LayoutTestUtil.addLayout(_layoutSetPrototypeGroup, true, layoutPrototype, true); Map<String, String[]> preferenceMap = new HashMap<>(); preferenceMap.put("bulletStyle", new String[] { "Dots" }); String testPortletId1 = LayoutTestUtil.addPortletToLayout(TestPropsValues.getUserId(), _layoutSetPrototypeLayout, JournalContentPortletKeys.JOURNAL_CONTENT, "column-1", preferenceMap); preferenceMap.put("bulletStyle", new String[] { "Arrows" }); String testPortletId2 = LayoutTestUtil.addPortletToLayout(TestPropsValues.getUserId(), _layoutSetPrototypeLayout, JournalContentPortletKeys.JOURNAL_CONTENT, "column-2", preferenceMap); propagateChanges(group); Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(group.getGroupId(), false, _layoutSetPrototypeLayout.getFriendlyURL()); PortletPreferences testPortletIdPortletPreferences = PortletPreferencesFactoryUtil .getPortletSetup(group.getGroupId(), layout, JournalContentPortletKeys.JOURNAL_CONTENT, null); Assert.assertEquals("Arrows", testPortletIdPortletPreferences.getValue("bulletStyle", StringPool.BLANK)); PortletPreferences testPortletId1PortletPreferences = PortletPreferencesFactoryUtil .getPortletSetup(layout, testPortletId1, null); Assert.assertEquals("Arrows", testPortletId1PortletPreferences.getValue("bulletStyle", StringPool.BLANK)); PortletPreferences testPortletId2PortletPreferences = PortletPreferencesFactoryUtil .getPortletSetup(layout, testPortletId2, null); Assert.assertEquals("Arrows", testPortletId2PortletPreferences.getValue("bulletStyle", StringPool.BLANK)); } finally { portlet.setPreferencesUniquePerLayout(preferencesUniquePerLayout); } }
From source file:com.liferay.exportimport.test.util.lar.BasePortletExportImportTestCase.java
License:Open Source License
protected void testExportImportAvailableLocales(Collection<Locale> sourceAvailableLocales, Collection<Locale> targetAvailableLocales, boolean expectFailure) throws Exception { Portlet portlet = PortletLocalServiceUtil.getPortletById(group.getCompanyId(), getPortletId()); if (portlet == null) { return;/*from www. j a v a 2 s . c om*/ } PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance(); if (!portletDataHandler.isDataLocalized()) { Assert.assertTrue("This test does not apply", true); return; } GroupTestUtil.updateDisplaySettings(group.getGroupId(), sourceAvailableLocales, null); GroupTestUtil.updateDisplaySettings(importedGroup.getGroupId(), targetAvailableLocales, null); try { exportImportPortlet(getPortletId()); Assert.assertFalse(expectFailure); } catch (LocaleException le) { Assert.assertTrue(expectFailure); } }
From source file:com.liferay.exportimport.test.util.lar.BasePortletExportImportTestCase.java
License:Open Source License
protected void testExportImportDisplayStyle(long displayStyleGroupId, String scopeType) throws Exception { Portlet portlet = PortletLocalServiceUtil.getPortletById(group.getCompanyId(), getPortletId()); if (portlet == null) { return;// w w w .j a va 2s . co m } if (scopeType.equals("layout") && !portlet.isScopeable()) { Assert.assertTrue("This test does not apply", true); return; } TemplateHandler templateHandler = portlet.getTemplateHandlerInstance(); if ((templateHandler == null) || !templateHandler.isDisplayTemplateHandler()) { Assert.assertTrue("This test does not apply", true); return; } String className = templateHandler.getClassName(); long resourceClassNameId = PortalUtil .getClassNameId("com.liferay.portlet.display.template.PortletDisplayTemplate"); DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(displayStyleGroupId, PortalUtil.getClassNameId(className), 0, resourceClassNameId); Map<String, String[]> preferenceMap = new HashMap<>(); String displayStyle = PortletDisplayTemplateManager.DISPLAY_STYLE_PREFIX + ddmTemplate.getTemplateKey(); preferenceMap.put("displayStyle", new String[] { displayStyle }); preferenceMap.put("displayStyleGroupId", new String[] { String.valueOf(ddmTemplate.getGroupId()) }); if (scopeType.equals("layout")) { preferenceMap.put("lfrScopeLayoutUuid", new String[] { this.layout.getUuid() }); } preferenceMap.put("lfrScopeType", new String[] { scopeType }); PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap); String importedDisplayStyle = portletPreferences.getValue("displayStyle", StringPool.BLANK); Assert.assertEquals(displayStyle, importedDisplayStyle); long importedDisplayStyleGroupId = GetterUtil .getLong(portletPreferences.getValue("displayStyleGroupId", null)); long expectedDisplayStyleGroupId = importedGroup.getGroupId(); if (scopeType.equals("company")) { Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(importedGroup.getCompanyId()); expectedDisplayStyleGroupId = companyGroup.getGroupId(); } else if (displayStyleGroupId != group.getGroupId()) { expectedDisplayStyleGroupId = displayStyleGroupId; } Assert.assertEquals(expectedDisplayStyleGroupId, importedDisplayStyleGroupId); }
From source file:com.liferay.exportimport.web.internal.portlet.action.ActionUtil.java
License:Open Source License
public static Portlet getPortlet(PortletRequest portletRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); String portletId = ParamUtil.getString(portletRequest, "portletResource"); Layout layout = PortletConfigurationLayoutUtil.getLayout(themeDisplay); if (!PortletPermissionUtil.contains(permissionChecker, themeDisplay.getScopeGroupId(), layout, portletId, ActionKeys.CONFIGURATION)) { throw new PrincipalException.MustHavePermission(permissionChecker, Portlet.class.getName(), portletId, ActionKeys.CONFIGURATION); }// ww w.j a v a 2 s. c o m return PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId); }
From source file:com.liferay.faces.bridge.ext.context.internal.PortalContextBridgeLiferayImpl.java
License:Open Source License
private boolean isLiferayNamespacingParameters(PortletRequest portletRequest) { boolean liferayNamespacingParameters = false; String portletId = (String) portletRequest.getAttribute(WebKeys.PORTLET_ID); try {/* w ww. j a v a 2 s . co m*/ ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId); liferayNamespacingParameters = portlet.isRequiresNamespacedParameters(); } catch (SystemException e) { logger.error(e); } return liferayNamespacingParameters; }
From source file:com.liferay.faces.bridge.ext.filter.internal.LiferayURLGeneratorBaseImpl.java
License:Open Source License
public String generateURL(Map<String, String[]> additionalParameterMap, String cacheability, PortletMode portletMode, String resourceId, WindowState windowState) { String toStringValue;/* w ww . jav a 2 s.c o m*/ if (baseURL.contains(Portal.FRIENDLY_URL_SEPARATOR)) { toStringValue = baseURL; } else { StringBuilder url = new StringBuilder(); // Build up a new URL string based on the one returned by Liferay, but discard everything after the // question mark because it's filled with all kinds of unnecessary stuff. url.append(prefix); // Possibly add the p_auth parameter. boolean firstParameter = true; String portalAuthToken = StringHelper.toString(additionalParameterMap.get(P_AUTH), parameterMap.get(P_AUTH)); if (portalAuthToken != null) { appendParameterToURL(firstParameter, P_AUTH, portalAuthToken, url); firstParameter = false; } // Possibly add the p_l_id parameter. String plid = StringHelper.toString(additionalParameterMap.get(P_L_ID), parameterMap.get(P_L_ID)); if (plid != null) { appendParameterToURL(firstParameter, P_L_ID, plid, url); firstParameter = false; } // Possibly add the p_p_auth parameter. String portletAuthToken = StringHelper.toString(additionalParameterMap.get(P_P_AUTH), parameterMap.get(P_P_AUTH)); if (portletAuthToken != null) { boolean addPortletAuthToken = true; if ((LIFERAY_BUILD_NUMBER < 6102) || ((LIFERAY_BUILD_NUMBER > 6102) && (LIFERAY_BUILD_NUMBER < 6130))) { // Versions of Liferay Portal prior to 6.1.2-CE/6.1.30-EE suffered from LPS-36481 which caused // PortletURLImpl.addPortletAuthToken(StringBundle, Key) method to add the p_p_auth parameter to // URLs for portlets when add-default-resource=false. It is therefore necessary to check that // add-default-resource=true before adding the p_p_auth parameter to the URL. FacesContext facesContext = FacesContext.getCurrentInstance(); PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest(); String portletId = (String) portletRequest.getAttribute(WebKeys.PORTLET_ID); ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); try { Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId); addPortletAuthToken = portlet.isAddDefaultResource(); } catch (SystemException e) { logger.error(e); } } if (addPortletAuthToken) { appendParameterToURL(firstParameter, P_P_AUTH, portletAuthToken, url); firstParameter = false; } } // Always add the p_p_id parameter String parameterValue = StringHelper.toString(additionalParameterMap.get(P_P_ID), responseNamespace); if (parameterValue.startsWith("_")) { parameterValue = parameterValue.substring(1); } if (parameterValue.endsWith("_")) { parameterValue = parameterValue.substring(0, parameterValue.length() - 1); } appendParameterToURL(firstParameter, P_P_ID, parameterValue, url); firstParameter = false; // Always add the p_p_lifecycle parameter. String portletLifecycleId = getPortletLifecycleId(); appendParameterToURL(P_P_LIFECYCLE, portletLifecycleId, url); // Add the p_p_state parameter. FacesContext facesContext = FacesContext.getCurrentInstance(); Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap(); WindowState urlWindowState = initialWindowState; if (additionalParameterMap.get(P_P_STATE) != null) { urlWindowState = new WindowState(additionalParameterMap.get(P_P_STATE)[0]); } if (windowState != null) { urlWindowState = windowState; } if (urlWindowState == null) { parameterValue = (String) applicationMap.get(responseNamespace + P_P_STATE); } else { parameterValue = urlWindowState.toString(); } appendParameterToURL(P_P_STATE, parameterValue, url); // Possibly add the p_p_state_rcv parameter. String stateRestoreCurrentView = StringHelper.toString(additionalParameterMap.get(P_P_STATE_RCV), parameterMap.get(P_P_STATE_RCV)); if (stateRestoreCurrentView != null) { appendParameterToURL(P_P_STATE_RCV, stateRestoreCurrentView, url); } // Add the p_p_mode parameter. PortletMode urlPortletMode = initialPortletMode; if (additionalParameterMap.get(P_P_MODE) != null) { urlPortletMode = new PortletMode(additionalParameterMap.get(P_P_MODE)[0]); } if (portletMode != null) { urlPortletMode = portletMode; } if (urlPortletMode == null) { parameterValue = (String) applicationMap.get(responseNamespace + P_P_MODE); } else { parameterValue = urlPortletMode.toString(); } appendParameterToURL(P_P_MODE, parameterValue, url); // Possibly add the p_p_cacheability parameter if (LIFECYCLE_RESOURCE_PHASE_ID.equals(portletLifecycleId)) { String urlCacheability = null; if (cacheability != null) { urlCacheability = cacheability; } if (urlCacheability == null) { urlCacheability = StringHelper.toString(additionalParameterMap.get(P_P_CACHEABILITY), parameterMap.get(P_P_CACHEABILITY)); } if (urlCacheability != null) { appendParameterToURL(P_P_CACHEABILITY, urlCacheability, url); } } // Always add the p_p_col_id parameter parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_ID); appendParameterToURL(P_P_COL_ID, parameterValue, url); // Possibly add the p_p_col_count parameter. parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_COUNT); appendParameterToURL(P_P_COL_COUNT, parameterValue, url); // Add the p_p_col_pos parameter if it is greater than zero (same logic as Liferay's // PortletURLImpl.toString()) parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_POS); if ((parameterValue != null) && (parameterValue.length() > 0)) { try { int colPos = Integer.parseInt(parameterValue); if (colPos > 0) { appendParameterToURL(P_P_COL_POS, parameterValue, url); } } catch (NumberFormatException e) { // ignore } } // Possibly add the p_o_p_id parameter. String outerPortletId = StringHelper.toString(additionalParameterMap.get(P_O_P_ID), parameterMap.get(P_O_P_ID)); if (outerPortletId != null) { appendParameterToURL(P_O_P_ID, outerPortletId, url); } // Possibly add the doAsUserId parameter. String doAsUserId = StringHelper.toString(additionalParameterMap.get(DO_AS_USER_ID), parameterMap.get(DO_AS_USER_ID)); if (doAsUserId != null) { appendParameterToURL(DO_AS_USER_ID, doAsUserId, url); } // Possibly add the doAsUserLanguageId parameter. String doAsUserLanguageId = StringHelper.toString(additionalParameterMap.get(DO_AS_USER_LANGUAGE_ID), parameterMap.get(DO_AS_USER_LANGUAGE_ID)); if (doAsUserLanguageId != null) { appendParameterToURL(DO_AS_USER_LANGUAGE_ID, doAsUserLanguageId, url); } // Possibly add the doAsGroupId parameter. String doAsGroupId = StringHelper.toString(additionalParameterMap.get(DO_AS_GROUP_ID), parameterMap.get(DO_AS_GROUP_ID)); if (doAsGroupId != null) { appendParameterToURL(DO_AS_GROUP_ID, doAsGroupId, url); } // Possibly add the refererGroupId parameter. String refererGroupId = StringHelper.toString(additionalParameterMap.get(REFERER_GROUP_ID), parameterMap.get(REFERER_GROUP_ID)); if (refererGroupId != null) { appendParameterToURL(REFERER_GROUP_ID, refererGroupId, url); } // Possibly add the refererPlid parameter. String refererPlid = StringHelper.toString(additionalParameterMap.get(REFERER_PLID), parameterMap.get(REFERER_PLID)); if (refererPlid != null) { appendParameterToURL(REFERER_PLID, refererPlid, url); } // Possibly add the controlPanelCategory parameter. String controlPanelCategory = StringHelper.toString(additionalParameterMap.get(CONTROL_PANEL_CATEGORY), parameterMap.get(CONTROL_PANEL_CATEGORY)); if (controlPanelCategory != null) { appendParameterToURL(CONTROL_PANEL_CATEGORY, controlPanelCategory, url); } // Add request parameters from the request parameter map. boolean namespaced = !responseNamespace.startsWith("wsrp"); Set<Map.Entry<String, String[]>> mapEntries = additionalParameterMap.entrySet(); if (mapEntries != null) { for (Map.Entry<String, String[]> mapEntry : mapEntries) { String[] parameterValues = mapEntry.getValue(); if (parameterValues != null) { String parameterName = mapEntry.getKey(); if (!LIFERAY_NON_NAMESPACED_PARAMS.contains(parameterName)) { for (String curParameterValue : parameterValues) { if (curParameterValue != null) { String encodedParameterValue = encode(curParameterValue); appendParameterToURL(firstParameter, namespaced, parameterName, encodedParameterValue, url); } } } } } } // Add WSRP URL parameters for (LiferayURLParameter wsrpParameter : wsrpParameters) { appendParameterToURL(wsrpParameter.getName(), wsrpParameter.getValue(), url); } // Possibly add the p_p_resource_id parameter. String urlResourceId = parameterMap.get(P_O_P_ID); if (resourceId != null) { urlResourceId = resourceId; } if (urlResourceId == null) { if (prefix.startsWith("wsrp")) { appendParameterToURL(P_P_RESOURCE_ID, "wsrp", url); } } else { appendParameterToURL(P_P_RESOURCE_ID, urlResourceId, url); } // Possibly add a Portlet URL Anchor if (portletURLAnchor != null) { url.append(portletURLAnchor); } toStringValue = url.toString(); } return toStringValue; }
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(); }// ww w. ja v a 2 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; }