001    /**
002     * Copyright (c) 2000-2012 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.blogs.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.blogs.model.BlogsEntry;
024    import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
025    import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
026    import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
027    import com.liferay.portlet.social.model.SocialActivity;
028    import com.liferay.portlet.social.model.SocialActivityConstants;
029    import com.liferay.portlet.social.model.SocialActivityFeedEntry;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     * @author Ryan Park
034     */
035    public class BlogsActivityInterpreter extends BaseSocialActivityInterpreter {
036    
037            public String[] getClassNames() {
038                    return _CLASS_NAMES;
039            }
040    
041            @Override
042            protected SocialActivityFeedEntry doInterpret(
043                            SocialActivity activity, ThemeDisplay themeDisplay)
044                    throws Exception {
045    
046                    PermissionChecker permissionChecker =
047                            themeDisplay.getPermissionChecker();
048    
049                    if (!BlogsEntryPermission.contains(
050                                    permissionChecker, activity.getClassPK(), 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                    String receiverUserName = getUserName(
064                            activity.getReceiverUserId(), themeDisplay);
065    
066                    int activityType = activity.getType();
067    
068                    // Link
069    
070                    BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(
071                            activity.getClassPK());
072    
073                    String link =
074                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
075                                    "/blogs/find_entry?entryId=" + activity.getClassPK();
076    
077                    // Title
078    
079                    String titlePattern = null;
080    
081                    if ((activityType == BlogsActivityKeys.ADD_COMMENT) ||
082                            (activityType == SocialActivityConstants.TYPE_ADD_COMMENT)) {
083    
084                            titlePattern = "activity-blogs-add-comment";
085                    }
086                    else if (activityType == BlogsActivityKeys.ADD_ENTRY) {
087                            titlePattern = "activity-blogs-add-entry";
088                    }
089    
090                    if (Validator.isNotNull(groupName)) {
091                            titlePattern += "-in";
092                    }
093    
094                    String entryTitle = wrapLink(
095                            link, HtmlUtil.escape(cleanContent(entry.getTitle())));
096    
097                    Object[] titleArguments = new Object[] {
098                            groupName, creatorUserName, receiverUserName, entryTitle
099                    };
100    
101                    String title = themeDisplay.translate(titlePattern, titleArguments);
102    
103                    // Body
104    
105                    String body = StringPool.BLANK;
106    
107                    return new SocialActivityFeedEntry(link, title, body);
108            }
109    
110            private static final String[] _CLASS_NAMES = new String[] {
111                    BlogsEntry.class.getName()
112            };
113    
114    }