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.imagegallery.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.imagegallery.model.IGImage;
24  import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
25  import com.liferay.portlet.imagegallery.service.permission.IGImagePermission;
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="IGActivityInterpreter.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Ryan Park
34   */
35  public class IGActivityInterpreter extends BaseSocialActivityInterpreter {
36  
37      public String[] getClassNames() {
38          return _CLASS_NAMES;
39      }
40  
41      protected SocialActivityFeedEntry doInterpret(
42              SocialActivity activity, ThemeDisplay themeDisplay)
43          throws Exception {
44  
45          PermissionChecker permissionChecker =
46              themeDisplay.getPermissionChecker();
47  
48          IGImage image = IGImageLocalServiceUtil.getIGImage(
49              activity.getClassPK());
50  
51          if (!IGImagePermission.contains(
52                  permissionChecker, image, ActionKeys.VIEW)) {
53  
54              return null;
55          }
56  
57          String groupName = StringPool.BLANK;
58  
59          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
60              groupName = getGroupName(activity.getGroupId(), themeDisplay);
61          }
62  
63          String creatorUserName = getUserName(
64              activity.getUserId(), themeDisplay);
65  
66          int activityType = activity.getType();
67  
68          // Link
69  
70          String link =
71              themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
72                  "/image_gallery/find_image?imageId=" + image.getImageId();
73  
74          // Title
75  
76          String titlePattern = null;
77  
78          if (activityType == IGActivityKeys.ADD_IMAGE) {
79              titlePattern = "activity-image-gallery-add-image";
80          }
81          else if (activityType == IGActivityKeys.UPDATE_IMAGE) {
82              titlePattern = "activity-image-gallery-update-image";
83          }
84  
85          if (Validator.isNotNull(groupName)) {
86              titlePattern += "-in";
87          }
88  
89          String imageName = wrapLink(
90              link, HtmlUtil.escape(cleanContent(image.getName())));
91  
92          Object[] titleArguments = new Object[] {
93              groupName, creatorUserName, imageName
94          };
95  
96          String title = themeDisplay.translate(titlePattern, titleArguments);
97  
98          // Body
99  
100         String folderLink =
101             themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
102                 "/image_gallery/find_folder?folderId=" + image.getFolderId();
103 
104         String body = wrapLink(folderLink, "go-to-folder", themeDisplay);
105 
106         return new SocialActivityFeedEntry(link, title, body);
107     }
108 
109     private static final String[] _CLASS_NAMES = new String[] {
110         IGImage.class.getName()
111     };
112 
113 }