| PortalIncludeUtil.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.portal.kernel.servlet;
16
17 import com.liferay.portal.kernel.util.WebKeys;
18
19 import java.io.IOException;
20
21 import javax.servlet.RequestDispatcher;
22 import javax.servlet.ServletContext;
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import javax.servlet.jsp.PageContext;
27
28 /**
29 * <a href="PortalIncludeUtil.java.html"><b><i>View Source</i></b></a>
30 *
31 * @author Brian Wing Shun Chan
32 * @author Shuyang Zhou
33 */
34 public class PortalIncludeUtil {
35
36 public static void include(PageContext pageContext, String path)
37 throws IOException, ServletException {
38
39 HttpServletRequest request =
40 (HttpServletRequest)pageContext.getRequest();
41 HttpServletResponse response =
42 (HttpServletResponse)pageContext.getResponse();
43
44 ServletContext servletContext = (ServletContext)request.getAttribute(
45 WebKeys.CTX);
46
47 RequestDispatcher requestDispatcher =
48 servletContext.getRequestDispatcher(path);
49
50 requestDispatcher.include(
51 request, new PipingServletResponse(response, pageContext.getOut()));
52 }
53
54 }