1
22
23 package com.liferay.portlet.pageratings.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.ratings.service.RatingsStatsLocalServiceUtil;
33
34 import javax.portlet.PortletPreferences;
35
36
43 public class PageRatingsPortletDataHandlerImpl extends BasePortletDataHandler {
44
45 public PortletPreferences deleteData(
46 PortletDataContext context, String portletId,
47 PortletPreferences preferences)
48 throws PortletDataException {
49
50 try {
51 RatingsStatsLocalServiceUtil.deleteStats(
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.addRatingsEntries(
68 Layout.class, new Long(context.getPlid()));
69
70 return String.valueOf(context.getPlid());
71 }
72 catch (Exception e) {
73 throw new PortletDataException(e);
74 }
75 }
76
77 public PortletDataHandlerControl[] getExportControls() {
78 return new PortletDataHandlerControl[] {_ratings};
79 }
80
81 public PortletDataHandlerControl[] getImportControls() {
82 return new PortletDataHandlerControl[] {_ratings};
83 }
84
85 public PortletPreferences importData(
86 PortletDataContext context, String portletId,
87 PortletPreferences preferences, String data)
88 throws PortletDataException {
89
90 try {
91 context.importRatingsEntries(
92 Layout.class, GetterUtil.getLong(data),
93 new Long(context.getPlid()));
94
95 return null;
96 }
97 catch (Exception e) {
98 throw new PortletDataException(e);
99 }
100 }
101
102 private static final String _NAMESPACE = "page_ratings";
103
104 private static final PortletDataHandlerBoolean _ratings =
105 new PortletDataHandlerBoolean(_NAMESPACE, "ratings", true, true);
106
107 }