001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }