1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.pagecomments.lar;
21  
22  import com.liferay.portal.kernel.util.GetterUtil;
23  import com.liferay.portal.lar.PortletDataContext;
24  import com.liferay.portal.lar.PortletDataException;
25  import com.liferay.portal.lar.PortletDataHandler;
26  import com.liferay.portal.lar.PortletDataHandlerBoolean;
27  import com.liferay.portal.lar.PortletDataHandlerControl;
28  import com.liferay.portal.model.Layout;
29  import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
30  
31  import javax.portlet.PortletPreferences;
32  
33  /**
34   * <a href="PageCommentsPortletDataHandlerImpl.java.html"><b><i>View Source</i>
35   * </b></a>
36   *
37   * @author Bruno Farache
38   *
39   */
40  public class PageCommentsPortletDataHandlerImpl implements PortletDataHandler {
41  
42      public PortletPreferences deleteData(
43              PortletDataContext context, String portletId,
44              PortletPreferences prefs)
45          throws PortletDataException {
46  
47          try {
48              MBMessageLocalServiceUtil.deleteDiscussionMessages(
49                  Layout.class.getName(), context.getPlid());
50  
51              return null;
52          }
53          catch (Exception e) {
54              throw new PortletDataException(e);
55          }
56      }
57  
58      public String exportData(
59              PortletDataContext context, String portletId,
60              PortletPreferences prefs)
61          throws PortletDataException {
62  
63          try {
64              context.addComments(Layout.class, new Long(context.getPlid()));
65  
66              return String.valueOf(context.getPlid());
67          }
68          catch (Exception e) {
69              throw new PortletDataException(e);
70          }
71      }
72  
73      public PortletDataHandlerControl[] getExportControls() {
74          return new PortletDataHandlerControl[] {_comments};
75      }
76  
77      public PortletDataHandlerControl[] getImportControls() {
78          return new PortletDataHandlerControl[] {_comments};
79      }
80  
81      public PortletPreferences importData(
82              PortletDataContext context, String portletId,
83              PortletPreferences prefs, String data)
84          throws PortletDataException {
85  
86          try {
87              context.importComments(
88                  Layout.class, GetterUtil.getLong(data), context.getPlid(),
89                  context.getGroupId());
90  
91              return null;
92          }
93          catch (Exception e) {
94              throw new PortletDataException(e);
95          }
96      }
97  
98      public boolean isPublishToLiveByDefault() {
99          return false;
100     }
101 
102     private static final String _NAMESPACE = "page_comments";
103 
104     private static final PortletDataHandlerBoolean _comments =
105         new PortletDataHandlerBoolean(_NAMESPACE, "comments", true, true);
106 
107 }