001    /**
002     * Copyright (c) 2000-2013 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.struts.BaseStrutsAction;
018    import com.liferay.portal.util.ClassLoaderUtil;
019    
020    import javax.servlet.http.HttpServletRequest;
021    import javax.servlet.http.HttpServletResponse;
022    
023    import org.apache.struts.action.Action;
024    import org.apache.struts.action.ActionForm;
025    import org.apache.struts.action.ActionForward;
026    import org.apache.struts.action.ActionMapping;
027    
028    /**
029     * @author Mika Koivisto
030     */
031    public class StrutsActionAdapter extends BaseStrutsAction {
032    
033            public StrutsActionAdapter(
034                    Action action, ActionMapping actionMapping, ActionForm actionForm) {
035    
036                    _action = action;
037                    _actionMapping = actionMapping;
038                    _actionForm = actionForm;
039            }
040    
041            @Override
042            public String execute(
043                            HttpServletRequest request, HttpServletResponse response)
044                    throws Exception {
045    
046                    Thread currentThread = Thread.currentThread();
047    
048                    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
049    
050                    currentThread.setContextClassLoader(
051                            ClassLoaderUtil.getPortalClassLoader());
052    
053                    try {
054                            ActionForward actionForward = _action.execute(
055                                    _actionMapping, _actionForm, request, response);
056    
057                            if (actionForward == null) {
058                                    return null;
059                            }
060    
061                            return actionForward.getPath();
062                    }
063                    finally {
064                            currentThread.setContextClassLoader(contextClassLoader);
065                    }
066            }
067    
068            private Action _action;
069            private ActionForm _actionForm;
070            private ActionMapping _actionMapping;
071    
072    }