List of usage examples for com.liferay.portal.kernel.portlet PortletPreferencesFactoryUtil toXML
public static String toXML(PortletPreferences portletPreferences)
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 www.ja va2 s . c om 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 www . j a va 2 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);/*from w w w . j a v a 2 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 . ja v a2 s . c o 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);/*from www . ja va 2 s . c o m*/ 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);// ww w .j ava 2s .c om _replaceClassNameId(portletPreferences, "anyAssetType"); _replaceClassNameId(portletPreferences, "classNameIds"); return PortletPreferencesFactoryUtil.toXML(portletPreferences); }
From source file:com.liferay.exportimport.controller.PortletExportController.java
License:Open Source License
protected void exportPortletPreference(PortletDataContext portletDataContext, long ownerId, int ownerType, boolean defaultUser, PortletPreferences portletPreferences, String portletId, long plid, Element parentElement) throws Exception { String preferencesXML = portletPreferences.getPreferences(); if (Validator.isNull(preferencesXML)) { preferencesXML = PortletConstants.DEFAULT_PREFERENCES; }//from w w w. j a v a 2 s . co m javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil .fromDefaultXML(preferencesXML); Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletId); Element portletPreferencesElement = parentElement.addElement("portlet-preferences"); if ((portlet != null) && (portlet.getPortletDataHandlerInstance() != null)) { Element exportDataRootElement = portletDataContext.getExportDataRootElement(); try { portletDataContext.clearScopedPrimaryKeys(); Element preferenceDataElement = portletPreferencesElement.addElement("preference-data"); portletDataContext.setExportDataRootElement(preferenceDataElement); ExportImportPortletPreferencesProcessor exportImportPortletPreferencesProcessor = ExportImportPortletPreferencesProcessorRegistryUtil .getExportImportPortletPreferencesProcessor(portlet.getRootPortletId()); if (exportImportPortletPreferencesProcessor != null) { List<Capability> exportCapabilities = exportImportPortletPreferencesProcessor .getExportCapabilities(); if (ListUtil.isNotEmpty(exportCapabilities)) { for (Capability exportCapability : exportCapabilities) { exportCapability.process(portletDataContext, jxPortletPreferences); } } exportImportPortletPreferencesProcessor.processExportPortletPreferences(portletDataContext, jxPortletPreferences); } else { PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance(); jxPortletPreferences = portletDataHandler.processExportPortletPreferences(portletDataContext, portletId, jxPortletPreferences); } } finally { portletDataContext.setExportDataRootElement(exportDataRootElement); } } Document document = SAXReaderUtil.read(PortletPreferencesFactoryUtil.toXML(jxPortletPreferences)); Element rootElement = document.getRootElement(); rootElement.addAttribute("owner-id", String.valueOf(ownerId)); rootElement.addAttribute("owner-type", String.valueOf(ownerType)); rootElement.addAttribute("default-user", String.valueOf(defaultUser)); rootElement.addAttribute("plid", String.valueOf(plid)); rootElement.addAttribute("portlet-id", portletId); if (ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) { PortletItem portletItem = _portletItemLocalService.getPortletItem(ownerId); rootElement.addAttribute("archive-user-uuid", portletItem.getUserUuid()); rootElement.addAttribute("archive-name", portletItem.getName()); } else if (ownerType == PortletKeys.PREFS_OWNER_TYPE_USER) { User user = _userLocalService.fetchUserById(ownerId); if (user == null) { return; } rootElement.addAttribute("user-uuid", user.getUserUuid()); } List<Node> nodes = document .selectNodes("/portlet-preferences/preference[name/text() = " + "'last-publish-date']"); for (Node node : nodes) { node.detach(); } String path = ExportImportPathUtil.getPortletPreferencesPath(portletDataContext, portletId, ownerId, ownerType, plid); portletPreferencesElement.addAttribute("path", path); portletDataContext.addZipEntry(path, document.formattedString(StringPool.TAB, false, false)); }
From source file:com.liferay.exportimport.controller.PortletExportController.java
License:Open Source License
protected void exportServicePortletPreference(PortletDataContext portletDataContext, long ownerId, int ownerType, PortletPreferences portletPreferences, String serviceName, Element parentElement) throws Exception { String preferencesXML = portletPreferences.getPreferences(); if (Validator.isNull(preferencesXML)) { preferencesXML = PortletConstants.DEFAULT_PREFERENCES; }//from ww w . j a va 2 s . c o m javax.portlet.PortletPreferences jxPortletPreferences = PortletPreferencesFactoryUtil .fromDefaultXML(preferencesXML); Document document = SAXReaderUtil.read(PortletPreferencesFactoryUtil.toXML(jxPortletPreferences)); Element rootElement = document.getRootElement(); rootElement.addAttribute("owner-id", String.valueOf(ownerId)); rootElement.addAttribute("owner-type", String.valueOf(ownerType)); rootElement.addAttribute("default-user", String.valueOf(false)); rootElement.addAttribute("service-name", serviceName); if (ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) { PortletItem portletItem = _portletItemLocalService.getPortletItem(ownerId); rootElement.addAttribute("archive-user-uuid", portletItem.getUserUuid()); rootElement.addAttribute("archive-name", portletItem.getName()); } else if (ownerType == PortletKeys.PREFS_OWNER_TYPE_USER) { User user = _userLocalService.fetchUserById(ownerId); if (user == null) { return; } rootElement.addAttribute("user-uuid", user.getUserUuid()); } List<Node> nodes = document .selectNodes("/portlet-preferences/preference[name/text() = " + "'last-publish-date']"); for (Node node : nodes) { node.detach(); } Element serviceElement = parentElement.addElement("service"); String path = ExportImportPathUtil.getServicePortletPreferencesPath(portletDataContext, serviceName, ownerId, ownerType); serviceElement.addAttribute("path", path); serviceElement.addAttribute("service-name", serviceName); portletDataContext.addZipEntry(path, document.formattedString()); }
From source file:com.liferay.exportimport.controller.PortletImportController.java
License:Open Source License
public String importPortletData(PortletDataContext portletDataContext, javax.portlet.PortletPreferences portletPreferences, Element portletDataElement) throws Exception { PortletDataHandler portletDataHandler = _portletDataHandlerProvider .provide(portletDataContext.getCompanyId(), portletDataContext.getPortletId()); if ((portletDataHandler == null) || portletDataHandler.isDataPortletInstanceLevel()) { if (_log.isDebugEnabled()) { StringBundler sb = new StringBundler(4); sb.append("Do not import portlet data for portlet "); sb.append(portletDataContext.getPortletId()); sb.append(" because the portlet does not have a portlet data "); sb.append("handler"); _log.debug(sb.toString());/* w w w .j av a 2s .c om*/ } return null; } if (_log.isDebugEnabled()) { _log.debug("Importing data for portlet " + portletDataContext.getPortletId()); } String portletData = portletDataContext.getZipEntryAsString(portletDataElement.attributeValue("path")); if (Validator.isNull(portletData)) { return null; } portletPreferences = portletDataHandler.importData(portletDataContext, portletDataContext.getPortletId(), portletPreferences, portletData); if (portletPreferences == null) { return null; } 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();//from ww w .jav a 2s.c om 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); } } }