List of usage examples for com.liferay.portal.kernel.xml Node detach
public Node detach();
From source file:com.beorn.onlinepayment.messaging.messageprocessor.RegisterMessageProcessor.java
License:Open Source License
private void rewriteConfigurationForLocalization(Node configParametersNode) { if (configParametersNode == null) return;/*from w w w. j a v a 2s . com*/ List<Node> localizableNodes = configParametersNode .selectNodes("group/name | group/parameter/name | group/parameter/helpMessage"); for (Node localizableNode : localizableNodes) { Map<Locale, String> localizationMap = getLocalizationMap(localizableNode); String xml = StringPool.BLANK; for (Entry<Locale, String> localizationMapEntry : localizationMap.entrySet()) { String key = localizableNode.getName(); String value = localizationMapEntry.getValue(); Locale locale = localizationMapEntry.getKey(); String requestedLanguageId = LocaleUtil.toLanguageId(locale); xml = LocalizationUtil.updateLocalization(xml, key, value, requestedLanguageId); } for (Node childNode : localizableNode.selectNodes("*")) childNode.detach(); localizableNode.setText(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 w w. jav a2 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 w w w . ja v a 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()); }