1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class SocialRequestInterpreterLocalServiceImpl
43      extends SocialRequestInterpreterLocalServiceBaseImpl {
44  
45      public void addRequestInterpreter(
46          SocialRequestInterpreter requestInterpreter) {
47  
48          _requestInterpreters.add(requestInterpreter);
49      }
50  
51      public void deleteRequestInterpreter(
52          SocialRequestInterpreter requestInterpreter) {
53  
54          if (requestInterpreter != null) {
55              _requestInterpreters.remove(requestInterpreter);
56          }
57      }
58  
59      public SocialRequestFeedEntry interpret(
60          SocialRequest request, ThemeDisplay themeDisplay) {
61  
62          String className = PortalUtil.getClassName(request.getClassNameId());
63  
64          for (int i = 0; i < _requestInterpreters.size(); i++) {
65              SocialRequestInterpreterImpl requestInterpreter =
66                  (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
67  
68              if (requestInterpreter.hasClassName(className)) {
69                  SocialRequestFeedEntry requestFeedEntry =
70                      requestInterpreter.interpret(request, themeDisplay);
71  
72                  if (requestFeedEntry != null) {
73                      requestFeedEntry.setPortletId(
74                          requestInterpreter.getPortletId());
75  
76                      return requestFeedEntry;
77                  }
78              }
79          }
80  
81          return null;
82      }
83  
84      public void processConfirmation(
85          SocialRequest request, ThemeDisplay themeDisplay) {
86  
87          String className = PortalUtil.getClassName(request.getClassNameId());
88  
89          for (int i = 0; i < _requestInterpreters.size(); i++) {
90              SocialRequestInterpreterImpl requestInterpreter =
91                  (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
92  
93              if (requestInterpreter.hasClassName(className)) {
94                  boolean value = requestInterpreter.processConfirmation(
95                      request, themeDisplay);
96  
97                  if (value) {
98                      return;
99                  }
100             }
101         }
102     }
103 
104     public void processRejection(
105         SocialRequest request, ThemeDisplay themeDisplay) {
106 
107         String className = PortalUtil.getClassName(request.getClassNameId());
108 
109         for (int i = 0; i < _requestInterpreters.size(); i++) {
110             SocialRequestInterpreterImpl requestInterpreter =
111                 (SocialRequestInterpreterImpl)_requestInterpreters.get(i);
112 
113             if (requestInterpreter.hasClassName(className)) {
114                 boolean value = requestInterpreter.processRejection(
115                     request, themeDisplay);
116 
117                 if (value) {
118                     return;
119                 }
120             }
121         }
122     }
123 
124     private List<SocialRequestInterpreter> _requestInterpreters =
125         new ArrayList<SocialRequestInterpreter>();
126 
127 }