1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.HtmlUtil;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.portal.security.permission.ActionKeys;
29  import com.liferay.portal.security.permission.PermissionChecker;
30  import com.liferay.portal.theme.ThemeDisplay;
31  import com.liferay.portlet.messageboards.model.MBMessage;
32  import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
33  import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
34  import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
35  import com.liferay.portlet.social.model.SocialActivity;
36  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
37  
38  /**
39   * <a href="MBActivityInterpreter.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   * @author Ryan Park
43   */
44  public class MBActivityInterpreter extends BaseSocialActivityInterpreter {
45  
46      public String[] getClassNames() {
47          return _CLASS_NAMES;
48      }
49  
50      protected SocialActivityFeedEntry doInterpret(
51              SocialActivity activity, ThemeDisplay themeDisplay)
52          throws Exception {
53  
54          PermissionChecker permissionChecker =
55              themeDisplay.getPermissionChecker();
56  
57          if (!MBMessagePermission.contains(
58                  permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
59  
60              return null;
61          }
62  
63          String groupName = StringPool.BLANK;
64  
65          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
66              groupName = getGroupName(activity.getGroupId(), themeDisplay);
67          }
68  
69          String creatorUserName = getUserName(
70              activity.getUserId(), themeDisplay);
71          String receiverUserName = getUserName(
72              activity.getReceiverUserId(), themeDisplay);
73  
74          int activityType = activity.getType();
75  
76          // Link
77  
78          MBMessage message = MBMessageLocalServiceUtil.getMessage(
79              activity.getClassPK());
80  
81          String link =
82              themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
83                  "/message_boards/find_message?messageId=" +
84                      message.getMessageId();
85  
86          // Title
87  
88          String titlePattern = null;
89  
90          if (activityType == MBActivityKeys.ADD_MESSAGE) {
91              titlePattern = "activity-message-boards-add-message";
92          }
93          else if (activityType == MBActivityKeys.REPLY_MESSAGE) {
94              titlePattern = "activity-message-boards-reply-message";
95          }
96  
97          if (Validator.isNotNull(groupName)) {
98              titlePattern += "-in";
99          }
100 
101         String messageSubject = wrapLink(
102             link, HtmlUtil.escape(cleanContent(message.getSubject())));
103 
104         Object[] titleArguments = new Object[] {
105             groupName, creatorUserName, receiverUserName, messageSubject
106         };
107 
108         String title = themeDisplay.translate(titlePattern, titleArguments);
109 
110         // Body
111 
112         String categoryLink =
113             themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
114                 "/message_boards/find_category?categoryId=" +
115                     message.getCategoryId();
116 
117         String body = wrapLink(categoryLink, "go-to-category", themeDisplay);
118 
119         return new SocialActivityFeedEntry(link, title, body);
120     }
121 
122     private static final String[] _CLASS_NAMES = new String[] {
123         MBMessage.class.getName()
124     };
125 
126 }