1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.calendar.social;
24  
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.kernel.util.Validator;
27  import com.liferay.portal.model.Group;
28  import com.liferay.portal.service.GroupLocalServiceUtil;
29  import com.liferay.portal.theme.ThemeDisplay;
30  import com.liferay.portlet.calendar.model.CalEvent;
31  import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
32  import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
33  import com.liferay.portlet.social.model.SocialActivity;
34  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
35  
36  /**
37   * <a href="CalendarActivityInterpreter.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class CalendarActivityInterpreter extends BaseSocialActivityInterpreter {
43  
44      public String[] getClassNames() {
45          return _CLASS_NAMES;
46      }
47  
48      protected SocialActivityFeedEntry doInterpret(
49              SocialActivity activity, ThemeDisplay themeDisplay)
50          throws Exception {
51  
52          String creatorUserName = getUserName(
53              activity.getUserId(), themeDisplay);
54  
55          int activityType = activity.getType();
56  
57          // Link
58  
59          CalEvent event = CalEventLocalServiceUtil.getEvent(
60              activity.getClassPK());
61  
62          String link =
63              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
64                  "/calendar/find_event?eventId=" + activity.getClassPK();
65  
66          // Title
67  
68          String groupName = StringPool.BLANK;
69  
70          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
71              Group group = GroupLocalServiceUtil.getGroup(activity.getGroupId());
72  
73              groupName = group.getDescriptiveName();
74          }
75  
76          String titlePattern = null;
77          Object[] titleArguments = null;
78  
79          if (activityType == CalendarActivityKeys.ADD_EVENT) {
80              titlePattern = "activity-calendar-add-event";
81  
82              if (Validator.isNotNull(groupName)) {
83                  titlePattern += "-in";
84              }
85  
86              titleArguments = new Object[] {creatorUserName, groupName};
87          }
88          else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
89              titlePattern = "activity-calendar-update-event";
90  
91              if (Validator.isNotNull(groupName)) {
92                  titlePattern += "-in";
93              }
94  
95              titleArguments = new Object[] {creatorUserName, groupName};
96          }
97  
98          String title = themeDisplay.translate(titlePattern, titleArguments);
99  
100         // Body
101 
102         StringBuilder sb = new StringBuilder();
103 
104         sb.append("<a href=\"");
105         sb.append(link);
106         sb.append("\">");
107         sb.append(cleanContent(event.getTitle()));
108         sb.append("</a><br />");
109         sb.append(cleanContent(event.getDescription()));
110 
111         String body = sb.toString();
112 
113         return new SocialActivityFeedEntry(link, title, body);
114     }
115 
116     private static final String[] _CLASS_NAMES = new String[] {
117         CalEvent.class.getName()
118     };
119 
120 }