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.v6_2_0;
016    
017    import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.kernel.util.RSSUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portlet.PortletPreferencesFactoryUtil;
022    
023    import javax.portlet.PortletPreferences;
024    
025    /**
026     * @author Eduardo Garcia
027     * @author Jorge Ferrer
028     */
029    public class UpgradeAssetPublisher extends BaseUpgradePortletPreferences {
030    
031            @Override
032            protected String[] getPortletIds() {
033                    return new String[] {"101_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                    upgradeRss(portletPreferences);
047                    upgradeScopeIds(portletPreferences);
048    
049                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
050            }
051    
052            protected void upgradeRss(PortletPreferences portletPreferences)
053                    throws Exception {
054    
055                    String rssFormat = GetterUtil.getString(
056                            portletPreferences.getValue("rssFormat", null));
057    
058                    if (Validator.isNotNull(rssFormat)) {
059                            portletPreferences.setValue(
060                                    "rssFeedType",
061                                    RSSUtil.getFeedType(
062                                            RSSUtil.getFormatType(rssFormat),
063                                            RSSUtil.getFormatVersion(rssFormat)));
064                    }
065    
066                    portletPreferences.reset("rssFormat");
067            }
068    
069            protected void upgradeScopeIds(PortletPreferences portletPreferences)
070                    throws Exception {
071    
072                    String defaultScope = GetterUtil.getString(
073                            portletPreferences.getValue("defaultScope", null));
074    
075                    if (Validator.isNull(defaultScope)) {
076                            return;
077                    }
078    
079                    if (defaultScope.equals("true")) {
080                            portletPreferences.setValues(
081                                    "scopeIds", new String[] {"Group_default"});
082                    }
083                    else if (!defaultScope.equals("false")) {
084                            portletPreferences.setValues(
085                                    "scopeIds", new String[] {defaultScope});
086                    }
087    
088                    portletPreferences.reset("defaultScope");
089            }
090    
091    }