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_2_0;
016    
017    import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences;
018    import com.liferay.portlet.PortletPreferencesFactoryUtil;
019    
020    import java.util.HashMap;
021    import java.util.Map;
022    
023    import javax.portlet.PortletPreferences;
024    
025    /**
026     * @author Marcellus Tavares
027     */
028    public class UpgradeDynamicDataListDisplay
029            extends BaseUpgradePortletPreferences {
030    
031            public UpgradeDynamicDataListDisplay() {
032                    _preferencesMap.put("detailDDMTemplateId", "formDDMTemplateId");
033                    _preferencesMap.put("listDDMTemplateId", "displayDDMTemplateId");
034            }
035    
036            @Override
037            protected String[] getPortletIds() {
038                    return new String[] {"169_INSTANCE_%"};
039            }
040    
041            @Override
042            protected String upgradePreferences(
043                            long companyId, long ownerId, int ownerType, long plid,
044                            String portletId, String xml)
045                    throws Exception {
046    
047                    PortletPreferences preferences =
048                            PortletPreferencesFactoryUtil.fromXML(
049                                    companyId, ownerId, ownerType, plid, portletId, xml);
050    
051                    Map<String, String[]> preferencesMap = preferences.getMap();
052    
053                    for (String name : _preferencesMap.keySet()) {
054                            String[] values = preferencesMap.get(name);
055    
056                            if (values == null) {
057                                    continue;
058                            }
059    
060                            preferences.reset(name);
061    
062                            preferences.setValues(_preferencesMap.get(name), values);
063                    }
064    
065                    return PortletPreferencesFactoryUtil.toXML(preferences);
066            }
067    
068            private Map<String, String> _preferencesMap = new HashMap<String, String>();
069    
070    }