1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.social.service.impl;
16  
17  import com.liferay.portal.theme.ThemeDisplay;
18  import com.liferay.portal.util.PortalUtil;
19  import com.liferay.portlet.social.model.SocialActivity;
20  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
21  import com.liferay.portlet.social.model.SocialActivityInterpreter;
22  import com.liferay.portlet.social.model.impl.SocialActivityInterpreterImpl;
23  import com.liferay.portlet.social.service.base.SocialActivityInterpreterLocalServiceBaseImpl;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  /**
29   * <a href="SocialActivityInterpreterLocalServiceImpl.java.html"><b><i>View
30   * Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   */
34  public class SocialActivityInterpreterLocalServiceImpl
35      extends SocialActivityInterpreterLocalServiceBaseImpl {
36  
37      public void addActivityInterpreter(
38          SocialActivityInterpreter activityInterpreter) {
39  
40          _activityInterpreters.add(activityInterpreter);
41      }
42  
43      public void deleteActivityInterpreter(
44          SocialActivityInterpreter activityInterpreter) {
45  
46          if (activityInterpreter != null) {
47              _activityInterpreters.remove(activityInterpreter);
48          }
49      }
50  
51      public SocialActivityFeedEntry interpret(
52          SocialActivity activity, ThemeDisplay themeDisplay) {
53  
54          if (activity.getMirrorActivityId() > 0) {
55              SocialActivity mirrorActivity = null;
56  
57              try {
58                  mirrorActivity = socialActivityLocalService.getActivity(
59                      activity.getMirrorActivityId());
60              }
61              catch (Exception e) {
62              }
63  
64              if (mirrorActivity != null) {
65                  activity = mirrorActivity;
66              }
67          }
68  
69          String className = PortalUtil.getClassName(activity.getClassNameId());
70  
71          for (int i = 0; i < _activityInterpreters.size(); i++) {
72              SocialActivityInterpreterImpl activityInterpreter =
73                  (SocialActivityInterpreterImpl)_activityInterpreters.get(i);
74  
75              if (activityInterpreter.hasClassName(className)) {
76                  SocialActivityFeedEntry activityFeedEntry =
77                      activityInterpreter.interpret(activity, themeDisplay);
78  
79                  if (activityFeedEntry != null) {
80                      activityFeedEntry.setPortletId(
81                          activityInterpreter.getPortletId());
82  
83                      return activityFeedEntry;
84                  }
85              }
86          }
87  
88          return null;
89      }
90  
91      private List<SocialActivityInterpreter> _activityInterpreters =
92          new ArrayList<SocialActivityInterpreter>();
93  
94  }