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.taglib.util;
016    
017    import com.liferay.portal.kernel.util.WebKeys;
018    import com.liferay.taglib.servlet.PipingServletResponse;
019    
020    import java.io.IOException;
021    
022    import javax.servlet.RequestDispatcher;
023    import javax.servlet.ServletContext;
024    import javax.servlet.ServletException;
025    import javax.servlet.http.HttpServletRequest;
026    import javax.servlet.http.HttpServletResponse;
027    import javax.servlet.jsp.PageContext;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Shuyang Zhou
032     */
033    public class PortalIncludeUtil {
034    
035            public static void include(PageContext pageContext, String path)
036                    throws IOException, ServletException {
037    
038                    HttpServletRequest request =
039                            (HttpServletRequest)pageContext.getRequest();
040                    HttpServletResponse response =
041                            (HttpServletResponse)pageContext.getResponse();
042    
043                    ServletContext servletContext = (ServletContext)request.getAttribute(
044                            WebKeys.CTX);
045    
046                    RequestDispatcher requestDispatcher =
047                            servletContext.getRequestDispatcher(path);
048    
049                    requestDispatcher.include(
050                            request, new PipingServletResponse(response, pageContext.getOut()));
051            }
052    
053    }