1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.util;
24  
25  import com.liferay.portal.model.ActivityFeedEntry;
26  import com.liferay.portal.model.ActivityTracker;
27  import com.liferay.portal.model.ActivityTrackerInterpreter;
28  import com.liferay.portal.model.impl.ActivityTrackerInterpreterImpl;
29  import com.liferay.portal.theme.ThemeDisplay;
30  
31  import java.util.ArrayList;
32  import java.util.List;
33  
34  /**
35   * <a href="ActivityTrackerInterpreterUtil.java.html"><b><i>View Source</i></b>
36   * </a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class ActivityTrackerInterpreterUtil {
42  
43      public static void addActivityTrackerInterpreter(
44          ActivityTrackerInterpreter activityTrackerInterpreter) {
45  
46          _instance._addActivityTrackerInterpreter(activityTrackerInterpreter);
47      }
48  
49      public static void deleteActivityTrackerInterpreter(
50          ActivityTrackerInterpreter activityTrackerInterpreter) {
51  
52          _instance._deleteActivityTrackerInterpreter(activityTrackerInterpreter);
53      }
54  
55      public static ActivityFeedEntry interpret(
56          ActivityTracker activityTracker, ThemeDisplay themeDisplay) {
57  
58          return _instance._interpret(activityTracker, themeDisplay);
59      }
60  
61      private ActivityTrackerInterpreterUtil() {
62          _activityTrackerInterpreters = new ArrayList();
63      }
64  
65      private void _addActivityTrackerInterpreter(
66          ActivityTrackerInterpreter activityTrackerInterpreter) {
67  
68          _activityTrackerInterpreters.add(activityTrackerInterpreter);
69      }
70  
71      private void _deleteActivityTrackerInterpreter(
72          ActivityTrackerInterpreter activityTrackerInterpreter) {
73  
74          if (activityTrackerInterpreter != null) {
75              _activityTrackerInterpreters.remove(activityTrackerInterpreter);
76          }
77      }
78  
79      private ActivityFeedEntry _interpret(
80          ActivityTracker activityTracker, ThemeDisplay themeDisplay) {
81  
82          String className = PortalUtil.getClassName(
83              activityTracker.getClassNameId());
84  
85          for (int i = 0; i < _activityTrackerInterpreters.size(); i++) {
86              ActivityTrackerInterpreterImpl activityTrackerInterpreter =
87                  (ActivityTrackerInterpreterImpl)
88                      _activityTrackerInterpreters.get(i);
89  
90              if (activityTrackerInterpreter.hasClassName(className)) {
91                  ActivityFeedEntry activityFeedEntry =
92                      activityTrackerInterpreter.interpret(
93                          activityTracker, themeDisplay);
94  
95                  if (activityFeedEntry != null) {
96                      return activityFeedEntry;
97                  }
98              }
99          }
100 
101         return null;
102     }
103 
104     private static ActivityTrackerInterpreterUtil _instance =
105         new ActivityTrackerInterpreterUtil();
106 
107     private List _activityTrackerInterpreters;
108 
109 }