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.servlet;
016    
017    import com.liferay.portal.kernel.util.WebKeys;
018    
019    import java.io.IOException;
020    
021    import javax.servlet.RequestDispatcher;
022    import javax.servlet.ServletException;
023    import javax.servlet.ServletRequest;
024    import javax.servlet.ServletResponse;
025    
026    /**
027     * @author Shuyang Zhou
028     */
029    public class DirectServletPathRegisterDispatcher implements RequestDispatcher {
030    
031            public DirectServletPathRegisterDispatcher(
032                    String path, RequestDispatcher requestDispatcher) {
033    
034                    _path = path;
035                    _requestDispatcher = requestDispatcher;
036            }
037    
038            @Override
039            public void forward(
040                            ServletRequest servletRequest, ServletResponse servletResponse)
041                    throws IOException, ServletException {
042    
043                    servletRequest.setAttribute(WebKeys.SERVLET_PATH, _path);
044    
045                    _requestDispatcher.forward(servletRequest, servletResponse);
046            }
047    
048            @Override
049            public void include(
050                            ServletRequest servletRequest, ServletResponse servletResponse)
051                    throws IOException, ServletException {
052    
053                    servletRequest.setAttribute(WebKeys.SERVLET_PATH, _path);
054    
055                    _requestDispatcher.include(servletRequest, servletResponse);
056            }
057    
058            private String _path;
059            private RequestDispatcher _requestDispatcher;
060    
061    }