1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.events;
16  
17  import com.liferay.portal.kernel.util.PortalClassInvoker;
18  
19  import javax.portlet.PortletRequest;
20  import javax.portlet.PortletResponse;
21  import javax.portlet.RenderRequest;
22  import javax.portlet.RenderResponse;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletResponse;
26  
27  /**
28   * <a href="Action.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public abstract class Action {
33  
34      public abstract void run(
35              HttpServletRequest request, HttpServletResponse response)
36          throws ActionException;
37  
38      public void run(RenderRequest renderRequest, RenderResponse renderResponse)
39          throws ActionException {
40  
41          try {
42              HttpServletRequest request = _getHttpServletRequest(renderRequest);
43              HttpServletResponse response = _getHttpServletResponse(
44                  renderResponse);
45  
46              run(request, response);
47          }
48          catch (ActionException ae) {
49              throw ae;
50          }
51          catch (Exception e) {
52              throw new ActionException(e);
53          }
54      }
55  
56      private HttpServletRequest _getHttpServletRequest(
57              PortletRequest portletRequest)
58          throws Exception {
59  
60          Object returnObj = PortalClassInvoker.invoke(
61              _CLASS, _METHOD_GETHTTPSERVLETREQUEST, portletRequest, false);
62  
63          if (returnObj != null) {
64              return (HttpServletRequest)returnObj;
65          }
66          else {
67              return null;
68          }
69      }
70  
71      private HttpServletResponse _getHttpServletResponse(
72              PortletResponse portletResponse)
73          throws Exception {
74  
75          Object returnObj = PortalClassInvoker.invoke(
76              _CLASS, _METHOD_GETHTTPSERVLETRESPONSE, portletResponse, false);
77  
78          if (returnObj != null) {
79              return (HttpServletResponse)returnObj;
80          }
81          else {
82              return null;
83          }
84      }
85  
86      private static final String _CLASS = "com.liferay.portal.util.PortalUtil";
87  
88      private static final String _METHOD_GETHTTPSERVLETREQUEST =
89          "getHttpServletRequest";
90  
91      private static final String _METHOD_GETHTTPSERVLETRESPONSE =
92          "getHttpServletResponse";
93  
94  }