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.portal.util;
022:
023: import com.liferay.portal.model.ActivityFeedEntry;
024: import com.liferay.portal.model.ActivityTracker;
025: import com.liferay.portal.model.ActivityTrackerInterpreter;
026: import com.liferay.portal.model.impl.ActivityTrackerInterpreterImpl;
027: import com.liferay.portal.theme.ThemeDisplay;
028:
029: import java.util.ArrayList;
030: import java.util.List;
031:
032: /**
033: * <a href="ActivityTrackerInterpreterUtil.java.html"><b><i>View Source</i></b>
034: * </a>
035: *
036: * @author Brian Wing Shun Chan
037: *
038: */
039: public class ActivityTrackerInterpreterUtil {
040:
041: public static void addActivityTrackerInterpreter(
042: ActivityTrackerInterpreter activityTrackerInterpreter) {
043:
044: _instance
045: ._addActivityTrackerInterpreter(activityTrackerInterpreter);
046: }
047:
048: public static void deleteActivityTrackerInterpreter(
049: ActivityTrackerInterpreter activityTrackerInterpreter) {
050:
051: _instance
052: ._deleteActivityTrackerInterpreter(activityTrackerInterpreter);
053: }
054:
055: public static ActivityFeedEntry interpret(
056: ActivityTracker activityTracker, ThemeDisplay themeDisplay) {
057:
058: return _instance._interpret(activityTracker, themeDisplay);
059: }
060:
061: private ActivityTrackerInterpreterUtil() {
062: _activityTrackerInterpreters = new ArrayList();
063: }
064:
065: private void _addActivityTrackerInterpreter(
066: ActivityTrackerInterpreter activityTrackerInterpreter) {
067:
068: _activityTrackerInterpreters.add(activityTrackerInterpreter);
069: }
070:
071: private void _deleteActivityTrackerInterpreter(
072: ActivityTrackerInterpreter activityTrackerInterpreter) {
073:
074: if (activityTrackerInterpreter != null) {
075: _activityTrackerInterpreters
076: .remove(activityTrackerInterpreter);
077: }
078: }
079:
080: private ActivityFeedEntry _interpret(
081: ActivityTracker activityTracker, ThemeDisplay themeDisplay) {
082:
083: String className = PortalUtil.getClassName(activityTracker
084: .getClassNameId());
085:
086: for (int i = 0; i < _activityTrackerInterpreters.size(); i++) {
087: ActivityTrackerInterpreterImpl activityTrackerInterpreter = (ActivityTrackerInterpreterImpl) _activityTrackerInterpreters
088: .get(i);
089:
090: if (activityTrackerInterpreter.hasClassName(className)) {
091: ActivityFeedEntry activityFeedEntry = activityTrackerInterpreter
092: .interpret(activityTracker, themeDisplay);
093:
094: if (activityFeedEntry != null) {
095: return activityFeedEntry;
096: }
097: }
098: }
099:
100: return null;
101: }
102:
103: private static ActivityTrackerInterpreterUtil _instance = new ActivityTrackerInterpreterUtil();
104:
105: private List _activityTrackerInterpreters;
106:
107: }
|