001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }