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.messageboards.social;
24  
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.theme.ThemeDisplay;
27  import com.liferay.portlet.messageboards.model.MBMessage;
28  import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
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="MBActivityInterpreter.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class MBActivityInterpreter 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          String receiverUserName = getUserName(
52              activity.getReceiverUserId(), themeDisplay);
53  
54          int activityType = activity.getType();
55  
56          // Link
57  
58          MBMessage message = MBMessageLocalServiceUtil.getMessage(
59              activity.getClassPK());
60  
61          String link =
62              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
63                  "/message_boards/find_message?messageId=" +
64                      activity.getClassPK();
65  
66          // Title
67  
68          String title = StringPool.BLANK;
69  
70          if (activityType == MBActivityKeys.ADD_MESSAGE) {
71              title = themeDisplay.translate(
72                  "activity-message-boards-add-message", creatorUserName);
73          }
74          else if (activityType == MBActivityKeys.REPLY_MESSAGE) {
75              title = themeDisplay.translate(
76                  "activity-message-boards-reply-message",
77                  new Object[] {creatorUserName, receiverUserName});
78          }
79  
80          // Body
81  
82          StringBuilder sb = new StringBuilder();
83  
84          sb.append("<a href=\"");
85          sb.append(link);
86          sb.append("\">");
87          sb.append(cleanContent(message.getSubject()));
88          sb.append("</a><br />");
89          sb.append(cleanContent(message.getBody()));
90  
91          String body = sb.toString();
92  
93          return new SocialActivityFeedEntry(link, title, body);
94      }
95  
96      private static final String[] _CLASS_NAMES = new String[] {
97          MBMessage.class.getName()
98      };
99  
100 }