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.kernel.upgrade;
016    
017    import com.liferay.portal.kernel.util.TextFormatter;
018    import com.liferay.portlet.PortletPreferencesFactoryUtil;
019    
020    import java.util.Map;
021    
022    import javax.portlet.PortletPreferences;
023    
024    /**
025     * @author Julio Camarero
026     */
027    public class CamelCaseUpgradePortletPreferences
028            extends BaseUpgradePortletPreferences {
029    
030            @Override
031            protected String upgradePreferences(
032                            long companyId, long ownerId, int ownerType, long plid,
033                            String portletId, String xml)
034                    throws Exception {
035    
036                    PortletPreferences portletPreferences =
037                            PortletPreferencesFactoryUtil.fromXML(
038                                    companyId, ownerId, ownerType, plid, portletId, xml);
039    
040                    Map<String, String[]> preferencesMap = portletPreferences.getMap();
041    
042                    for (String oldName : preferencesMap.keySet()) {
043                            String[] values = preferencesMap.get(oldName);
044    
045                            String newName = TextFormatter.format(oldName, TextFormatter.M);
046    
047                            portletPreferences.reset(oldName);
048    
049                            portletPreferences.setValues(newName, values);
050                    }
051    
052                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
053            }
054    
055    }