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.portal.kernel.events;
16  
17  import com.liferay.portal.kernel.util.MethodKey;
18  import com.liferay.portal.kernel.util.PortalClassInvoker;
19  
20  import javax.portlet.PortletRequest;
21  import javax.portlet.PortletResponse;
22  import javax.portlet.RenderRequest;
23  import javax.portlet.RenderResponse;
24  
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  
28  /**
29   * <a href="Action.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public abstract class Action {
34  
35      public abstract void run(
36              HttpServletRequest request, HttpServletResponse response)
37          throws ActionException;
38  
39      public void run(RenderRequest renderRequest, RenderResponse renderResponse)
40          throws ActionException {
41  
42          try {
43              HttpServletRequest request = _getHttpServletRequest(renderRequest);
44              HttpServletResponse response = _getHttpServletResponse(
45                  renderResponse);
46  
47              run(request, response);
48          }
49          catch (ActionException ae) {
50              throw ae;
51          }
52          catch (Exception e) {
53              throw new ActionException(e);
54          }
55      }
56  
57      private HttpServletRequest _getHttpServletRequest(
58              PortletRequest portletRequest)
59          throws Exception {
60  
61          Object returnObj = PortalClassInvoker.invoke(
62              false, _getHttpServletRequestMethodKey, portletRequest);
63  
64          if (returnObj != null) {
65              return (HttpServletRequest)returnObj;
66          }
67          else {
68              return null;
69          }
70      }
71  
72      private HttpServletResponse _getHttpServletResponse(
73              PortletResponse portletResponse)
74          throws Exception {
75  
76          Object returnObj = PortalClassInvoker.invoke(
77              false, _getHttpServletResponseMethodKey, portletResponse);
78  
79          if (returnObj != null) {
80              return (HttpServletResponse)returnObj;
81          }
82          else {
83              return null;
84          }
85      }
86  
87      private static final String _CLASS_NAME =
88          "com.liferay.portal.util.PortalUtil";
89  
90      private static MethodKey _getHttpServletRequestMethodKey = new MethodKey(
91          _CLASS_NAME, "getHttpServletRequest", PortletRequest.class);
92      private static MethodKey _getHttpServletResponseMethodKey = new MethodKey(
93          _CLASS_NAME, "getHttpServletResponse", PortletResponse.class);
94  
95  }