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.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  }