1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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 }