/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.site.navigation.menu.web.internal.upgrade.v1_0_0; import com.liferay.portal.kernel.portlet.PortletPreferencesFactoryUtil; import com.liferay.portal.kernel.portletdisplaytemplate.PortletDisplayTemplateManager; import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.Validator; import com.liferay.site.navigation.menu.web.internal.constants.SiteNavigationMenuPortletKeys; import javax.portlet.PortletPreferences; import javax.portlet.ReadOnlyException; /** * @author Eduardo Garcia */ public class UpgradePortletPreferences extends BaseUpgradePortletPreferences { @Override protected String[] getPortletIds() { return new String[] { SiteNavigationMenuPortletKeys.SITE_NAVIGATION_MENU }; } protected void upgradeDisplayStyle(PortletPreferences portletPreferences) throws ReadOnlyException { String displayStyle = GetterUtil.getString( portletPreferences.getValue("displayStyle", null)); if (Validator.isNull(displayStyle) || displayStyle.startsWith( PortletDisplayTemplateManager.DISPLAY_STYLE_PREFIX)) { return; } portletPreferences.setValue( "displayStyle", PortletDisplayTemplateManager.DISPLAY_STYLE_PREFIX + "list-menu-ftl"); // Extract old "navigation.display.options" as portlet preferences if (displayStyle.equals("from-level-0")) { _upgradeDisplayStylePreferences( portletPreferences, "absolute", "0", "auto"); } else if (displayStyle.equals("from-level-1") || displayStyle.equals("from-level-1-with-title")) { _upgradeDisplayStylePreferences( portletPreferences, "absolute", "1", "auto"); } else if (displayStyle.equals("from-level-1-to-all-sublevels")) { _upgradeDisplayStylePreferences( portletPreferences, "absolute", "1", "all"); } else if (displayStyle.equals("from-level-2-with-title")) { _upgradeDisplayStylePreferences( portletPreferences, "absolute", "2", "auto"); } else if (displayStyle.equals("relative-with-breadcrumb")) { _upgradeDisplayStylePreferences( portletPreferences, "relative", "0", "auto"); } // Remove unsupported preferences portletPreferences.reset("bulletStyle"); portletPreferences.reset("headerType"); portletPreferences.reset("nestedChildren"); } @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); upgradeDisplayStyle(portletPreferences); return PortletPreferencesFactoryUtil.toXML(portletPreferences); } private void _upgradeDisplayStylePreferences( PortletPreferences portletPreferences, String includedLayouts, String rootLayoutLevel, String rootLayoutType) throws ReadOnlyException { portletPreferences.setValue("includedLayouts", includedLayouts); portletPreferences.setValue("rootLayoutLevel", rootLayoutLevel); portletPreferences.setValue("rootLayoutType", rootLayoutType); } }