001
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.SocialActivityFeedEntry;
029
030
034 public class BlogsActivityInterpreter extends BaseSocialActivityInterpreter {
035
036 public String[] getClassNames() {
037 return _CLASS_NAMES;
038 }
039
040 protected SocialActivityFeedEntry doInterpret(
041 SocialActivity activity, ThemeDisplay themeDisplay)
042 throws Exception {
043
044 PermissionChecker permissionChecker =
045 themeDisplay.getPermissionChecker();
046
047 if (!BlogsEntryPermission.contains(
048 permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
049
050 return null;
051 }
052
053 String groupName = StringPool.BLANK;
054
055 if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
056 groupName = getGroupName(activity.getGroupId(), themeDisplay);
057 }
058
059 String creatorUserName = getUserName(
060 activity.getUserId(), themeDisplay);
061 String receiverUserName = getUserName(
062 activity.getReceiverUserId(), themeDisplay);
063
064 int activityType = activity.getType();
065
066
067
068 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(
069 activity.getClassPK());
070
071 String link =
072 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
073 "/blogs/find_entry?entryId=" + activity.getClassPK();
074
075
076
077 String titlePattern = null;
078
079 if (activityType == BlogsActivityKeys.ADD_COMMENT) {
080 titlePattern = "activity-blogs-add-comment";
081 }
082 else if (activityType == BlogsActivityKeys.ADD_ENTRY) {
083 titlePattern = "activity-blogs-add-entry";
084 }
085
086 if (Validator.isNotNull(groupName)) {
087 titlePattern += "-in";
088 }
089
090 String entryTitle = wrapLink(
091 link, HtmlUtil.escape(cleanContent(entry.getTitle())));
092
093 Object[] titleArguments = new Object[] {
094 groupName, creatorUserName, receiverUserName, entryTitle
095 };
096
097 String title = themeDisplay.translate(titlePattern, titleArguments);
098
099
100
101 String body = StringPool.BLANK;
102
103 return new SocialActivityFeedEntry(link, title, body);
104 }
105
106 private static final String[] _CLASS_NAMES = new String[] {
107 BlogsEntry.class.getName()
108 };
109
110 }