001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.imagegallery.social;
016    
017    import com.liferay.portal.kernel.util.HtmlUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portlet.imagegallery.model.IGImage;
024    import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
025    import com.liferay.portlet.imagegallery.service.permission.IGImagePermission;
026    import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
027    import com.liferay.portlet.social.model.SocialActivity;
028    import com.liferay.portlet.social.model.SocialActivityFeedEntry;
029    
030    /**
031     * @author Ryan Park
032     */
033    public class IGActivityInterpreter extends BaseSocialActivityInterpreter {
034    
035            public String[] getClassNames() {
036                    return _CLASS_NAMES;
037            }
038    
039            protected SocialActivityFeedEntry doInterpret(
040                            SocialActivity activity, ThemeDisplay themeDisplay)
041                    throws Exception {
042    
043                    PermissionChecker permissionChecker =
044                            themeDisplay.getPermissionChecker();
045    
046                    IGImage image = IGImageLocalServiceUtil.getIGImage(
047                            activity.getClassPK());
048    
049                    if (!IGImagePermission.contains(
050                                    permissionChecker, image, ActionKeys.VIEW)) {
051    
052                            return null;
053                    }
054    
055                    String groupName = StringPool.BLANK;
056    
057                    if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
058                            groupName = getGroupName(activity.getGroupId(), themeDisplay);
059                    }
060    
061                    String creatorUserName = getUserName(
062                            activity.getUserId(), themeDisplay);
063    
064                    int activityType = activity.getType();
065    
066                    // Link
067    
068                    String link =
069                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
070                                    "/image_gallery/find_image?imageId=" + image.getImageId();
071    
072                    // Title
073    
074                    String titlePattern = null;
075    
076                    if (activityType == IGActivityKeys.ADD_IMAGE) {
077                            titlePattern = "activity-image-gallery-add-image";
078                    }
079                    else if (activityType == IGActivityKeys.UPDATE_IMAGE) {
080                            titlePattern = "activity-image-gallery-update-image";
081                    }
082    
083                    if (Validator.isNotNull(groupName)) {
084                            titlePattern += "-in";
085                    }
086    
087                    String imageName = wrapLink(
088                            link, HtmlUtil.escape(cleanContent(image.getName())));
089    
090                    Object[] titleArguments = new Object[] {
091                            groupName, creatorUserName, imageName
092                    };
093    
094                    String title = themeDisplay.translate(titlePattern, titleArguments);
095    
096                    // Body
097    
098                    String folderLink =
099                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
100                                    "/image_gallery/find_folder?folderId=" + image.getFolderId();
101    
102                    String body = wrapLink(folderLink, "go-to-folder", themeDisplay);
103    
104                    return new SocialActivityFeedEntry(link, title, body);
105            }
106    
107            private static final String[] _CLASS_NAMES = new String[] {
108                    IGImage.class.getName()
109            };
110    
111    }