001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.upgrade.v7_0_0;
016    
017    import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences;
018    import com.liferay.portal.kernel.util.ArrayUtil;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.util.StringUtil;
021    import com.liferay.portlet.PortletPreferencesFactoryUtil;
022    
023    import javax.portlet.PortletPreferences;
024    
025    /**
026     * @author Eudaldo Alonso
027     */
028    public class UpgradeJournalDisplayPreferences
029            extends BaseUpgradePortletPreferences {
030    
031            @Override
032            protected String[] getPortletIds() {
033                    return new String[] {"56_INSTANCE_%"};
034            }
035    
036            @Override
037            protected String upgradePreferences(
038                            long companyId, long ownerId, int ownerType, long plid,
039                            String portletId, String xml)
040                    throws Exception {
041    
042                    PortletPreferences portletPreferences =
043                            PortletPreferencesFactoryUtil.fromXML(
044                                    companyId, ownerId, ownerType, plid, portletId, xml);
045    
046                    String[] extensions = portletPreferences.getValues(
047                            "extensions", StringPool.EMPTY_ARRAY);
048    
049                    if (ArrayUtil.isNotEmpty(extensions)) {
050                            portletPreferences.setValue(
051                                    "extensions", StringUtil.merge(extensions));
052                    }
053    
054                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
055            }
056    
057    }