1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.calendar.social;
16  
17  import com.liferay.portal.kernel.util.HtmlUtil;
18  import com.liferay.portal.kernel.util.StringPool;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.security.permission.PermissionChecker;
22  import com.liferay.portal.theme.ThemeDisplay;
23  import com.liferay.portlet.calendar.model.CalEvent;
24  import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
25  import com.liferay.portlet.calendar.service.permission.CalEventPermission;
26  import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
27  import com.liferay.portlet.social.model.SocialActivity;
28  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
29  
30  /**
31   * <a href="CalendarActivityInterpreter.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   * @author Ryan Park
35   */
36  public class CalendarActivityInterpreter extends BaseSocialActivityInterpreter {
37  
38      public String[] getClassNames() {
39          return _CLASS_NAMES;
40      }
41  
42      protected SocialActivityFeedEntry doInterpret(
43              SocialActivity activity, ThemeDisplay themeDisplay)
44          throws Exception {
45  
46          PermissionChecker permissionChecker =
47              themeDisplay.getPermissionChecker();
48  
49          if (!CalEventPermission.contains(
50                  permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
51  
52              return null;
53          }
54  
55          String groupName = StringPool.BLANK;
56  
57          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
58              groupName = getGroupName(activity.getGroupId(), themeDisplay);
59          }
60  
61          String creatorUserName = getUserName(
62              activity.getUserId(), themeDisplay);
63  
64          int activityType = activity.getType();
65  
66          // Link
67  
68          CalEvent event = CalEventLocalServiceUtil.getEvent(
69              activity.getClassPK());
70  
71          String link =
72              themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
73                  "/calendar/find_event?redirect=" +
74                      HtmlUtil.escapeURL(themeDisplay.getURLCurrent()) +
75                          "&eventId=" + activity.getClassPK();
76  
77          // Title
78  
79          String titlePattern = null;
80  
81          if (activityType == CalendarActivityKeys.ADD_EVENT) {
82              titlePattern = "activity-calendar-add-event";
83          }
84          else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
85              titlePattern = "activity-calendar-update-event";
86          }
87  
88          if (Validator.isNotNull(groupName)) {
89              titlePattern += "-in";
90          }
91  
92          String eventTitle = wrapLink(
93              link, HtmlUtil.escape(cleanContent(event.getTitle())));
94  
95          Object[] titleArguments = new Object[] {
96              groupName, creatorUserName, eventTitle
97          };
98  
99          String title = themeDisplay.translate(titlePattern, titleArguments);
100 
101         // Body
102 
103         String body = StringPool.BLANK;
104 
105         return new SocialActivityFeedEntry(link, title, body);
106     }
107 
108     private static final String[] _CLASS_NAMES = new String[] {
109         CalEvent.class.getName()
110     };
111 
112 }