1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
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  /**
29   * <a href="PageRatingsPortletDataHandlerImpl.java.html"><b><i>View Source</i>
30   * </b></a>
31   *
32   * @author Bruno Farache
33   */
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  }