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.v7_0_0;
016    
017    import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.util.PortletKeys;
020    import com.liferay.portlet.PortletPreferencesFactoryUtil;
021    import com.liferay.taglib.ui.LanguageTag;
022    
023    import javax.portlet.PortletPreferences;
024    import javax.portlet.ReadOnlyException;
025    
026    /**
027     * @author Eduardo Garcia
028     */
029    public class UpgradeLanguagePreferences extends BaseUpgradePortletPreferences {
030    
031            @Override
032            protected String[] getPortletIds() {
033                    return new String[] {PortletKeys.LANGUAGE};
034            }
035    
036            @SuppressWarnings("deprecation")
037            protected void upgradeDisplayStyle(PortletPreferences portletPreferences)
038                    throws ReadOnlyException {
039    
040                    int displayStyle = GetterUtil.getInteger(
041                            portletPreferences.getValue("displayStyle", null),
042                            LanguageTag.LIST_ICON);
043    
044                    if (displayStyle == LanguageTag.LIST_LONG_TEXT) {
045                            portletPreferences.setValue("displayStyle", "long-text");
046                    }
047                    else if (displayStyle == LanguageTag.LIST_SHORT_TEXT) {
048                            portletPreferences.setValue("displayStyle", "short-text");
049                    }
050                    else if (displayStyle == LanguageTag.SELECT_BOX) {
051                            portletPreferences.setValue("displayStyle", "select-box");
052                    }
053                    else {
054                            portletPreferences.setValue("displayStyle", "icon");
055                    }
056            }
057    
058            @Override
059            protected String upgradePreferences(
060                            long companyId, long ownerId, int ownerType, long plid,
061                            String portletId, String xml)
062                    throws Exception {
063    
064                    PortletPreferences portletPreferences =
065                            PortletPreferencesFactoryUtil.fromXML(
066                                    companyId, ownerId, ownerType, plid, portletId, xml);
067    
068                    upgradeDisplayStyle(portletPreferences);
069    
070                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
071            }
072    
073    }