1
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
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 }