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.SocialActivityFeedEntry;
026 import com.liferay.portlet.wiki.model.WikiPage;
027 import com.liferay.portlet.wiki.model.WikiPageResource;
028 import com.liferay.portlet.wiki.service.WikiPageResourceLocalServiceUtil;
029 import com.liferay.portlet.wiki.service.permission.WikiPagePermission;
030
031
035 public class WikiActivityInterpreter extends BaseSocialActivityInterpreter {
036
037 public String[] getClassNames() {
038 return _CLASS_NAMES;
039 }
040
041 protected SocialActivityFeedEntry doInterpret(
042 SocialActivity activity, ThemeDisplay themeDisplay)
043 throws Exception {
044
045 PermissionChecker permissionChecker =
046 themeDisplay.getPermissionChecker();
047
048 if (!WikiPagePermission.contains(
049 permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
050
051 return null;
052 }
053
054 String groupName = StringPool.BLANK;
055
056 if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
057 groupName = getGroupName(activity.getGroupId(), themeDisplay);
058 }
059
060 String creatorUserName = getUserName(
061 activity.getUserId(), themeDisplay);
062
063 int activityType = activity.getType();
064
065
066
067 WikiPageResource pageResource =
068 WikiPageResourceLocalServiceUtil.getPageResource(
069 activity.getClassPK());
070
071 String link =
072 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
073 "/wiki/find_page?pageResourcePrimKey=" + activity.getClassPK();
074
075
076
077 String titlePattern = null;
078
079 if (activityType == WikiActivityKeys.ADD_PAGE) {
080 titlePattern = "activity-wiki-add-page";
081 }
082 else if (activityType == WikiActivityKeys.UPDATE_PAGE) {
083 titlePattern = "activity-wiki-update-page";
084 }
085
086 if (Validator.isNotNull(groupName)) {
087 titlePattern += "-in";
088 }
089
090 String pageTitle = wrapLink(
091 link, HtmlUtil.escape(cleanContent(pageResource.getTitle())));
092
093 Object[] titleArguments = new Object[] {
094 groupName, creatorUserName, pageTitle
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 WikiPage.class.getName()
108 };
109
110 }