List of usage examples for com.liferay.portal.kernel.portlet PortletIdCodec decodePortletName
public static String decodePortletName(String portletId)
From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java
License:Open Source License
public String getRootPortletId() { if (_rootPortletId != null) { return _rootPortletId; }//from w w w . j a v a 2 s .co m _rootPortletId = PortletIdCodec.decodePortletName(getPortletResource()); return _rootPortletId; }
From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java
License:Open Source License
public void addAndStoreSelection(PortletRequest portletRequest, String className, long classPK, int assetEntryOrder) throws Exception { String portletId = _portal.getPortletId(portletRequest); String rootPortletId = PortletIdCodec.decodePortletName(portletId); if (!rootPortletId.equals(AssetPublisherPortletKeys.ASSET_PUBLISHER)) { return;/*from ww w . j a v a 2 s . c o m*/ } ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); Layout layout = _layoutLocalService.fetchLayout(themeDisplay.getPlid()); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, portletId); if (portletPreferences instanceof StrictPortletPreferencesImpl) { return; } String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic"); if (selectionStyle.equals("dynamic")) { return; } AssetEntry assetEntry = _assetEntryLocalService.getEntry(className, classPK); addSelection(portletPreferences, assetEntry.getEntryId(), assetEntryOrder, className); portletPreferences.store(); }
From source file:com.liferay.asset.publisher.web.portlet.action.AssetPublisherConfigurationAction.java
License:Open Source License
@Override public void include(PortletConfig portletConfig, HttpServletRequest request, HttpServletResponse response) throws Exception { String portletResource = ParamUtil.getString(request, "portletResource"); String rootPortletId = PortletIdCodec.decodePortletName(portletResource); AssetPublisherCustomizer assetPublisherCustomizer = assetPublisherCustomizerRegistry .getAssetPublisherCustomizer(rootPortletId); request.setAttribute(AssetPublisherWebKeys.ASSET_PUBLISHER_CUSTOMIZER, assetPublisherCustomizer); request.setAttribute(AssetPublisherWebKeys.ASSET_PUBLISHER_WEB_CONFIGURATION, assetPublisherWebConfiguration); request.setAttribute(AssetPublisherWebKeys.ASSET_PUBLISHER_WEB_UTIL, assetPublisherWebUtil); request.setAttribute(AssetPublisherWebKeys.ITEM_SELECTOR, itemSelector); request.setAttribute(AssetPublisherWebKeys.ASSET_PUBLISHER_PORTLET_INSTANCE_CONFIGURATION, _getAssetPublisherPortletInstanceConfiguration(request)); super.include(portletConfig, request, response); }
From source file:com.liferay.asset.publisher.web.portlet.AssetPublisherPortlet.java
License:Open Source License
public void getRSS(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException { PortletPreferences portletPreferences = resourceRequest.getPreferences(); boolean enableRss = GetterUtil.getBoolean(portletPreferences.getValue("enableRss", null)); if (!portal.isRSSFeedsEnabled() || !enableRss) { try {/*from ww w . ja v a2 s . c o m*/ portal.sendRSSFeedsDisabledError(resourceRequest, resourceResponse); } catch (ServletException se) { } return; } resourceResponse.setContentType(ContentTypes.TEXT_XML_UTF8); try (OutputStream outputStream = resourceResponse.getPortletOutputStream()) { String rootPortletId = PortletIdCodec.decodePortletName(portal.getPortletId(resourceRequest)); AssetPublisherCustomizer assetPublisherCustomizer = assetPublisherCustomizerRegistry .getAssetPublisherCustomizer(rootPortletId); resourceRequest.setAttribute(AssetPublisherWebKeys.ASSET_PUBLISHER_CUSTOMIZER, assetPublisherCustomizer); resourceRequest.setAttribute(AssetPublisherWebKeys.ASSET_PUBLISHER_WEB_UTIL, assetPublisherWebUtil); byte[] bytes = AssetRSSUtil.getRSS(resourceRequest, resourceResponse); outputStream.write(bytes); } catch (Exception e) { _log.error("Unable to get RSS feed", e); } }
From source file:com.liferay.asset.publisher.web.portlet.AssetPublisherPortlet.java
License:Open Source License
@Override protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { try {//from w ww .j ava2 s . c om renderRequest.setAttribute(AssetPublisherWebKeys.ASSET_ENTRY_ACTION_REGISTRY, assetEntryActionRegistry); renderRequest.setAttribute(AssetWebKeys.ASSET_HELPER, assetHelper); String rootPortletId = PortletIdCodec.decodePortletName(portal.getPortletId(renderRequest)); AssetPublisherCustomizer assetPublisherCustomizer = assetPublisherCustomizerRegistry .getAssetPublisherCustomizer(rootPortletId); renderRequest.setAttribute(AssetPublisherWebKeys.ASSET_PUBLISHER_CUSTOMIZER, assetPublisherCustomizer); renderRequest.setAttribute(AssetPublisherWebKeys.ASSET_PUBLISHER_WEB_CONFIGURATION, assetPublisherWebConfiguration); ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); AssetPublisherPortletInstanceConfiguration assetPublisherPortletInstanceConfiguration = portletDisplay .getPortletInstanceConfiguration(AssetPublisherPortletInstanceConfiguration.class); renderRequest.setAttribute(AssetPublisherWebKeys.ASSET_PUBLISHER_PORTLET_INSTANCE_CONFIGURATION, assetPublisherPortletInstanceConfiguration); renderRequest.setAttribute(WebKeys.SINGLE_PAGE_APPLICATION_CLEAR_CACHE, Boolean.TRUE); } catch (Exception e) { _log.error("Unable to get asset publisher customizer", e); } if (SessionErrors.contains(renderRequest, NoSuchGroupException.class.getName()) || SessionErrors.contains(renderRequest, PrincipalException.getNestedClasses())) { include("/error.jsp", renderRequest, renderResponse); } else { super.doDispatch(renderRequest, renderResponse); } }
From source file:com.liferay.asset.publisher.web.servlet.taglib.ui.ScopeFormNavigatorEntry.java
License:Open Source License
@Override public boolean isVisible(User user, Object object) { if (!isDynamicAssetSelection()) { return true; }/*from w w w. j av a 2s. c o m*/ ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); ThemeDisplay themeDisplay = serviceContext.getThemeDisplay(); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); String rootPortletId = PortletIdCodec.decodePortletName(portletDisplay.getPortletName()); if (rootPortletId.equals(AssetPublisherPortletKeys.RELATED_ASSETS)) { return false; } return true; }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
public static void addAndStoreSelection(PortletRequest portletRequest, String className, long classPK, int assetEntryOrder) throws Exception { String portletId = PortalUtil.getPortletId(portletRequest); String rootPortletId = PortletIdCodec.decodePortletName(portletId); if (!rootPortletId.equals(AssetPublisherPortletKeys.ASSET_PUBLISHER)) { return;/* w ww .ja v a 2 s . co m*/ } ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, portletId); if (portletPreferences instanceof StrictPortletPreferencesImpl) { return; } String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic"); if (selectionStyle.equals("dynamic")) { return; } AssetEntry assetEntry = _assetEntryLocalService.getEntry(className, classPK); addSelection(themeDisplay, portletPreferences, portletId, assetEntry.getEntryId(), assetEntryOrder, className); portletPreferences.store(); }
From source file:com.liferay.contacts.web.internal.portlet.ContactsCenterPortlet.java
License:Open Source License
public void requestSocialRelation(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long[] userIds = getUserIds(actionRequest); int type = ParamUtil.getInteger(actionRequest, "type"); for (long userId : userIds) { if (userId == themeDisplay.getUserId()) { continue; }/*from ww w . j av a 2 s . c o m*/ if (socialRelationLocalService.hasRelation(userId, themeDisplay.getUserId(), SocialRelationConstants.TYPE_BI_CONNECTION) || socialRelationLocalService.hasRelation(userId, themeDisplay.getUserId(), SocialRelationConstants.TYPE_UNI_ENEMY) || socialRequestLocalService.hasRequest(themeDisplay.getUserId(), User.class.getName(), themeDisplay.getUserId(), type, userId, SocialRequestConstants.STATUS_PENDING)) { continue; } JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); String portletId = portal.getPortletId(actionRequest); extraDataJSONObject.put("portletId", PortletIdCodec.decodePortletName(portletId)); SocialRequest socialRequest = socialRequestLocalService.addRequest(themeDisplay.getUserId(), 0, User.class.getName(), themeDisplay.getUserId(), type, extraDataJSONObject.toString(), userId); sendNotificationEvent(socialRequest); } }
From source file:com.liferay.exportimport.controller.PortletImportController.java
License:Open Source License
public void importPortletPreferences(PortletDataContext portletDataContext, long companyId, long groupId, Layout layout, Element parentElement, boolean preserveScopeLayoutId, boolean importPortletArchivedSetups, boolean importPortletData, boolean importPortletSetup, boolean importPortletUserPreferences) throws Exception { long plid = LayoutConstants.DEFAULT_PLID; String scopeType = StringPool.BLANK; String scopeLayoutUuid = StringPool.BLANK; if (layout != null) { plid = layout.getPlid();//from w ww . ja v a 2 s .c o m if (preserveScopeLayoutId) { javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil .getLayoutPortletSetup(layout, portletDataContext.getPortletId()); scopeType = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeType", null)); scopeLayoutUuid = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeLayoutUuid", null)); portletDataContext.setScopeType(scopeType); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); } } List<Element> portletPreferencesElements = parentElement.elements("portlet-preferences"); for (Element portletPreferencesElement : portletPreferencesElements) { String path = portletPreferencesElement.attributeValue("path"); if (portletDataContext.isPathNotProcessed(path)) { String xml = null; Element element = null; try { xml = portletDataContext.getZipEntryAsString(path); Document preferencesDocument = SAXReaderUtil.read(xml); element = preferencesDocument.getRootElement(); } catch (DocumentException de) { throw new SystemException( "Unable to parse XML portlet preferences for portlet " + portletDataContext.getPortletId() + " while importing portlet preferences", de); } long ownerId = GetterUtil.getLong(element.attributeValue("owner-id")); int ownerType = GetterUtil.getInteger(element.attributeValue("owner-type")); if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_COMPANY) || !importPortletSetup) { continue; } if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) && !importPortletArchivedSetups) { continue; } if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_USER) && (ownerId != PortletKeys.PREFS_OWNER_ID_DEFAULT) && !importPortletUserPreferences) { continue; } long curPlid = plid; String curPortletId = portletDataContext.getPortletId(); if (ownerType == PortletKeys.PREFS_OWNER_TYPE_GROUP) { curPlid = PortletKeys.PREFS_PLID_SHARED; curPortletId = portletDataContext.getRootPortletId(); ownerId = portletDataContext.getScopeGroupId(); } long elementPlid = GetterUtil.getLong(element.attributeValue("plid")); if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_LAYOUT) && (ownerId != PortletKeys.PREFS_OWNER_ID_DEFAULT) && (elementPlid == PortletKeys.PREFS_PLID_SHARED)) { curPlid = PortletKeys.PREFS_PLID_SHARED; ownerId = portletDataContext.getScopeGroupId(); } if (ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) { String userUuid = element.attributeValue("archive-user-uuid"); long userId = portletDataContext.getUserId(userUuid); String name = element.attributeValue("archive-name"); curPortletId = portletDataContext.getRootPortletId(); PortletItem portletItem = _portletItemLocalService.updatePortletItem(userId, groupId, name, curPortletId, PortletPreferences.class.getName()); curPlid = LayoutConstants.DEFAULT_PLID; ownerId = portletItem.getPortletItemId(); } if (ownerType == PortletKeys.PREFS_OWNER_TYPE_USER) { String userUuid = element.attributeValue("user-uuid"); ownerId = portletDataContext.getUserId(userUuid); } boolean defaultUser = GetterUtil.getBoolean(element.attributeValue("default-user")); if (defaultUser) { ownerId = _userLocalService.getDefaultUserId(companyId); } javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil .fromXML(companyId, ownerId, ownerType, curPlid, curPortletId, xml); Element importDataRootElement = portletDataContext.getImportDataRootElement(); try { Element preferenceDataElement = portletPreferencesElement.element("preference-data"); if (preferenceDataElement != null) { portletDataContext.setImportDataRootElement(preferenceDataElement); } ExportImportPortletPreferencesProcessor exportImportPortletPreferencesProcessor = ExportImportPortletPreferencesProcessorRegistryUtil .getExportImportPortletPreferencesProcessor( PortletIdCodec.decodePortletName(curPortletId)); if (exportImportPortletPreferencesProcessor != null) { List<Capability> importCapabilities = exportImportPortletPreferencesProcessor .getImportCapabilities(); if (ListUtil.isNotEmpty(importCapabilities)) { for (Capability importCapability : importCapabilities) { importCapability.process(portletDataContext, jxPortletPreferences); } } exportImportPortletPreferencesProcessor.processImportPortletPreferences(portletDataContext, jxPortletPreferences); } else { PortletDataHandler portletDataHandler = _portletDataHandlerProvider .provide(portletDataContext.getCompanyId(), curPortletId); if (portletDataHandler != null) { jxPortletPreferences = portletDataHandler.processImportPortletPreferences( portletDataContext, curPortletId, jxPortletPreferences); } } } finally { portletDataContext.setImportDataRootElement(importDataRootElement); } updatePortletPreferences(portletDataContext, ownerId, ownerType, curPlid, curPortletId, PortletPreferencesFactoryUtil.toXML(jxPortletPreferences), importPortletData); } } if (preserveScopeLayoutId && (layout != null)) { javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil .getLayoutPortletSetup(layout, portletDataContext.getPortletId()); try { jxPortletPreferences.setValue("lfrScopeType", scopeType); jxPortletPreferences.setValue("lfrScopeLayoutUuid", scopeLayoutUuid); jxPortletPreferences.store(); } finally { portletDataContext.setScopeType(scopeType); portletDataContext.setScopeLayoutUuid(scopeLayoutUuid); } } }
From source file:com.liferay.exportimport.controller.PortletImportController.java
License:Open Source License
protected void validateFile(long companyId, long groupId, String portletId, ZipReader zipReader) throws Exception { // XML/* w ww . j a v a 2s. c o m*/ String xml = zipReader.getEntryAsString("/manifest.xml"); if (xml == null) { throw new LARFileException(LARFileException.TYPE_MISSING_MANIFEST); } Element rootElement = null; try { Document document = SAXReaderUtil.read(xml); rootElement = document.getRootElement(); } catch (Exception e) { throw new LARFileException(LARFileException.TYPE_INVALID_MANIFEST, e); } // Build compatibility Element headerElement = rootElement.element("header"); Element portletElement = rootElement.element("portlet"); int importBuildNumber = GetterUtil.getInteger(headerElement.attributeValue("build-number")); if (importBuildNumber < ReleaseInfo.RELEASE_7_0_0_BUILD_NUMBER) { int buildNumber = ReleaseInfo.getBuildNumber(); throw new LayoutImportException(LayoutImportException.TYPE_WRONG_BUILD_NUMBER, new Object[] { importBuildNumber, buildNumber }); } else { BiPredicate<Version, Version> majorVersionBiPredicate = (currentVersion, importVersion) -> Objects .equals(currentVersion.getMajor(), importVersion.getMajor()); BiPredicate<Version, Version> minorVersionBiPredicate = (currentVersion, importVersion) -> { int currentMinorVersion = GetterUtil.getInteger(currentVersion.getMinor(), -1); int importedMinorVersion = GetterUtil.getInteger(importVersion.getMinor(), -1); if (((currentMinorVersion == -1) && (importedMinorVersion == -1)) || (currentMinorVersion < importedMinorVersion)) { return false; } return true; }; BiPredicate<Version, Version> manifestVersionBiPredicate = (currentVersion, importVersion) -> { BiPredicate<Version, Version> versionBiPredicate = majorVersionBiPredicate .and(minorVersionBiPredicate); return versionBiPredicate.test(currentVersion, importVersion); }; String importSchemaVersion = GetterUtil.getString(headerElement.attributeValue("schema-version"), "1.0.0"); if (!manifestVersionBiPredicate.test( Version.getInstance(ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION), Version.getInstance(importSchemaVersion))) { throw new LayoutImportException(LayoutImportException.TYPE_WRONG_LAR_SCHEMA_VERSION, new Object[] { importSchemaVersion, ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION }); } } // Type String larType = headerElement.attributeValue("type"); if (!larType.equals("portlet")) { throw new LARTypeException(larType, new String[] { "portlet" }); } // Portlet compatibility String rootPortletId = headerElement.attributeValue("root-portlet-id"); String expectedRootPortletId = PortletIdCodec.decodePortletName(portletId); if (!expectedRootPortletId.equals(rootPortletId)) { throw new PortletIdException(expectedRootPortletId); } String schemaVersion = GetterUtil.getString(portletElement.attributeValue("schema-version"), "1.0.0"); PortletDataHandler portletDataHandler = _portletDataHandlerProvider.provide(companyId, portletId); if (!portletDataHandler.validateSchemaVersion(schemaVersion)) { throw new LayoutImportException(LayoutImportException.TYPE_WRONG_PORTLET_SCHEMA_VERSION, new Object[] { schemaVersion, portletId, portletDataHandler.getSchemaVersion() }); } // Available locales if (portletDataHandler.isDataLocalized()) { List<Locale> sourceAvailableLocales = Arrays.asList(LocaleUtil .fromLanguageIds(StringUtil.split(headerElement.attributeValue("available-locales")))); for (Locale sourceAvailableLocale : sourceAvailableLocales) { if (!LanguageUtil.isAvailableLocale(_portal.getSiteGroupId(groupId), sourceAvailableLocale)) { LocaleException le = new LocaleException(LocaleException.TYPE_EXPORT_IMPORT); le.setSourceAvailableLocales(sourceAvailableLocales); le.setTargetAvailableLocales(LanguageUtil.getAvailableLocales(_portal.getSiteGroupId(groupId))); throw le; } } } }