001    /**
002     * Copyright (c) 2000-2010 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.servlet;
016    
017    import com.liferay.portal.kernel.io.unsync.UnsyncStringWriter;
018    
019    import java.io.IOException;
020    import java.io.Writer;
021    
022    import java.util.Enumeration;
023    
024    import javax.el.ELContext;
025    
026    import javax.servlet.Servlet;
027    import javax.servlet.ServletConfig;
028    import javax.servlet.ServletContext;
029    import javax.servlet.ServletException;
030    import javax.servlet.ServletRequest;
031    import javax.servlet.ServletResponse;
032    import javax.servlet.http.HttpSession;
033    import javax.servlet.jsp.ErrorData;
034    import javax.servlet.jsp.JspWriter;
035    import javax.servlet.jsp.PageContext;
036    import javax.servlet.jsp.tagext.BodyContent;
037    
038    /**
039     * @author Brian Wing Shun Chan
040     * @author Shuyang Zhou
041     */
042    public class PageContextWrapper extends PageContext {
043    
044            public PageContextWrapper(PageContext pageContext) {
045                    _pageContext = pageContext;
046            }
047    
048            public Object findAttribute(String name) {
049                    return _pageContext.findAttribute(name);
050            }
051    
052            public void forward(String relativeUrlPath)
053                    throws IOException, ServletException {
054    
055                    _pageContext.forward(relativeUrlPath);
056            }
057    
058            public Object getAttribute(String name) {
059                    return _pageContext.getAttribute(name);
060            }
061    
062            public Object getAttribute(String name, int scope) {
063                    return _pageContext.getAttribute(name, scope);
064            }
065    
066            public Enumeration<String> getAttributeNamesInScope(int scope) {
067                    return _pageContext.getAttributeNamesInScope(scope);
068            }
069    
070            public int getAttributesScope(String name) {
071                    return _pageContext.getAttributesScope(name);
072            }
073    
074            public ELContext getELContext() {
075                    return _pageContext.getELContext();
076            }
077    
078            public ErrorData getErrorData() {
079                    return super.getErrorData();
080            }
081    
082            public Exception getException() {
083                    return _pageContext.getException();
084            }
085    
086            /**
087             * @deprecated
088             */
089            public javax.servlet.jsp.el.ExpressionEvaluator getExpressionEvaluator() {
090                    return _pageContext.getExpressionEvaluator();
091            }
092    
093            public JspWriter getOut() {
094                    return new PipingJspWriter(_pageContext.getOut());
095            }
096    
097            public Object getPage() {
098                    return _pageContext.getPage();
099            }
100    
101            public ServletRequest getRequest() {
102                    return _pageContext.getRequest();
103            }
104    
105            public ServletResponse getResponse() {
106                    return _pageContext.getResponse();
107            }
108    
109            public ServletConfig getServletConfig() {
110                    return _pageContext.getServletConfig();
111            }
112    
113            public ServletContext getServletContext() {
114                    return _pageContext.getServletContext();
115            }
116    
117            public HttpSession getSession() {
118                    return _pageContext.getSession();
119            }
120    
121            /**
122             * @deprecated
123             */
124            public javax.servlet.jsp.el.VariableResolver getVariableResolver() {
125                    return _pageContext.getVariableResolver();
126            }
127    
128            public PageContext getWrappedPageContext() {
129                    return _pageContext;
130            }
131    
132            public void handlePageException(Exception e)
133                    throws IOException, ServletException {
134    
135                    _pageContext.handlePageException(e);
136            }
137    
138            public void handlePageException(Throwable t)
139                    throws IOException, ServletException {
140    
141                    _pageContext.handlePageException(t);
142            }
143    
144            public void include(String relativeUrlPath)
145                    throws IOException, ServletException {
146    
147                    _pageContext.include(relativeUrlPath);
148            }
149    
150            public void include(String relativeUrlPath, boolean flush)
151                    throws IOException, ServletException {
152    
153                    _pageContext.include(relativeUrlPath, flush);
154            }
155    
156            public void initialize(
157                            Servlet servlet, ServletRequest request, ServletResponse response,
158                            String errorPageURL, boolean needsSession, int bufferSize,
159                            boolean autoFlush)
160                    throws IllegalArgumentException, IllegalStateException, IOException {
161    
162                    _pageContext.initialize(
163                            servlet, request, response, errorPageURL, needsSession, bufferSize,
164                            autoFlush);
165            }
166    
167            public JspWriter popBody() {
168                    return _pageContext.popBody();
169            }
170    
171            public BodyContent pushBody() {
172                    UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();
173    
174                    BodyContent bodyContent = (BodyContent)_pageContext.pushBody(
175                            unsyncStringWriter);
176    
177                    return new BodyContentWrapper(bodyContent, unsyncStringWriter);
178            }
179    
180            public JspWriter pushBody(Writer writer) {
181                    return _pageContext.pushBody(new PipingJspWriter(writer));
182            }
183    
184            public void release() {
185                    _pageContext.release();
186            }
187    
188            public void removeAttribute(String name) {
189                    _pageContext.removeAttribute(name);
190            }
191    
192            public void removeAttribute(String name, int scope) {
193                    _pageContext.removeAttribute(name, scope);
194            }
195    
196            public void setAttribute(String name, Object value) {
197                    _pageContext.setAttribute(name, value);
198            }
199    
200            public void setAttribute(String name, Object value, int scope) {
201                    _pageContext.setAttribute(name, value, scope);
202            }
203    
204            private PageContext _pageContext;
205    
206    }