001    /**
002     * Copyright (c) 2000-2010 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            public PortletDataHandlerControl[] getExportControls() {
033                    return new PortletDataHandlerControl[] {_comments};
034            }
035    
036            public PortletDataHandlerControl[] getImportControls() {
037                    return new PortletDataHandlerControl[] {_comments};
038            }
039    
040            protected PortletPreferences doDeleteData(
041                            PortletDataContext context, String portletId,
042                            PortletPreferences preferences)
043                    throws Exception {
044    
045                    MBMessageLocalServiceUtil.deleteDiscussionMessages(
046                            Layout.class.getName(), context.getPlid());
047    
048                    return null;
049            }
050    
051            protected String doExportData(
052                            PortletDataContext context, String portletId,
053                            PortletPreferences preferences)
054                    throws Exception {
055    
056                    context.addComments(Layout.class, context.getPlid());
057    
058                    return String.valueOf(context.getPlid());
059            }
060    
061            protected PortletPreferences doImportData(
062                            PortletDataContext context, String portletId,
063                            PortletPreferences preferences, String data)
064                    throws Exception {
065    
066                    context.importComments(
067                            Layout.class, GetterUtil.getLong(data), context.getPlid(),
068                            context.getScopeGroupId());
069    
070                    return null;
071            }
072    
073            private static final String _NAMESPACE = "page_comments";
074    
075            private static PortletDataHandlerBoolean _comments =
076                    new PortletDataHandlerBoolean(_NAMESPACE, "comments", true, true);
077    
078    }