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.SocialRequest;
25  import com.liferay.portlet.social.model.SocialRequestFeedEntry;
26  import com.liferay.portlet.social.model.SocialRequestInterpreter;
27  import com.liferay.portlet.social.model.impl.SocialRequestInterpreterImpl;
28  import com.liferay.portlet.social.service.base.SocialRequestInterpreterLocalServiceBaseImpl;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  /**
34   * <a href="SocialRequestInterpreterLocalServiceImpl.java.html"><b><i>View
35   * Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class SocialRequestInterpreterLocalServiceImpl
41      extends SocialRequestInterpreterLocalServiceBaseImpl {
42  
43      public void addRequestInterpreter(
44          SocialRequestInterpreter requestInterpreter) {
45  
46          _requestInterpreters.add(requestInterpreter);
47      }
48  
49      public void deleteRequestInterpreter(
50          SocialRequestInterpreter requestInterpreter) {
51  
52          if (requestInterpreter != null) {
53              _requestInterpreters.remove(requestInterpreter);
54          }
55      }
56  
57      public SocialRequestFeedEntry interpret(
58          SocialRequest request, ThemeDisplay themeDisplay) {
59  
60          String className = PortalUtil.getClassName(request.getClassNameId());
61  
62          for (int i = 0; i < _requestInterpreters.size(); i++) {
63              SocialRequestInterpreterImpl requestInterpreter =
64                  (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
65  
66              if (requestInterpreter.hasClassName(className)) {
67                  SocialRequestFeedEntry requestFeedEntry =
68                      requestInterpreter.interpret(request, themeDisplay);
69  
70                  if (requestFeedEntry != null) {
71                      requestFeedEntry.setPortletId(
72                          requestInterpreter.getPortletId());
73  
74                      return requestFeedEntry;
75                  }
76              }
77          }
78  
79          return null;
80      }
81  
82      public void processConfirmation(
83          SocialRequest request, ThemeDisplay themeDisplay) {
84  
85          String className = PortalUtil.getClassName(request.getClassNameId());
86  
87          for (int i = 0; i < _requestInterpreters.size(); i++) {
88              SocialRequestInterpreterImpl requestInterpreter =
89                  (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
90  
91              if (requestInterpreter.hasClassName(className)) {
92                  boolean value = requestInterpreter.processConfirmation(
93                      request, themeDisplay);
94  
95                  if (value) {
96                      return;
97                  }
98              }
99          }
100     }
101 
102     public void processRejection(
103         SocialRequest request, ThemeDisplay themeDisplay) {
104 
105         String className = PortalUtil.getClassName(request.getClassNameId());
106 
107         for (int i = 0; i < _requestInterpreters.size(); i++) {
108             SocialRequestInterpreterImpl requestInterpreter =
109                 (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
110 
111             if (requestInterpreter.hasClassName(className)) {
112                 boolean value = requestInterpreter.processRejection(
113                     request, themeDisplay);
114 
115                 if (value) {
116                     return;
117                 }
118             }
119         }
120     }
121 
122     private List<SocialRequestInterpreter> _requestInterpreters =
123         new ArrayList<SocialRequestInterpreter>();
124 
125 }