001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jsp;
031:
032: import com.caucho.log.Log;
033: import com.caucho.server.connection.CauchoResponse;
034: import com.caucho.server.webapp.WebApp;
035: import com.caucho.util.FreeList;
036: import com.caucho.util.L10N;
037:
038: import javax.servlet.ServletConfig;
039: import javax.servlet.ServletContext;
040: import javax.servlet.ServletRequest;
041: import javax.servlet.ServletResponse;
042: import javax.servlet.http.HttpServletRequest;
043: import javax.servlet.http.HttpSession;
044: import javax.servlet.jsp.ErrorData;
045: import javax.servlet.jsp.JspContext;
046: import javax.servlet.jsp.JspWriter;
047: import javax.servlet.jsp.el.ExpressionEvaluator;
048: import javax.servlet.jsp.tagext.BodyContent;
049: import java.io.IOException;
050: import java.io.PrintWriter;
051: import java.io.Writer;
052: import java.util.logging.Logger;
053:
054: public class PageContextWrapper extends PageContextImpl {
055: private static final Logger log = Logger
056: .getLogger(PageContextWrapper.class.getName());
057: static final L10N L = new L10N(PageContextWrapper.class);
058:
059: private static final FreeList<PageContextWrapper> _freeList = new FreeList<PageContextWrapper>(
060: 32);
061:
062: private PageContextImpl _parent;
063:
064: public static PageContextWrapper create(JspContext parent) {
065: PageContextWrapper wrapper = _freeList.allocate();
066: if (wrapper == null)
067: wrapper = new PageContextWrapper();
068:
069: wrapper.init((PageContextImpl) parent);
070:
071: return wrapper;
072: }
073:
074: public void init(PageContextImpl parent) {
075: super .init();
076:
077: _parent = parent;
078: clearAttributes();
079: setOut(parent.getOut());
080: _isFilled = true;
081: }
082:
083: /**
084: * Returns the underlying servlet for the page.
085: */
086: public Object getPage() {
087: return _parent.getPage();
088: }
089:
090: /**
091: * Returns the servlet request for the page.
092: */
093: public ServletRequest getRequest() {
094: return _parent.getRequest();
095: }
096:
097: /**
098: * Returns the servlet response for the page.
099: */
100: public ServletResponse getResponse() {
101: return _parent.getResponse();
102: }
103:
104: /**
105: * Returns the servlet response for the page.
106: */
107: public HttpServletRequest getCauchoRequest() {
108: return _parent.getCauchoRequest();
109: }
110:
111: /**
112: * Returns the servlet response for the page.
113: */
114: public CauchoResponse getCauchoResponse() {
115: return _parent.getCauchoResponse();
116: }
117:
118: public HttpSession getSession() {
119: return _parent.getSession();
120: }
121:
122: public ServletConfig getServletConfig() {
123: return _parent.getServletConfig();
124: }
125:
126: /**
127: * Returns the page's servlet context.
128: */
129: public ServletContext getServletContext() {
130: return _parent.getServletContext();
131: }
132:
133: /**
134: * Returns the page's application.
135: */
136: public WebApp getApplication() {
137: return _parent.getApplication();
138: }
139:
140: /**
141: * Returns the page's error page.
142: */
143: public String getErrorPage() {
144: return _parent.getErrorPage();
145: }
146:
147: /**
148: * Sets the page's error page.
149: */
150: public void setErrorPage(String errorPage) {
151: _parent.setErrorPage(errorPage);
152: }
153:
154: /**
155: * Returns the Throwable stored by the error page.
156: */
157: public Throwable getThrowable() {
158: return _parent.getThrowable();
159: }
160:
161: /**
162: * Returns the error data
163: */
164: public ErrorData getErrorData() {
165: return _parent.getErrorData();
166: }
167:
168: /**
169: * Returns the variable resolver
170: */
171: public javax.servlet.jsp.el.VariableResolver getVariableResolver() {
172: return _parent.getVariableResolver();
173: }
174:
175: /**
176: * Returns the current out.
177: */
178: public JspWriter getOut() {
179: return _parent.getOut();
180: }
181:
182: /**
183: * Pushes the page body.
184: */
185: public BodyContent pushBody() {
186: return _parent.pushBody();
187: }
188:
189: /**
190: * Pushes the page body.
191: */
192: public JspWriter pushBody(Writer out) {
193: return _parent.pushBody(out);
194: }
195:
196: /**
197: * Pops the BodyContent from the JspWriter stack.
198: *
199: * @return the enclosing writer
200: */
201: public JspWriter popAndReleaseBody() throws IOException {
202: return _parent.popAndReleaseBody();
203: }
204:
205: /**
206: * Pops the page body.
207: */
208: public JspWriter popBody() {
209: return _parent.popBody();
210: }
211:
212: public void releaseBody(BodyContentImpl out) throws IOException {
213: _parent.releaseBody(out);
214: }
215:
216: /**
217: * Pops the BodyContent from the JspWriter stack.
218: *
219: * @param oldWriter the old writer
220: */
221: public JspWriter setWriter(JspWriter oldWriter) {
222: return _parent.setWriter(oldWriter);
223: }
224:
225: /**
226: * Returns the top writer.
227: */
228: public PrintWriter getTopWriter() throws IOException {
229: return _parent.getTopWriter();
230: }
231:
232: /**
233: * Returns the expression evaluator
234: */
235: public ExpressionEvaluator getExpressionEvaluator() {
236: return _parent.getExpressionEvaluator();
237: }
238:
239: public static void free(PageContextWrapper wrapper) {
240: _freeList.free(wrapper);
241: }
242: }
|