001    /**
002     * Copyright (c) 2000-2011 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            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    }