1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.pagecomments.lar;
16  
17  import com.liferay.portal.kernel.util.GetterUtil;
18  import com.liferay.portal.lar.BasePortletDataHandler;
19  import com.liferay.portal.lar.PortletDataContext;
20  import com.liferay.portal.lar.PortletDataException;
21  import com.liferay.portal.lar.PortletDataHandlerBoolean;
22  import com.liferay.portal.lar.PortletDataHandlerControl;
23  import com.liferay.portal.model.Layout;
24  import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
25  
26  import javax.portlet.PortletPreferences;
27  
28  /**
29   * <a href="PageCommentsPortletDataHandlerImpl.java.html"><b><i>View Source</i>
30   * </b></a>
31   *
32   * @author Bruno Farache
33   */
34  public class PageCommentsPortletDataHandlerImpl extends BasePortletDataHandler {
35  
36      public PortletPreferences deleteData(
37              PortletDataContext context, String portletId,
38              PortletPreferences preferences)
39          throws PortletDataException {
40  
41          try {
42              MBMessageLocalServiceUtil.deleteDiscussionMessages(
43                  Layout.class.getName(), context.getPlid());
44  
45              return null;
46          }
47          catch (Exception e) {
48              throw new PortletDataException(e);
49          }
50      }
51  
52      public String exportData(
53              PortletDataContext context, String portletId,
54              PortletPreferences preferences)
55          throws PortletDataException {
56  
57          try {
58              context.addComments(Layout.class, new Long(context.getPlid()));
59  
60              return String.valueOf(context.getPlid());
61          }
62          catch (Exception e) {
63              throw new PortletDataException(e);
64          }
65      }
66  
67      public PortletDataHandlerControl[] getExportControls() {
68          return new PortletDataHandlerControl[] {_comments};
69      }
70  
71      public PortletDataHandlerControl[] getImportControls() {
72          return new PortletDataHandlerControl[] {_comments};
73      }
74  
75      public PortletPreferences importData(
76              PortletDataContext context, String portletId,
77              PortletPreferences preferences, String data)
78          throws PortletDataException {
79  
80          try {
81              context.importComments(
82                  Layout.class, GetterUtil.getLong(data), context.getPlid(),
83                  context.getGroupId());
84  
85              return null;
86          }
87          catch (Exception e) {
88              throw new PortletDataException(e);
89          }
90      }
91  
92      private static final String _NAMESPACE = "page_comments";
93  
94      private static final PortletDataHandlerBoolean _comments =
95          new PortletDataHandlerBoolean(_NAMESPACE, "comments", true, true);
96  
97  }