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.blogs.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.blogs.model.BlogsEntry;
24  import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
25  import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
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="BlogsActivityInterpreter.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   * @author Ryan Park
35   */
36  public class BlogsActivityInterpreter 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 (!BlogsEntryPermission.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          String receiverUserName = getUserName(
64              activity.getReceiverUserId(), themeDisplay);
65  
66          int activityType = activity.getType();
67  
68          // Link
69  
70          BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(
71              activity.getClassPK());
72  
73          String link =
74              themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
75                  "/blogs/find_entry?entryId=" + activity.getClassPK();
76  
77          // Title
78  
79          String titlePattern = null;
80  
81          if (activityType == BlogsActivityKeys.ADD_COMMENT) {
82              titlePattern = "activity-blogs-add-comment";
83          }
84          else if (activityType == BlogsActivityKeys.ADD_ENTRY) {
85              titlePattern = "activity-blogs-add-entry";
86          }
87  
88          if (Validator.isNotNull(groupName)) {
89              titlePattern += "-in";
90          }
91  
92          String entryTitle = wrapLink(
93              link, HtmlUtil.escape(cleanContent(entry.getTitle())));
94  
95          Object[] titleArguments = new Object[] {
96              groupName, creatorUserName, receiverUserName, entryTitle
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         BlogsEntry.class.getName()
110     };
111 
112 }