001    /**
002     * Copyright (c) 2000-2012 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 mapping, ActionForm form, PortletConfig portletConfig,
039                            ActionRequest actionRequest, ActionResponse actionResponse)
040                    throws Exception {
041    
042                    ModuleConfig moduleConfig = getModuleConfig(actionRequest);
043    
044                    mapping = (ActionMapping)moduleConfig.findActionConfig(
045                            getPath(actionRequest));
046    
047                    PortletAction action = (PortletAction)InstancePool.get(
048                            mapping.getType());
049    
050                    action.processAction(
051                            mapping, form, portletConfig, actionRequest, actionResponse);
052            }
053    
054            @Override
055            public ActionForward render(
056                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
057                            RenderRequest renderRequest, RenderResponse renderResponse)
058                    throws Exception {
059    
060                    ModuleConfig moduleConfig = getModuleConfig(renderRequest);
061    
062                    mapping = (ActionMapping)moduleConfig.findActionConfig(
063                            getPath(renderRequest));
064    
065                    PortletAction action = (PortletAction)InstancePool.get(
066                            mapping.getType());
067    
068                    return action.render(
069                            mapping, form, portletConfig, renderRequest, renderResponse);
070            }
071    
072            protected String getPath(PortletRequest portletRequest) throws Exception {
073                    return null;
074            }
075    
076    }