001    /**
002     * Copyright (c) 2000-2012 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 Julio Camarero
026     */
027    public class UpgradeNavigation extends BaseUpgradePortletPreferences {
028    
029            @Override
030            protected String[] getPortletIds() {
031                    return new String[] {"71_INSTANCE_%"};
032            }
033    
034            @Override
035            protected String upgradePreferences(
036                            long companyId, long ownerId, int ownerType, long plid,
037                            String portletId, String xml)
038                    throws Exception {
039    
040                    PortletPreferences portletPreferences =
041                            PortletPreferencesFactoryUtil.fromXML(
042                                    companyId, ownerId, ownerType, plid, portletId, xml);
043    
044                    String displayStyle = portletPreferences.getValue(
045                            "display-style", null);
046    
047                    if (Validator.isNumber(displayStyle)) {
048                            int index = GetterUtil.getInteger(displayStyle);
049    
050                            if ((index < 0) || (index > 6)) {
051                                    index = 0;
052                            }
053    
054                            portletPreferences.setValue(
055                                    "display-style", _DISPLAY_STYLES[index]);
056                    }
057    
058                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
059            }
060    
061            private static final String[] _DISPLAY_STYLES = {
062                    "", "relative-with-breadcrumb", "from-level-2-with-title",
063                    "from-level-1-with-title", "from-level-1",
064                    "from-level-1-to-all-sublevels", "from-level-0"
065            };
066    
067    }