001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.messageboards;
022:
023: import com.liferay.portal.kernel.language.LanguageUtil;
024: import com.liferay.portal.kernel.util.StringMaker;
025: import com.liferay.portal.kernel.util.StringPool;
026: import com.liferay.portal.kernel.util.StringUtil;
027: import com.liferay.portal.model.ActivityFeedEntry;
028: import com.liferay.portal.model.ActivityTracker;
029: import com.liferay.portal.model.ActivityTrackerInterpreter;
030: import com.liferay.portal.model.User;
031: import com.liferay.portal.service.UserLocalServiceUtil;
032: import com.liferay.portal.theme.ThemeDisplay;
033: import com.liferay.portlet.messageboards.model.MBMessage;
034: import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
035:
036: import org.apache.commons.logging.Log;
037: import org.apache.commons.logging.LogFactory;
038:
039: /**
040: * <a href="MBActivityTrackerInterpreter.java.html"><b><i>View Source</i></b>
041: * </a>
042: *
043: * @author Brian Wing Shun Chan
044: *
045: */
046: public class MBActivityTrackerInterpreter implements
047: ActivityTrackerInterpreter {
048:
049: public String[] getClassNames() {
050: return _CLASS_NAMES;
051: }
052:
053: public ActivityFeedEntry interpret(ActivityTracker activityTracker,
054: ThemeDisplay themeDisplay) {
055:
056: try {
057: return doInterpret(activityTracker, themeDisplay);
058: } catch (Exception e) {
059: if (_log.isWarnEnabled()) {
060: _log.warn(e);
061: }
062: }
063:
064: return null;
065: }
066:
067: protected ActivityFeedEntry doInterpret(
068: ActivityTracker activityTracker, ThemeDisplay themeDisplay)
069: throws Exception {
070:
071: User creatorUser = UserLocalServiceUtil
072: .getUserById(activityTracker.getUserId());
073:
074: String creatorUserName = creatorUser.getFullName();
075: String creatorUserDisplayURL = creatorUser
076: .getDisplayURL(themeDisplay.getURLPortal());
077:
078: creatorUserName = "<a href=\"" + creatorUserDisplayURL + "\">"
079: + creatorUserName + "</a>";
080:
081: String activity = activityTracker.getActivity();
082:
083: String receiverUserName = activityTracker.getReceiverUserName();
084:
085: if (activityTracker.getReceiverUserId() > 0) {
086: User receiverUser = UserLocalServiceUtil
087: .getUserById(activityTracker.getReceiverUserId());
088:
089: receiverUserName = receiverUser.getFullName();
090: }
091:
092: // Title
093:
094: String title = StringPool.BLANK;
095:
096: if (activity.equals(MBActivityKeys.ADD)) {
097: title = LanguageUtil.format(themeDisplay.getCompanyId(),
098: themeDisplay.getLocale(),
099: "activity-message-boards-add",
100: new Object[] { creatorUserName });
101: } else if (activity.equals(MBActivityKeys.REPLY)) {
102: title = LanguageUtil.format(themeDisplay.getCompanyId(),
103: themeDisplay.getLocale(),
104: "activity-message-boards-reply", new Object[] {
105: creatorUserName, receiverUserName });
106: }
107:
108: // Body
109:
110: MBMessage message = MBMessageLocalServiceUtil
111: .getMessage(activityTracker.getClassPK());
112:
113: StringMaker sm = new StringMaker();
114:
115: sm.append("<b>");
116: sm.append(message.getSubject());
117: sm.append("</b><br />");
118: sm.append(StringUtil.shorten(message.getBody(), 200));
119:
120: String body = sm.toString();
121:
122: return new ActivityFeedEntry(title, body);
123: }
124:
125: private static final String[] _CLASS_NAMES = new String[] { MBMessage.class
126: .getName() };
127:
128: private static Log _log = LogFactory
129: .getLog(MBActivityTrackerInterpreter.class);
130:
131: }
|