1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.SocialRequest;
28  import com.liferay.portlet.social.model.SocialRequestFeedEntry;
29  import com.liferay.portlet.social.model.SocialRequestInterpreter;
30  import com.liferay.portlet.social.model.impl.SocialRequestInterpreterImpl;
31  import com.liferay.portlet.social.service.base.SocialRequestInterpreterLocalServiceBaseImpl;
32  
33  import java.util.ArrayList;
34  import java.util.List;
35  
36  /**
37   * <a href="SocialRequestInterpreterLocalServiceImpl.java.html"><b><i>View
38   * Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   *
42   */
43  public class SocialRequestInterpreterLocalServiceImpl
44      extends SocialRequestInterpreterLocalServiceBaseImpl {
45  
46      public void addRequestInterpreter(
47          SocialRequestInterpreter requestInterpreter) {
48  
49          _requestInterpreters.add(requestInterpreter);
50      }
51  
52      public void deleteRequestInterpreter(
53          SocialRequestInterpreter requestInterpreter) {
54  
55          if (requestInterpreter != null) {
56              _requestInterpreters.remove(requestInterpreter);
57          }
58      }
59  
60      public SocialRequestFeedEntry interpret(
61          SocialRequest request, ThemeDisplay themeDisplay) {
62  
63          String className = PortalUtil.getClassName(request.getClassNameId());
64  
65          for (int i = 0; i < _requestInterpreters.size(); i++) {
66              SocialRequestInterpreterImpl requestInterpreter =
67                  (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
68  
69              if (requestInterpreter.hasClassName(className)) {
70                  SocialRequestFeedEntry requestFeedEntry =
71                      requestInterpreter.interpret(request, themeDisplay);
72  
73                  if (requestFeedEntry != null) {
74                      requestFeedEntry.setPortletId(
75                          requestInterpreter.getPortletId());
76  
77                      return requestFeedEntry;
78                  }
79              }
80          }
81  
82          return null;
83      }
84  
85      public void processConfirmation(
86          SocialRequest request, ThemeDisplay themeDisplay) {
87  
88          String className = PortalUtil.getClassName(request.getClassNameId());
89  
90          for (int i = 0; i < _requestInterpreters.size(); i++) {
91              SocialRequestInterpreterImpl requestInterpreter =
92                  (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
93  
94              if (requestInterpreter.hasClassName(className)) {
95                  boolean value = requestInterpreter.processConfirmation(
96                      request, themeDisplay);
97  
98                  if (value) {
99                      return;
100                 }
101             }
102         }
103     }
104 
105     public void processRejection(
106         SocialRequest request, ThemeDisplay themeDisplay) {
107 
108         String className = PortalUtil.getClassName(request.getClassNameId());
109 
110         for (int i = 0; i < _requestInterpreters.size(); i++) {
111             SocialRequestInterpreterImpl requestInterpreter =
112                 (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
113 
114             if (requestInterpreter.hasClassName(className)) {
115                 boolean value = requestInterpreter.processRejection(
116                     request, themeDisplay);
117 
118                 if (value) {
119                     return;
120                 }
121             }
122         }
123     }
124 
125     private List<SocialRequestInterpreter> _requestInterpreters =
126         new ArrayList<SocialRequestInterpreter>();
127 
128 }