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.struts;
16  
17  import com.liferay.portal.kernel.util.InstancePool;
18  
19  import javax.portlet.ActionRequest;
20  import javax.portlet.ActionResponse;
21  import javax.portlet.PortletConfig;
22  import javax.portlet.PortletRequest;
23  import javax.portlet.RenderRequest;
24  import javax.portlet.RenderResponse;
25  
26  import org.apache.struts.action.ActionForm;
27  import org.apache.struts.action.ActionForward;
28  import org.apache.struts.action.ActionMapping;
29  import org.apache.struts.config.ModuleConfig;
30  
31  /**
32   * <a href="DynamicPortletAction.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class DynamicPortletAction extends PortletAction {
37  
38      public void processAction(
39              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
40              ActionRequest actionRequest, ActionResponse actionResponse)
41          throws Exception {
42  
43          ModuleConfig moduleConfig = getModuleConfig(actionRequest);
44  
45          mapping = (ActionMapping)moduleConfig.findActionConfig(
46              getPath(actionRequest));
47  
48          PortletAction action = (PortletAction)InstancePool.get(
49              mapping.getType());
50  
51          action.processAction(
52              mapping, form, portletConfig, actionRequest, actionResponse);
53      }
54  
55      public ActionForward render(
56              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
57              RenderRequest renderRequest, RenderResponse renderResponse)
58          throws Exception {
59  
60          ModuleConfig moduleConfig = getModuleConfig(renderRequest);
61  
62          mapping = (ActionMapping)moduleConfig.findActionConfig(
63              getPath(renderRequest));
64  
65          PortletAction action = (PortletAction)InstancePool.get(
66              mapping.getType());
67  
68          return action.render(
69              mapping, form, portletConfig, renderRequest, renderResponse);
70      }
71  
72      protected String getPath(PortletRequest portletRequest) throws Exception {
73          return null;
74      }
75  
76  }