001
014
015 package com.liferay.portlet.wiki.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.social.model.BaseSocialActivityInterpreter;
024 import com.liferay.portlet.social.model.SocialActivity;
025 import com.liferay.portlet.social.model.SocialActivityConstants;
026 import com.liferay.portlet.social.model.SocialActivityFeedEntry;
027 import com.liferay.portlet.wiki.model.WikiPage;
028 import com.liferay.portlet.wiki.model.WikiPageResource;
029 import com.liferay.portlet.wiki.service.WikiPageResourceLocalServiceUtil;
030 import com.liferay.portlet.wiki.service.permission.WikiPagePermission;
031
032
036 public class WikiActivityInterpreter extends BaseSocialActivityInterpreter {
037
038 @Override
039 public String[] getClassNames() {
040 return _CLASS_NAMES;
041 }
042
043 @Override
044 protected SocialActivityFeedEntry doInterpret(
045 SocialActivity activity, ThemeDisplay themeDisplay)
046 throws Exception {
047
048 PermissionChecker permissionChecker =
049 themeDisplay.getPermissionChecker();
050
051 if (!WikiPagePermission.contains(
052 permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
053
054 return null;
055 }
056
057 String groupName = StringPool.BLANK;
058
059 if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
060 groupName = getGroupName(activity.getGroupId(), themeDisplay);
061 }
062
063 String creatorUserName = getUserName(
064 activity.getUserId(), themeDisplay);
065
066 int activityType = activity.getType();
067
068
069
070 WikiPageResource pageResource =
071 WikiPageResourceLocalServiceUtil.getPageResource(
072 activity.getClassPK());
073
074 String link =
075 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
076 "/wiki/find_page?pageResourcePrimKey=" + activity.getClassPK();
077
078
079
080 String titlePattern = null;
081
082 if ((activityType == WikiActivityKeys.ADD_COMMENT) ||
083 (activityType == SocialActivityConstants.TYPE_ADD_COMMENT)) {
084
085 titlePattern = "activity-wiki-add-comment";
086 }
087 else if (activityType == WikiActivityKeys.ADD_PAGE) {
088 titlePattern = "activity-wiki-add-page";
089 }
090 else if (activityType == WikiActivityKeys.UPDATE_PAGE) {
091 titlePattern = "activity-wiki-update-page";
092 }
093
094 if (Validator.isNotNull(groupName)) {
095 titlePattern += "-in";
096 }
097
098 String pageTitle = wrapLink(
099 link, HtmlUtil.escape(pageResource.getTitle()));
100
101 Object[] titleArguments = new Object[] {
102 groupName, creatorUserName, pageTitle
103 };
104
105 String title = themeDisplay.translate(titlePattern, titleArguments);
106
107
108
109 String body = StringPool.BLANK;
110
111 return new SocialActivityFeedEntry(link, title, body);
112 }
113
114 private static final String[] _CLASS_NAMES = new String[] {
115 WikiPage.class.getName()
116 };
117
118 }