001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.impl;
016    
017    import com.liferay.portal.theme.ThemeDisplay;
018    import com.liferay.portal.util.PortalUtil;
019    import com.liferay.portlet.social.model.SocialActivity;
020    import com.liferay.portlet.social.model.SocialActivityFeedEntry;
021    import com.liferay.portlet.social.model.SocialActivityInterpreter;
022    import com.liferay.portlet.social.model.impl.SocialActivityInterpreterImpl;
023    import com.liferay.portlet.social.service.base.SocialActivityInterpreterLocalServiceBaseImpl;
024    
025    import java.util.ArrayList;
026    import java.util.List;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class SocialActivityInterpreterLocalServiceImpl
032            extends SocialActivityInterpreterLocalServiceBaseImpl {
033    
034            public void addActivityInterpreter(
035                    SocialActivityInterpreter activityInterpreter) {
036    
037                    _activityInterpreters.add(activityInterpreter);
038            }
039    
040            public void deleteActivityInterpreter(
041                    SocialActivityInterpreter activityInterpreter) {
042    
043                    if (activityInterpreter != null) {
044                            _activityInterpreters.remove(activityInterpreter);
045                    }
046            }
047    
048            public SocialActivityFeedEntry interpret(
049                    SocialActivity activity, ThemeDisplay themeDisplay) {
050    
051                    if (activity.getMirrorActivityId() > 0) {
052                            SocialActivity mirrorActivity = null;
053    
054                            try {
055                                    mirrorActivity = socialActivityLocalService.getActivity(
056                                            activity.getMirrorActivityId());
057                            }
058                            catch (Exception e) {
059                            }
060    
061                            if (mirrorActivity != null) {
062                                    activity = mirrorActivity;
063                            }
064                    }
065    
066                    String className = PortalUtil.getClassName(activity.getClassNameId());
067    
068                    for (int i = 0; i < _activityInterpreters.size(); i++) {
069                            SocialActivityInterpreterImpl activityInterpreter =
070                                    (SocialActivityInterpreterImpl)_activityInterpreters.get(i);
071    
072                            if (activityInterpreter.hasClassName(className)) {
073                                    SocialActivityFeedEntry activityFeedEntry =
074                                            activityInterpreter.interpret(activity, themeDisplay);
075    
076                                    if (activityFeedEntry != null) {
077                                            activityFeedEntry.setPortletId(
078                                                    activityInterpreter.getPortletId());
079    
080                                            return activityFeedEntry;
081                                    }
082                            }
083                    }
084    
085                    return null;
086            }
087    
088            private List<SocialActivityInterpreter> _activityInterpreters =
089                    new ArrayList<SocialActivityInterpreter>();
090    
091    }