1   /**
2    * Copyright (c) 2000-2008 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.theme.ThemeDisplay;
27  import com.liferay.portlet.calendar.model.CalEvent;
28  import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
29  import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
30  import com.liferay.portlet.social.model.SocialActivity;
31  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
32  
33  /**
34   * <a href="CalendarActivityInterpreter.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class CalendarActivityInterpreter extends BaseSocialActivityInterpreter {
40  
41      public String[] getClassNames() {
42          return _CLASS_NAMES;
43      }
44  
45      protected SocialActivityFeedEntry doInterpret(
46              SocialActivity activity, ThemeDisplay themeDisplay)
47          throws Exception {
48  
49          String creatorUserName = getUserName(
50              activity.getUserId(), themeDisplay);
51  
52          int activityType = activity.getType();
53  
54          // Link
55  
56          CalEvent event = CalEventLocalServiceUtil.getEvent(
57              activity.getClassPK());
58  
59          String link =
60              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
61                  "/calendar/find_event?eventId=" + activity.getClassPK();
62  
63          // Title
64  
65          String title = StringPool.BLANK;
66  
67          if (activityType == CalendarActivityKeys.ADD_EVENT) {
68              title = themeDisplay.translate(
69                  "activity-calendar-add-event", creatorUserName);
70          }
71          else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
72              title = themeDisplay.translate(
73                  "activity-calendar-update-event", creatorUserName);
74          }
75  
76          // Body
77  
78          StringBuilder sb = new StringBuilder();
79  
80          sb.append("<a href=\"");
81          sb.append(link);
82          sb.append("\">");
83          sb.append(cleanContent(event.getTitle()));
84          sb.append("</a><br />");
85          sb.append(cleanContent(event.getDescription()));
86  
87          String body = sb.toString();
88  
89          return new SocialActivityFeedEntry(link, title, body);
90      }
91  
92      private static final String[] _CLASS_NAMES = new String[] {
93          CalEvent.class.getName()
94      };
95  
96  }