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.struts.BaseStrutsPortletAction;
018    
019    import javax.portlet.ActionRequest;
020    import javax.portlet.ActionResponse;
021    import javax.portlet.PortletConfig;
022    import javax.portlet.RenderRequest;
023    import javax.portlet.RenderResponse;
024    import javax.portlet.ResourceRequest;
025    import javax.portlet.ResourceResponse;
026    
027    import org.apache.struts.action.ActionForm;
028    import org.apache.struts.action.ActionForward;
029    import org.apache.struts.action.ActionMapping;
030    
031    /**
032     * @author Mika Koivisto
033     */
034    public class StrutsPortletActionAdapter extends BaseStrutsPortletAction {
035    
036            public StrutsPortletActionAdapter(
037                    PortletAction portletAction, ActionMapping actionMapping,
038                    ActionForm actionForm) {
039    
040                    _portletAction = portletAction;
041                    _actionMapping = actionMapping;
042                    _actionForm = actionForm;
043            }
044    
045            @Override
046            public void processAction(
047                            PortletConfig portletConfig, ActionRequest actionRequest,
048                            ActionResponse actionResponse)
049                    throws Exception {
050    
051                    _portletAction.processAction(
052                            _actionMapping, _actionForm, portletConfig, actionRequest,
053                            actionResponse);
054            }
055    
056            @Override
057            public String render(
058                            PortletConfig portletConfig, RenderRequest renderRequest,
059                            RenderResponse renderResponse)
060                    throws Exception {
061    
062                    ActionForward actionForward = _portletAction.render(
063                            _actionMapping, _actionForm, portletConfig, renderRequest,
064                            renderResponse);
065    
066                    if (actionForward != null) {
067                            return actionForward.getPath();
068                    }
069    
070                    return null;
071            }
072    
073            @Override
074            public void serveResource(
075                            PortletConfig portletConfig, ResourceRequest resourceRequest,
076                            ResourceResponse resourceResponse)
077                    throws Exception {
078    
079                    _portletAction.serveResource(
080                            _actionMapping, _actionForm, portletConfig, resourceRequest,
081                            resourceResponse);
082            }
083    
084            private ActionForm _actionForm;
085            private ActionMapping _actionMapping;
086            private PortletAction _portletAction;
087    
088    }