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