001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.struts;
016    
017    import com.liferay.portal.kernel.util.InstancePool;
018    
019    import javax.portlet.ActionRequest;
020    import javax.portlet.ActionResponse;
021    import javax.portlet.PortletConfig;
022    import javax.portlet.PortletRequest;
023    import javax.portlet.RenderRequest;
024    import javax.portlet.RenderResponse;
025    
026    import org.apache.struts.action.ActionForm;
027    import org.apache.struts.action.ActionForward;
028    import org.apache.struts.action.ActionMapping;
029    import org.apache.struts.config.ModuleConfig;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class DynamicPortletAction extends PortletAction {
035    
036            @Override
037            public void processAction(
038                            ActionMapping actionMapping, ActionForm actionForm,
039                            PortletConfig portletConfig, ActionRequest actionRequest,
040                            ActionResponse actionResponse)
041                    throws Exception {
042    
043                    ModuleConfig moduleConfig = getModuleConfig(actionRequest);
044    
045                    actionMapping = (ActionMapping)moduleConfig.findActionConfig(
046                            getPath(actionRequest));
047    
048                    PortletAction action = (PortletAction)InstancePool.get(
049                            actionMapping.getType());
050    
051                    action.processAction(
052                            actionMapping, actionForm, portletConfig, actionRequest,
053                            actionResponse);
054            }
055    
056            @Override
057            public ActionForward render(
058                            ActionMapping actionMapping, ActionForm actionForm,
059                            PortletConfig portletConfig, RenderRequest renderRequest,
060                            RenderResponse renderResponse)
061                    throws Exception {
062    
063                    ModuleConfig moduleConfig = getModuleConfig(renderRequest);
064    
065                    actionMapping = (ActionMapping)moduleConfig.findActionConfig(
066                            getPath(renderRequest));
067    
068                    PortletAction action = (PortletAction)InstancePool.get(
069                            actionMapping.getType());
070    
071                    return action.render(
072                            actionMapping, actionForm, portletConfig, renderRequest,
073                            renderResponse);
074            }
075    
076            protected String getPath(PortletRequest portletRequest) throws Exception {
077                    return null;
078            }
079    
080    }