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.v5_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.StringPool;
020    import com.liferay.portlet.PortletPreferencesFactoryUtil;
021    
022    import javax.portlet.PortletPreferences;
023    
024    /**
025     * @author Jorge Ferrer
026     * @author Brian Wing Shun Chan
027     */
028    public class UpgradeSitemap extends BaseUpgradePortletPreferences {
029    
030            @Override
031            protected String[] getPortletIds() {
032                    return new String[] {"85_INSTANCE_%"};
033            }
034    
035            @Override
036            protected String upgradePreferences(
037                            long companyId, long ownerId, int ownerType, long plid,
038                            String portletId, String xml)
039                    throws Exception {
040    
041                    PortletPreferences portletPreferences =
042                            PortletPreferencesFactoryUtil.fromXML(
043                                    companyId, ownerId, ownerType, plid, portletId, xml);
044    
045                    long rootPlid = GetterUtil.getLong(
046                            portletPreferences.getValue("root-plid", StringPool.BLANK));
047    
048                    if (rootPlid > 0) {
049                            Object[] layout = getLayout(rootPlid);
050    
051                            if (layout != null) {
052                                    long layoutId = (Long)layout[3];
053    
054                                    portletPreferences.setValue(
055                                            "root-layout-id", String.valueOf(layoutId));
056                            }
057                    }
058    
059                    portletPreferences.setValue("root-plid", null);
060    
061                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
062            }
063    
064    }