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