List of usage examples for com.liferay.portal.kernel.portlet PortletPreferencesFactoryUtil fromDefaultXML
public static PortletPreferences fromDefaultXML(String xml)
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 ww.j a va 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; }/* 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
/** * @deprecated As of 4.0.0, replaced by {@link * #importPortletData(PortletDataContext portletDataContext, * javax.portlet.PortletPreferences portletPreferences, Element * portletDataElement)}//from w ww . j av a 2s . c o m */ @Deprecated public String importPortletData(PortletDataContext portletDataContext, PortletPreferences portletPreferences, Element portletDataElement) throws Exception { PortletPreferencesImpl portletPreferencesImpl = null; if (portletPreferences != null) { portletPreferencesImpl = (PortletPreferencesImpl) PortletPreferencesFactoryUtil .fromDefaultXML(portletPreferences.getPreferences()); } return importPortletData(portletDataContext, portletPreferencesImpl, portletDataElement); }
From source file:com.liferay.exportimport.controller.PortletImportController.java
License:Open Source License
/** * @deprecated As of 4.0.0, replaced by {@link * deletePortletData(PortletDataContext portletDataContext, * javax.portlet.PortletPreferences portletPreferences)} */// ww w .java 2 s.c o m @Deprecated protected String deletePortletData(PortletDataContext portletDataContext, PortletPreferences portletPreferences) throws Exception { javax.portlet.PortletPreferences portletPreferencesImpl = PortletPreferencesFactoryUtil .fromDefaultXML(portletPreferences.getPreferences()); return deletePortletData(portletDataContext, portletPreferencesImpl); }
From source file:com.liferay.journal.internal.upgrade.v0_0_5.UpgradeJournalArticles.java
License:Open Source License
protected String getNewPreferences(long plid, String preferences) throws Exception { PortletPreferences oldPortletPreferences = PortletPreferencesFactoryUtil.fromDefaultXML(preferences); String ddmStructureKey = oldPortletPreferences.getValue("ddmStructureKey", StringPool.BLANK); long groupId = GetterUtil.getLong(oldPortletPreferences.getValue("groupId", StringPool.BLANK)); String orderByCol = oldPortletPreferences.getValue("orderByCol", StringPool.BLANK); String orderByType = oldPortletPreferences.getValue("orderByType", StringPool.BLANK); int pageDelta = GetterUtil.getInteger(oldPortletPreferences.getValue("pageDelta", StringPool.BLANK)); String pageUrl = oldPortletPreferences.getValue("pageUrl", StringPool.BLANK); String type = oldPortletPreferences.getValue("type", StringPool.BLANK); PortletPreferences newPortletPreferences = new PortletPreferencesImpl(); newPortletPreferences.setValue("anyAssetType", String.valueOf(PortalUtil.getClassNameId(JournalArticle.class.getName()))); Layout layout = _layoutLocalService.getLayout(plid); long structureId = getStructureId(layout.getCompanyId(), layout.getGroupId(), ddmStructureKey); if (structureId > 0) { newPortletPreferences.setValue("anyClassTypeJournalArticleAssetRendererFactory", String.valueOf(structureId)); }//from w w w .j ava 2 s . c o m String assetLinkBehavior = "showFullContent"; if (pageUrl.equals("viewInContext")) { assetLinkBehavior = "viewInPortlet"; } newPortletPreferences.setValue("assetLinkBehavior", assetLinkBehavior); if (structureId > 0) { newPortletPreferences.setValue("classTypeIds", String.valueOf(structureId)); } newPortletPreferences.setValue("delta", String.valueOf(pageDelta)); newPortletPreferences.setValue("displayStyle", "table"); newPortletPreferences.setValue("metadataFields", "publish-date,author"); newPortletPreferences.setValue("orderByColumn1", orderByCol); newPortletPreferences.setValue("orderByType1", orderByType); newPortletPreferences.setValue("paginationType", "none"); long categoryId = getCategoryId(layout.getCompanyId(), type); if (categoryId > 0) { newPortletPreferences.setValue("queryAndOperator0", Boolean.TRUE.toString()); newPortletPreferences.setValue("queryContains0", Boolean.TRUE.toString()); newPortletPreferences.setValue("queryName0", "assetCategories"); newPortletPreferences.setValue("queryValues0", String.valueOf(categoryId)); } newPortletPreferences.setValue("showAddContentButton", Boolean.FALSE.toString()); String groupName = String.valueOf(groupId); if (groupId == layout.getGroupId()) { groupName = "default"; } newPortletPreferences.setValue("scopeIds", "Group_" + groupName); return PortletPreferencesFactoryUtil.toXML(newPortletPreferences); }
From source file:com.liferay.journal.verify.JournalServiceVerifyProcess.java
License:Open Source License
protected void updateContentSearch(long groupId, String portletId) throws Exception { try (PreparedStatement ps = connection .prepareStatement("select preferences from PortletPreferences inner join " + "Layout on PortletPreferences.plid = Layout.plid where " + "groupId = ? and portletId = ?")) { ps.setLong(1, groupId);//from www. j av a2 s. c om ps.setString(2, portletId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { String xml = rs.getString("preferences"); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromDefaultXML(xml); String articleId = portletPreferences.getValue("articleId", null); List<JournalContentSearch> contentSearches = _journalContentSearchLocalService .getArticleContentSearches(groupId, articleId); if (contentSearches.isEmpty()) { continue; } JournalContentSearch contentSearch = contentSearches.get(0); _journalContentSearchLocalService.updateContentSearch(contentSearch.getGroupId(), contentSearch.isPrivateLayout(), contentSearch.getLayoutId(), contentSearch.getPortletId(), articleId, true); } } } }