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_1_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.Validator;
020    import com.liferay.portlet.PortletPreferencesFactoryUtil;
021    
022    import javax.portlet.PortletPreferences;
023    
024    /**
025     * @author Tamas Molnar
026     */
027    public class UpgradeIFrame extends BaseUpgradePortletPreferences {
028    
029            @Override
030            protected String[] getPortletIds() {
031                    return new String[] {"48_INSTANCE_%"};
032            }
033    
034            protected void upgradePassword(PortletPreferences portletPreferences)
035                    throws Exception {
036    
037                    String password = GetterUtil.getString(
038                            portletPreferences.getValue("password", null));
039    
040                    if (Validator.isNotNull(password)) {
041                            portletPreferences.setValue("formPassword", password);
042                    }
043    
044                    portletPreferences.reset("password");
045            }
046    
047            @Override
048            protected String upgradePreferences(
049                            long companyId, long ownerId, int ownerType, long plid,
050                            String portletId, String xml)
051                    throws Exception {
052    
053                    PortletPreferences portletPreferences =
054                            PortletPreferencesFactoryUtil.fromXML(
055                                    companyId, ownerId, ownerType, plid, portletId, xml);
056    
057                    upgradePassword(portletPreferences);
058                    upgradeUserName(portletPreferences);
059    
060                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
061            }
062    
063            protected void upgradeUserName(PortletPreferences portletPreferences)
064                    throws Exception {
065    
066                    String userName = GetterUtil.getString(
067                            portletPreferences.getValue("userName", null));
068    
069                    if (Validator.isNull(userName)) {
070                            userName = GetterUtil.getString(
071                                    portletPreferences.getValue("user-name", null));
072                    }
073    
074                    if (Validator.isNotNull(userName)) {
075                            portletPreferences.setValue("formUserName", userName);
076                    }
077    
078                    portletPreferences.reset("user-name");
079                    portletPreferences.reset("userName");
080            }
081    
082    }