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.PortletDataContext;
19  import com.liferay.portal.lar.PortletDataException;
20  import com.liferay.portal.lar.PortletDataHandler;
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 implements PortletDataHandler {
35  
36      public PortletPreferences deleteData(
37              PortletDataContext context, String portletId,
38              PortletPreferences prefs)
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 prefs)
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 prefs, 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      public boolean isPublishToLiveByDefault() {
93          return false;
94      }
95  
96      private static final String _NAMESPACE = "page_comments";
97  
98      private static final PortletDataHandlerBoolean _comments =
99          new PortletDataHandlerBoolean(_NAMESPACE, "comments", true, true);
100 
101 }