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