001
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
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 }