1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }