001    /**
002     * Copyright (c) 2000-present 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.kernel.events;
016    
017    import com.liferay.portal.util.PortalUtil;
018    
019    import javax.portlet.RenderRequest;
020    import javax.portlet.RenderResponse;
021    
022    import javax.servlet.http.HttpServletRequest;
023    import javax.servlet.http.HttpServletResponse;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public abstract class Action implements LifecycleAction {
029    
030            @Override
031            public final void processLifecycleEvent(LifecycleEvent lifecycleEvent)
032                    throws ActionException {
033    
034                    run(lifecycleEvent.getRequest(), lifecycleEvent.getResponse());
035            }
036    
037            public abstract void run(
038                            HttpServletRequest request, HttpServletResponse response)
039                    throws ActionException;
040    
041            public void run(RenderRequest renderRequest, RenderResponse renderResponse)
042                    throws ActionException {
043    
044                    try {
045                            HttpServletRequest request = PortalUtil.getHttpServletRequest(
046                                    renderRequest);
047                            HttpServletResponse response = PortalUtil.getHttpServletResponse(
048                                    renderResponse);
049    
050                            run(request, response);
051                    }
052                    catch (ActionException ae) {
053                            throw ae;
054                    }
055                    catch (Exception e) {
056                            throw new ActionException(e);
057                    }
058            }
059    
060    }