1
22
23 package com.liferay.portlet.blogs.social;
24
25 import com.liferay.portal.kernel.json.JSONFactoryUtil;
26 import com.liferay.portal.kernel.json.JSONObject;
27 import com.liferay.portal.kernel.util.StringPool;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.portal.theme.ThemeDisplay;
30 import com.liferay.portlet.blogs.model.BlogsEntry;
31 import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
32 import com.liferay.portlet.messageboards.model.MBMessage;
33 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
34 import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
35 import com.liferay.portlet.social.model.SocialActivity;
36 import com.liferay.portlet.social.model.SocialActivityFeedEntry;
37
38
44 public class BlogsActivityInterpreter extends BaseSocialActivityInterpreter {
45
46 public String[] getClassNames() {
47 return _CLASS_NAMES;
48 }
49
50 protected SocialActivityFeedEntry doInterpret(
51 SocialActivity activity, ThemeDisplay themeDisplay)
52 throws Exception {
53
54 String creatorUserName = getUserName(
55 activity.getUserId(), themeDisplay);
56 String receiverUserName = getUserName(
57 activity.getReceiverUserId(), themeDisplay);
58
59 int activityType = activity.getType();
60
61 JSONObject extraData = null;
62
63 if (Validator.isNotNull(activity.getExtraData())) {
64 extraData = JSONFactoryUtil.createJSONObject(
65 activity.getExtraData());
66 }
67
68
70 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(
71 activity.getClassPK());
72
73 String link =
74 themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
75 "/blogs/find_entry?entryId=" + activity.getClassPK();
76
77
79 String title = StringPool.BLANK;
80
81 if (activityType == BlogsActivityKeys.ADD_COMMENT) {
82 title = themeDisplay.translate(
83 "activity-blogs-add-comment",
84 new Object[] {creatorUserName, receiverUserName});
85 }
86 else if (activityType == BlogsActivityKeys.ADD_ENTRY) {
87 title = themeDisplay.translate(
88 "activity-blogs-add-entry", creatorUserName);
89 }
90
91
93 StringBuilder sb = new StringBuilder();
94
95 sb.append("<a href=\"");
96 sb.append(link);
97 sb.append("\">");
98
99 if (activityType == BlogsActivityKeys.ADD_COMMENT) {
100 long messageId = extraData.getInt("messageId");
101
102 MBMessage message = MBMessageLocalServiceUtil.getMessage(messageId);
103
104 sb.append(cleanContent(message.getBody()));
105 }
106 else if (activityType == BlogsActivityKeys.ADD_ENTRY) {
107 sb.append(entry.getTitle());
108 }
109
110 sb.append("</a><br />");
111
112 if (activityType == BlogsActivityKeys.ADD_ENTRY) {
113 sb.append(cleanContent(entry.getContent()));
114 }
115
116 String body = sb.toString();
117
118 return new SocialActivityFeedEntry(link, title, body);
119 }
120
121 private static final String[] _CLASS_NAMES = new String[] {
122 BlogsEntry.class.getName()
123 };
124
125 }