1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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              if (context.getBooleanParameter(_NAMESPACE, "comments")) {
59                  context.addComments(Layout.class, new Long(context.getPlid()));
60              }
61  
62              return String.valueOf(context.getPlid());
63          }
64          catch (Exception e) {
65              throw new PortletDataException(e);
66          }
67      }
68  
69      public PortletDataHandlerControl[] getExportControls() {
70          return new PortletDataHandlerControl[] {_comments};
71      }
72  
73      public PortletDataHandlerControl[] getImportControls() {
74          return new PortletDataHandlerControl[] {_comments};
75      }
76  
77      public PortletPreferences importData(
78              PortletDataContext context, String portletId,
79              PortletPreferences preferences, String data)
80          throws PortletDataException {
81  
82          try {
83              context.importComments(
84                  Layout.class, GetterUtil.getLong(data), context.getPlid(),
85                  context.getScopeGroupId());
86  
87              return null;
88          }
89          catch (Exception e) {
90              throw new PortletDataException(e);
91          }
92      }
93  
94      private static final String _NAMESPACE = "page_comments";
95  
96      private static final PortletDataHandlerBoolean _comments =
97          new PortletDataHandlerBoolean(_NAMESPACE, "comments", true, true);
98  
99  }