001    /**
002     * Copyright (c) 2000-2010 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.util.GetterUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.upgrade.BaseUpgradePortletPreferences;
020    import com.liferay.portlet.PortletPreferencesImpl;
021    import com.liferay.portlet.PortletPreferencesSerializer;
022    
023    /**
024     * @author Jorge Ferrer
025     * @author Brian Wing Shun Chan
026     */
027    public class UpgradeSitemap extends BaseUpgradePortletPreferences {
028    
029            protected String getUpdatePortletPreferencesWhereClause() {
030                    return "portletId like '85_%'";
031            }
032    
033            protected String upgradePreferences(
034                            long companyId, long ownerId, int ownerType, long plid,
035                            String portletId, String xml)
036                    throws Exception {
037    
038                    PortletPreferencesImpl preferences =
039                            PortletPreferencesSerializer.fromXML(
040                                    companyId, ownerId, ownerType, plid, portletId, xml);
041    
042                    long rootPlid = GetterUtil.getLong(
043                            preferences.getValue("root-plid", StringPool.BLANK));
044    
045                    if (rootPlid > 0) {
046                            Object[] layout = getLayout(rootPlid);
047    
048                            if (layout != null) {
049                                    long layoutId = (Long)layout[3];
050    
051                                    preferences.setValue(
052                                            "root-layout-id", String.valueOf(layoutId));
053                            }
054                    }
055    
056                    preferences.setValue("root-plid", null);
057    
058                    return PortletPreferencesSerializer.toXML(preferences);
059            }
060    
061    }