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