1
14
15 package com.liferay.portlet.pageratings.lar;
16
17 import com.liferay.portal.kernel.util.GetterUtil;
18 import com.liferay.portal.lar.BasePortletDataHandler;
19 import com.liferay.portal.lar.PortletDataContext;
20 import com.liferay.portal.lar.PortletDataException;
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.ratings.service.RatingsStatsLocalServiceUtil;
25
26 import javax.portlet.PortletPreferences;
27
28
34 public class PageRatingsPortletDataHandlerImpl extends BasePortletDataHandler {
35
36 public PortletPreferences deleteData(
37 PortletDataContext context, String portletId,
38 PortletPreferences preferences)
39 throws PortletDataException {
40
41 try {
42 RatingsStatsLocalServiceUtil.deleteStats(
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 preferences)
55 throws PortletDataException {
56
57 try {
58 context.addRatingsEntries(
59 Layout.class, new Long(context.getPlid()));
60
61 return String.valueOf(context.getPlid());
62 }
63 catch (Exception e) {
64 throw new PortletDataException(e);
65 }
66 }
67
68 public PortletDataHandlerControl[] getExportControls() {
69 return new PortletDataHandlerControl[] {_ratings};
70 }
71
72 public PortletDataHandlerControl[] getImportControls() {
73 return new PortletDataHandlerControl[] {_ratings};
74 }
75
76 public PortletPreferences importData(
77 PortletDataContext context, String portletId,
78 PortletPreferences preferences, String data)
79 throws PortletDataException {
80
81 try {
82 context.importRatingsEntries(
83 Layout.class, GetterUtil.getLong(data),
84 new Long(context.getPlid()));
85
86 return null;
87 }
88 catch (Exception e) {
89 throw new PortletDataException(e);
90 }
91 }
92
93 private static final String _NAMESPACE = "page_ratings";
94
95 private static final PortletDataHandlerBoolean _ratings =
96 new PortletDataHandlerBoolean(_NAMESPACE, "ratings", true, true);
97
98 }