List of usage examples for com.liferay.portal.kernel.portlet PortletPreferencesFactoryUtil fromXML
public static PortletPreferences fromXML(long companyId, long ownerId, int ownerType, long plid, String portletId, String xml)
From source file:com.liferay.asset.publisher.web.internal.messaging.AssetEntriesCheckerUtil.java
License:Open Source License
private void _checkAssetEntries(com.liferay.portal.kernel.model.PortletPreferences portletPreferencesModel) throws PortalException { Layout layout = _layoutLocalService.fetchLayout(portletPreferencesModel.getPlid()); if (layout == null) { return;//from www . j ava 2s . c o m } PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromXML(layout.getCompanyId(), portletPreferencesModel.getOwnerId(), portletPreferencesModel.getOwnerType(), portletPreferencesModel.getPlid(), portletPreferencesModel.getPortletId(), portletPreferencesModel.getPreferences()); if (!_assetPublisherWebUtil.getEmailAssetEntryAddedEnabled(portletPreferences)) { return; } List<AssetEntry> assetEntries = _getAssetEntries(portletPreferences, layout); if (assetEntries.isEmpty()) { return; } long[] notifiedAssetEntryIds = GetterUtil .getLongValues(portletPreferences.getValues("notifiedAssetEntryIds", null)); ArrayList<AssetEntry> newAssetEntries = new ArrayList<>(); for (AssetEntry assetEntry : assetEntries) { if (!ArrayUtil.contains(notifiedAssetEntryIds, assetEntry.getEntryId())) { newAssetEntries.add(assetEntry); } } List<Subscription> subscriptions = _subscriptionLocalService.getSubscriptions( portletPreferencesModel.getCompanyId(), com.liferay.portal.kernel.model.PortletPreferences.class.getName(), _assetPublisherWebUtil.getSubscriptionClassPK(portletPreferencesModel.getPlid(), portletPreferencesModel.getPortletId())); _notifySubscribers(subscriptions, portletPreferences, newAssetEntries); try { portletPreferences.setValues("notifiedAssetEntryIds", StringUtil.split(ListUtil.toString(assetEntries, AssetEntry.ENTRY_ID_ACCESSOR))); portletPreferences.store(); } catch (IOException | PortletException e) { throw new PortalException(e); } }
From source file:com.liferay.asset.publisher.web.upgrade.v1_0_0.UpgradePortletPreferences.java
License:Open Source License
@Override protected String upgradePreferences(long companyId, long ownerId, int ownerType, long plid, String portletId, String xml) throws Exception { PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);/*from w w w . j av a 2 s.c o m*/ String[] assetEntryXmls = portletPreferences.getValues("asset-entry-xml", new String[0]); if (ArrayUtil.isNotEmpty(assetEntryXmls)) { upgradeUuids(assetEntryXmls); portletPreferences.setValues("assetEntryXml", assetEntryXmls); } boolean subtypeFieldsFilterEnabled = GetterUtil .getBoolean(portletPreferences.getValue("subtypeFieldsFilterEnabled", Boolean.FALSE.toString())); if (subtypeFieldsFilterEnabled) { boolean dlFilterByFieldEnable = isFilterByFieldEnable(portletPreferences, _DL_FILTER_BY_FIELD_ENABLED_KEY); boolean journalFilterByFieldEnable = isFilterByFieldEnable(portletPreferences, _JOURNAL_FILTER_BY_FIELD_ENABLED_KEY); if (dlFilterByFieldEnable) { upgradeDLDateFieldsValues(portletPreferences); } else if (journalFilterByFieldEnable) { upgradeJournalDateFieldValue(portletPreferences); } upgradeOrderByColumns(portletPreferences); } return PortletPreferencesFactoryUtil.toXML(portletPreferences); }
From source file:com.liferay.asset.publisher.web.upgrade.v1_1_0.UpgradePortletPreferences.java
License:Open Source License
@Override protected String upgradePreferences(long companyId, long ownerId, int ownerType, long plid, String portletId, String xml) throws Exception { PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);/*from w w w .j av a2 s. c o m*/ String enableSocialBookmarks = portletPreferences.getValue("enableSocialBookmarks", Boolean.TRUE.toString()); if (!enableSocialBookmarks.equals(Boolean.TRUE.toString())) { portletPreferences.setValue("socialBookmarksTypes", StringPool.BLANK); } portletPreferences.reset("enableSocialBookmarks"); portletPreferences.reset("socialBookmarksDisplayPosition"); return PortletPreferencesFactoryUtil.toXML(portletPreferences); }
From source file:com.liferay.blogs.web.internal.upgrade.v1_0_0.UpgradePortletPreferences.java
License:Open Source License
@Override protected String upgradePreferences(long companyId, long ownerId, int ownerType, long plid, String portletId, String xml) throws Exception { PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);//ww w . j a va2 s.c o m portletPreferences.setValue("enableViewCount", "true"); return PortletPreferencesFactoryUtil.toXML(portletPreferences); }
From source file:com.liferay.bookmarks.web.internal.upgrade.v1_0_0.UpgradePortletPreferences.java
License:Open Source License
@Override protected String upgradePreferences(long companyId, long ownerId, int ownerType, long plid, String portletId, String xml) throws Exception { PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);/*from w ww. j ava 2 s . co m*/ upgradeMultiValuePreference(portletPreferences, "entryColumns"); upgradeMultiValuePreference(portletPreferences, "folderColumns"); return PortletPreferencesFactoryUtil.toXML(portletPreferences); }
From source file:com.liferay.calendar.web.internal.upgrade.v1_0_0.UpgradePortletPreferences.java
License:Open Source License
@Override protected String upgradePreferences(long companyId, long ownerId, int ownerType, long plid, String portletId, String xml) throws Exception { PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);//w w w.j a v a2s . c om String isoTimeFormat = portletPreferences.getValue("isoTimeFormat", Boolean.FALSE.toString()); if (isoTimeFormat.equals(Boolean.TRUE.toString())) { portletPreferences.setValue("timeFormat", "24-hour"); } else { portletPreferences.setValue("timeFormat", "am-pm"); } portletPreferences.reset("isoTimeFormat"); return PortletPreferencesFactoryUtil.toXML(portletPreferences); }
From source file:com.liferay.calendar.web.internal.upgrade.v1_0_1.UpgradePortletPreferences.java
License:Open Source License
@Override protected String upgradePreferences(long companyId, long ownerId, int ownerType, long plid, String portletId, String xml) throws Exception { PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);// w w w . ja v a 2 s . c o m _replaceClassNameId(portletPreferences, "anyAssetType"); _replaceClassNameId(portletPreferences, "classNameIds"); return PortletPreferencesFactoryUtil.toXML(portletPreferences); }
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();//w w w .j ava 2 s .com 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 updatePortletPreferences(PortletDataContext portletDataContext, long ownerId, int ownerType, long plid, String portletId, String xml, boolean importData) throws Exception { PortletDataHandler portletDataHandler = _portletDataHandlerProvider .provide(portletDataContext.getCompanyId(), portletId); // Current portlet preferences javax.portlet.PortletPreferences portletPreferences = _portletPreferencesLocalService .getPreferences(portletDataContext.getCompanyId(), ownerId, ownerType, plid, portletId); // New portlet preferences javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil .fromXML(portletDataContext.getCompanyId(), ownerId, ownerType, plid, portletId, xml); if (importData || !MergeLayoutPrototypesThreadLocal.isInProgress()) { String currentLastPublishDate = portletPreferences.getValue("last-publish-date", null); String newLastPublishDate = jxPortletPreferences.getValue("last-publish-date", null); if (Validator.isNotNull(currentLastPublishDate)) { jxPortletPreferences.setValue("last-publish-date", currentLastPublishDate); } else if (Validator.isNotNull(newLastPublishDate)) { jxPortletPreferences.reset("last-publish-date"); }/*from w w w. j a v a 2s. c o m*/ _portletPreferencesLocalService.updatePreferences(ownerId, ownerType, plid, portletId, PortletPreferencesFactoryUtil.toXML(jxPortletPreferences)); return; } // Portlet preferences will be updated only when importing data String[] dataPortletPreferences = portletDataHandler.getDataPortletPreferences(); Enumeration<String> enu = jxPortletPreferences.getNames(); while (enu.hasMoreElements()) { String name = enu.nextElement(); String scopeLayoutUuid = portletDataContext.getScopeLayoutUuid(); String scopeType = portletDataContext.getScopeType(); if (!ArrayUtil.contains(dataPortletPreferences, name) || (Validator.isNull(scopeLayoutUuid) && scopeType.equals("company"))) { String[] values = jxPortletPreferences.getValues(name, null); portletPreferences.setValues(name, values); } } _portletPreferencesLocalService.updatePreferences(ownerId, ownerType, plid, portletId, portletPreferences); }
From source file:com.liferay.journal.content.web.internal.upgrade.v1_0_0.UpgradePortletPreferences.java
License:Open Source License
@Override protected String upgradePreferences(long companyId, long ownerId, int ownerType, long plid, String portletId, String xml) throws Exception { PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);/*w w w. j av a2s. c o m*/ upgradeContentMetadataAssetAddonEntryKeys(portletPreferences); upgradeUserToolAssetAddonEntryKeys(portletPreferences); return PortletPreferencesFactoryUtil.toXML(portletPreferences); }