UpgradePortletId extends BaseUpgradePortletId { protected String getNewTypeSettings( String typeSettings, String oldRootPortletId) { UnicodeProperties typeSettingsUnicodeProperties = new UnicodeProperties( true); typeSettingsUnicodeProperties.fastLoad(typeSettings); Set<String> keys = typeSettingsUnicodeProperties.keySet(); Iterator<String> iterator = keys.iterator(); while (iterator.hasNext()) { String key = iterator.next(); if (StringUtil.startsWith( key, LayoutTypePortletConstants.COLUMN_PREFIX) || StringUtil.startsWith( key, LayoutTypePortletConstants.NESTED_COLUMN_IDS)) { String[] portletIds = StringUtil.split( typeSettingsUnicodeProperties.getProperty(key)); if (!ArrayUtil.contains(portletIds, oldRootPortletId)) { continue; } if (portletIds.length > 1) { portletIds = ArrayUtil.remove(portletIds, oldRootPortletId); String mergedPortletIds = StringUtil.merge(portletIds); typeSettingsUnicodeProperties.setProperty( key, mergedPortletIds.concat(StringPool.COMMA)); } else { iterator.remove(); } } } return typeSettingsUnicodeProperties.toString(); }    }
@Test public void testOldTypeSettingsShouldBeUpdate1() { String oldTypeSettings = "column-1=1_WAR_kaleoformsportlet,\ncolumn-2=" + _PORTLET_KEY; String newTypeSettings = _upgradePortletId.getNewTypeSettings( oldTypeSettings, "1_WAR_kaleoformsportlet"); String expectedTypeSettings = "column-2=" + _PORTLET_KEY + "\n"; Assert.assertEquals(expectedTypeSettings, newTypeSettings); }
@Test public void testOldTypeSettingsShouldBeUpdate2() { String oldTypeSettings = "column-1=" + _PORTLET_KEY + ",\ncolumn-2=1_WAR_kaleoformsportlet"; String newTypeSettings = _upgradePortletId.getNewTypeSettings( oldTypeSettings, "1_WAR_kaleoformsportlet"); String expectedTypeSettings = "column-1=" + _PORTLET_KEY + ",\n"; Assert.assertEquals(expectedTypeSettings, newTypeSettings); }