001    /**
002     * Copyright (c) 2000-2013 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.StringPool;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portlet.PortletPreferencesFactoryUtil;
022    
023    import javax.portlet.PortletPreferences;
024    
025    /**
026     * @author Roberto D??az
027     */
028    public class UpgradeWiki extends BaseUpgradePortletPreferences {
029    
030            @Override
031            protected void doUpgrade() throws Exception {
032                    super.doUpgrade();
033            }
034    
035            @Override
036            protected String[] getPortletIds() {
037                    return new String[] {"36"};
038            }
039    
040            @Override
041            protected String upgradePreferences(
042                            long companyId, long ownerId, int ownerType, long plid,
043                            String portletId, String xml)
044                    throws Exception {
045    
046                    PortletPreferences portletPreferences =
047                            PortletPreferencesFactoryUtil.fromXML(
048                                    companyId, ownerId, ownerType, plid, portletId, xml);
049    
050                    portletPreferences = upgradeSubscriptionSubject(
051                            "emailPageAddedSubject", "emailPageAddedSubjectPrefix",
052                            portletPreferences);
053    
054                    portletPreferences = upgradeSubscriptionSubject(
055                            "emailPageUpdatedSubject", "emailPageUpdatedSubjectPrefix",
056                            portletPreferences);
057    
058                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
059            }
060    
061            protected PortletPreferences upgradeSubscriptionSubject(
062                            String subjectName, String subjectPrefixName,
063                            PortletPreferences portletPreferences)
064                    throws Exception {
065    
066                    String subjectPrefix = GetterUtil.getString(
067                            portletPreferences.getValue(subjectPrefixName, StringPool.BLANK));
068    
069                    if (Validator.isNotNull(subjectPrefix)) {
070                            String subject = subjectPrefix;
071    
072                            if (!subjectPrefix.contains("[$PAGE_TITLE$]")) {
073                                    subject = subject.concat(" [$PAGE_TITLE$]");
074                            }
075    
076                            portletPreferences.setValue(subjectName, subject);
077                    }
078    
079                    portletPreferences.reset(subjectPrefixName);
080    
081                    return portletPreferences;
082            }
083    
084    }