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.SocialRequest;
020    import com.liferay.portlet.social.model.SocialRequestFeedEntry;
021    import com.liferay.portlet.social.model.SocialRequestInterpreter;
022    import com.liferay.portlet.social.model.impl.SocialRequestInterpreterImpl;
023    import com.liferay.portlet.social.service.base.SocialRequestInterpreterLocalServiceBaseImpl;
024    
025    import java.util.ArrayList;
026    import java.util.List;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class SocialRequestInterpreterLocalServiceImpl
032            extends SocialRequestInterpreterLocalServiceBaseImpl {
033    
034            public void addRequestInterpreter(
035                    SocialRequestInterpreter requestInterpreter) {
036    
037                    _requestInterpreters.add(requestInterpreter);
038            }
039    
040            public void deleteRequestInterpreter(
041                    SocialRequestInterpreter requestInterpreter) {
042    
043                    if (requestInterpreter != null) {
044                            _requestInterpreters.remove(requestInterpreter);
045                    }
046            }
047    
048            public SocialRequestFeedEntry interpret(
049                    SocialRequest request, ThemeDisplay themeDisplay) {
050    
051                    String className = PortalUtil.getClassName(request.getClassNameId());
052    
053                    for (int i = 0; i < _requestInterpreters.size(); i++) {
054                            SocialRequestInterpreterImpl requestInterpreter =
055                                    (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
056    
057                            if (requestInterpreter.hasClassName(className)) {
058                                    SocialRequestFeedEntry requestFeedEntry =
059                                            requestInterpreter.interpret(request, themeDisplay);
060    
061                                    if (requestFeedEntry != null) {
062                                            requestFeedEntry.setPortletId(
063                                                    requestInterpreter.getPortletId());
064    
065                                            return requestFeedEntry;
066                                    }
067                            }
068                    }
069    
070                    return null;
071            }
072    
073            public void processConfirmation(
074                    SocialRequest request, ThemeDisplay themeDisplay) {
075    
076                    String className = PortalUtil.getClassName(request.getClassNameId());
077    
078                    for (int i = 0; i < _requestInterpreters.size(); i++) {
079                            SocialRequestInterpreterImpl requestInterpreter =
080                                    (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
081    
082                            if (requestInterpreter.hasClassName(className)) {
083                                    boolean value = requestInterpreter.processConfirmation(
084                                            request, themeDisplay);
085    
086                                    if (value) {
087                                            return;
088                                    }
089                            }
090                    }
091            }
092    
093            public void processRejection(
094                    SocialRequest request, ThemeDisplay themeDisplay) {
095    
096                    String className = PortalUtil.getClassName(request.getClassNameId());
097    
098                    for (int i = 0; i < _requestInterpreters.size(); i++) {
099                            SocialRequestInterpreterImpl requestInterpreter =
100                                    (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
101    
102                            if (requestInterpreter.hasClassName(className)) {
103                                    boolean value = requestInterpreter.processRejection(
104                                            request, themeDisplay);
105    
106                                    if (value) {
107                                            return;
108                                    }
109                            }
110                    }
111            }
112    
113            private List<SocialRequestInterpreter> _requestInterpreters =
114                    new ArrayList<SocialRequestInterpreter>();
115    
116    }