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