1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.social.service.impl;
21  
22  import com.liferay.portal.theme.ThemeDisplay;
23  import com.liferay.portal.util.PortalUtil;
24  import com.liferay.portlet.social.model.SocialActivity;
25  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
26  import com.liferay.portlet.social.model.SocialActivityInterpreter;
27  import com.liferay.portlet.social.model.impl.SocialActivityInterpreterImpl;
28  import com.liferay.portlet.social.service.base.SocialActivityInterpreterLocalServiceBaseImpl;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  /**
34   * <a href="SocialActivityInterpreterLocalServiceImpl.java.html"><b><i>View
35   * Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class SocialActivityInterpreterLocalServiceImpl
41      extends SocialActivityInterpreterLocalServiceBaseImpl {
42  
43      public void addActivityInterpreter(
44          SocialActivityInterpreter activityInterpreter) {
45  
46          _activityInterpreters.add(activityInterpreter);
47      }
48  
49      public void deleteActivityInterpreter(
50          SocialActivityInterpreter activityInterpreter) {
51  
52          if (activityInterpreter != null) {
53              _activityInterpreters.remove(activityInterpreter);
54          }
55      }
56  
57      public SocialActivityFeedEntry interpret(
58          SocialActivity activity, ThemeDisplay themeDisplay) {
59  
60          if (activity.getMirrorActivityId() > 0) {
61              SocialActivity mirrorActivity = null;
62  
63              try {
64                  mirrorActivity = socialActivityLocalService.getActivity(
65                      activity.getMirrorActivityId());
66              }
67              catch (Exception e) {
68              }
69  
70              if (mirrorActivity != null) {
71                  activity = mirrorActivity;
72              }
73          }
74  
75          String className = PortalUtil.getClassName(activity.getClassNameId());
76  
77          for (int i = 0; i < _activityInterpreters.size(); i++) {
78              SocialActivityInterpreterImpl activityInterpreter =
79                  (SocialActivityInterpreterImpl)_activityInterpreters.get(i);
80  
81              if (activityInterpreter.hasClassName(className)) {
82                  SocialActivityFeedEntry activityFeedEntry =
83                      activityInterpreter.interpret(activity, themeDisplay);
84  
85                  if (activityFeedEntry != null) {
86                      activityFeedEntry.setPortletId(
87                          activityInterpreter.getPortletId());
88  
89                      return activityFeedEntry;
90                  }
91              }
92          }
93  
94          return null;
95      }
96  
97      private List<SocialActivityInterpreter> _activityInterpreters =
98          new ArrayList<SocialActivityInterpreter>();
99  
100 }