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.upgrade.v5_2_0;
016    
017    import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.StringUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portlet.PortletPreferencesFactoryUtil;
022    
023    import javax.portlet.PortletPreferences;
024    
025    /**
026     * @author Samuel Kong
027     * @author Brian Wing Shun Chan
028     * @author Edward Shin
029     */
030    public class UpgradeDocumentLibrary extends BaseUpgradePortletPreferences {
031    
032            @Override
033            protected String[] getPortletIds() {
034                    return new String[] {"20"};
035            }
036    
037            @Override
038            protected String upgradePreferences(
039                            long companyId, long ownerId, int ownerType, long plid,
040                            String portletId, String xml)
041                    throws Exception {
042    
043                    PortletPreferences portletPreferences =
044                            PortletPreferencesFactoryUtil.fromXML(
045                                    companyId, ownerId, ownerType, plid, portletId, xml);
046    
047                    String fileEntryColumns = portletPreferences.getValue(
048                            "fileEntryColumns", StringPool.BLANK);
049    
050                    if (Validator.isNotNull(fileEntryColumns)) {
051                            fileEntryColumns = StringUtil.replace(
052                                    fileEntryColumns, "document", "name");
053    
054                            portletPreferences.setValue("fileEntryColumns", fileEntryColumns);
055                    }
056    
057                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
058            }
059    
060    }