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