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.portlet.pagecomments.lar;
016    
017    import com.liferay.portal.kernel.lar.BasePortletDataHandler;
018    import com.liferay.portal.kernel.lar.PortletDataContext;
019    import com.liferay.portal.kernel.lar.PortletDataHandlerBoolean;
020    import com.liferay.portal.kernel.lar.PortletDataHandlerControl;
021    import com.liferay.portal.kernel.util.GetterUtil;
022    import com.liferay.portal.model.Layout;
023    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
024    
025    import javax.portlet.PortletPreferences;
026    
027    /**
028     * @author Bruno Farache
029     */
030    public class PageCommentsPortletDataHandlerImpl extends BasePortletDataHandler {
031    
032            @Override
033            public PortletDataHandlerControl[] getExportControls() {
034                    return new PortletDataHandlerControl[] {_comments};
035            }
036    
037            @Override
038            public PortletDataHandlerControl[] getImportControls() {
039                    return new PortletDataHandlerControl[] {_comments};
040            }
041    
042            @Override
043            protected PortletPreferences doDeleteData(
044                            PortletDataContext portletDataContext, String portletId,
045                            PortletPreferences portletPreferences)
046                    throws Exception {
047    
048                    MBMessageLocalServiceUtil.deleteDiscussionMessages(
049                            Layout.class.getName(), portletDataContext.getPlid());
050    
051                    return null;
052            }
053    
054            @Override
055            protected String doExportData(
056                            PortletDataContext portletDataContext, String portletId,
057                            PortletPreferences portletPreferences)
058                    throws Exception {
059    
060                    if (portletDataContext.getBooleanParameter(_NAMESPACE, "comments")) {
061                            portletDataContext.addComments(
062                                    Layout.class, portletDataContext.getPlid());
063                    }
064    
065                    return String.valueOf(portletDataContext.getPlid());
066            }
067    
068            @Override
069            protected PortletPreferences doImportData(
070                            PortletDataContext portletDataContext, String portletId,
071                            PortletPreferences portletPreferences, String data)
072                    throws Exception {
073    
074                    portletDataContext.importComments(
075                            Layout.class, GetterUtil.getLong(data),
076                            portletDataContext.getPlid(), portletDataContext.getScopeGroupId());
077    
078                    return null;
079            }
080    
081            private static final String _NAMESPACE = "page_comments";
082    
083            private static PortletDataHandlerBoolean _comments =
084                    new PortletDataHandlerBoolean(_NAMESPACE, "comments", true, true);
085    
086    }