1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.pagecomments.lar;
24  
25  import com.liferay.portal.kernel.util.GetterUtil;
26  import com.liferay.portal.lar.BasePortletDataHandler;
27  import com.liferay.portal.lar.PortletDataContext;
28  import com.liferay.portal.lar.PortletDataException;
29  import com.liferay.portal.lar.PortletDataHandlerBoolean;
30  import com.liferay.portal.lar.PortletDataHandlerControl;
31  import com.liferay.portal.model.Layout;
32  import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
33  
34  import javax.portlet.PortletPreferences;
35  
36  /**
37   * <a href="PageCommentsPortletDataHandlerImpl.java.html"><b><i>View Source</i>
38   * </b></a>
39   *
40   * @author Bruno Farache
41   *
42   */
43  public class PageCommentsPortletDataHandlerImpl extends BasePortletDataHandler {
44  
45      public PortletPreferences deleteData(
46              PortletDataContext context, String portletId,
47              PortletPreferences preferences)
48          throws PortletDataException {
49  
50          try {
51              MBMessageLocalServiceUtil.deleteDiscussionMessages(
52                  Layout.class.getName(), context.getPlid());
53  
54              return null;
55          }
56          catch (Exception e) {
57              throw new PortletDataException(e);
58          }
59      }
60  
61      public String exportData(
62              PortletDataContext context, String portletId,
63              PortletPreferences preferences)
64          throws PortletDataException {
65  
66          try {
67              context.addComments(Layout.class, new Long(context.getPlid()));
68  
69              return String.valueOf(context.getPlid());
70          }
71          catch (Exception e) {
72              throw new PortletDataException(e);
73          }
74      }
75  
76      public PortletDataHandlerControl[] getExportControls() {
77          return new PortletDataHandlerControl[] {_comments};
78      }
79  
80      public PortletDataHandlerControl[] getImportControls() {
81          return new PortletDataHandlerControl[] {_comments};
82      }
83  
84      public PortletPreferences importData(
85              PortletDataContext context, String portletId,
86              PortletPreferences preferences, String data)
87          throws PortletDataException {
88  
89          try {
90              context.importComments(
91                  Layout.class, GetterUtil.getLong(data), context.getPlid(),
92                  context.getGroupId());
93  
94              return null;
95          }
96          catch (Exception e) {
97              throw new PortletDataException(e);
98          }
99      }
100 
101     private static final String _NAMESPACE = "page_comments";
102 
103     private static final PortletDataHandlerBoolean _comments =
104         new PortletDataHandlerBoolean(_NAMESPACE, "comments", true, true);
105 
106 }