001: /*
002: * ========================================================================
003: *
004: * Copyright 2001-2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.server;
021:
022: import java.io.IOException;
023:
024: import java.util.Enumeration;
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.HttpServletRequest;
033: import javax.servlet.http.HttpSession;
034: import javax.servlet.jsp.JspWriter;
035: import javax.servlet.jsp.PageContext;
036: import javax.servlet.jsp.tagext.BodyContent;
037:
038: import org.apache.cactus.ServletURL;
039:
040: /**
041: * Abstract wrapper around <code>PageContext</code>. This class provides
042: * a common implementation of the wrapper for the different servlet API.
043: *
044: * @version $Id: AbstractPageContextWrapper.java 239136 2005-02-01 08:54:44Z vmassol $
045: */
046: public abstract class AbstractPageContextWrapper extends PageContext {
047: /**
048: * The real page context
049: */
050: protected PageContext originalPageContext;
051:
052: /**
053: * The URL to simulate
054: */
055: protected ServletURL url;
056:
057: /**
058: * Construct an <code>PageContext</code> instance that delegates
059: * it's method calls to the page context object passed as parameter and
060: * that uses the URL passed as parameter to simulate a URL from which
061: * the request would come from.
062: *
063: * @param theOriginalPageContext the real page context
064: * @param theURL the URL to simulate or <code>null</code> if none
065: */
066: public AbstractPageContextWrapper(
067: PageContext theOriginalPageContext, ServletURL theURL) {
068: this .originalPageContext = theOriginalPageContext;
069: this .url = theURL;
070: }
071:
072: // New methods ---------------------------------------------------------
073:
074: /**
075: * @return the original page context
076: * @since 1.7
077: */
078: public PageContext getOriginalPageContext() {
079: return this .originalPageContext;
080: }
081:
082: // Modified overridden methods -------------------------------------------
083:
084: /**
085: * @return the Cactus wrapped servlet request that knows about the
086: * simulated URL
087: */
088: public ServletRequest getRequest() {
089: // Note: we only manage HttpServletRequest here
090: return new HttpServletRequestWrapper(
091: (HttpServletRequest) this .originalPageContext
092: .getRequest(), this .url);
093: }
094:
095: /**
096: * @return the Cactus wrapped servlet config
097: */
098: public ServletConfig getServletConfig() {
099: return new ServletConfigWrapper(this .originalPageContext
100: .getServletConfig());
101: }
102:
103: /**
104: * @return the Cactus wrapped servlet context
105: */
106: public ServletContext getServletContext() {
107: return new ServletContextWrapper(this .originalPageContext
108: .getServletContext());
109: }
110:
111: // Unmodified overridden methods -----------------------------------------
112:
113: /**
114: * @see PageContext#findAttribute(String)
115: */
116: public Object findAttribute(String theName) {
117: return this .originalPageContext.findAttribute(theName);
118: }
119:
120: /**
121: * @see PageContext#forward(String)
122: */
123: public void forward(String theRelativeURLPath)
124: throws ServletException, IOException {
125: this .originalPageContext.forward(theRelativeURLPath);
126: }
127:
128: /**
129: * @see PageContext#getAttribute(String)
130: */
131: public Object getAttribute(String theName) {
132: return this .originalPageContext.getAttribute(theName);
133: }
134:
135: /**
136: * @see PageContext#getAttribute(String, int)
137: */
138: public Object getAttribute(String theName, int theScope) {
139: return this .originalPageContext.getAttribute(theName, theScope);
140: }
141:
142: /**
143: * @see PageContext#getAttributeNamesInScope(int)
144: */
145: public Enumeration getAttributeNamesInScope(int theScope) {
146: return this .originalPageContext
147: .getAttributeNamesInScope(theScope);
148: }
149:
150: /**
151: * @see PageContext#getAttributesScope(String)
152: */
153: public int getAttributesScope(String theName) {
154: return this .originalPageContext.getAttributesScope(theName);
155: }
156:
157: /**
158: * @see PageContext#getException()
159: */
160: public Exception getException() {
161: return this .originalPageContext.getException();
162: }
163:
164: /**
165: * @see PageContext#getOut()
166: */
167: public JspWriter getOut() {
168: return this .originalPageContext.getOut();
169: }
170:
171: /**
172: * @see PageContext#getPage()
173: */
174: public Object getPage() {
175: return this .originalPageContext.getPage();
176: }
177:
178: /**
179: * @see PageContext#getResponse()
180: */
181: public ServletResponse getResponse() {
182: return this .originalPageContext.getResponse();
183: }
184:
185: /**
186: * @see PageContext#getSession()
187: */
188: public HttpSession getSession() {
189: return this .originalPageContext.getSession();
190: }
191:
192: /**
193: * @see PageContext#handlePageException(Exception)
194: */
195: public void handlePageException(Exception theException)
196: throws ServletException, IOException {
197: this .originalPageContext.handlePageException(theException);
198: }
199:
200: /**
201: * @see PageContext#include(String)
202: */
203: public void include(String theRelativeURLPath)
204: throws ServletException, IOException {
205: this .originalPageContext.include(theRelativeURLPath);
206: }
207:
208: /**
209: * @see PageContext#initialize
210: */
211: public void initialize(Servlet theServlet,
212: ServletRequest theRequest, ServletResponse theResponse,
213: String theErrorPageURL, boolean isSessionNeeded,
214: int theBufferSize, boolean isAutoFlush) throws IOException,
215: IllegalStateException, IllegalArgumentException {
216: this .originalPageContext.initialize(theServlet, theRequest,
217: theResponse, theErrorPageURL, isSessionNeeded,
218: theBufferSize, isAutoFlush);
219: }
220:
221: /**
222: * @see PageContext#popBody()
223: */
224: public JspWriter popBody() {
225: return this .originalPageContext.popBody();
226: }
227:
228: /**
229: * @see PageContext#pushBody()
230: */
231: public BodyContent pushBody() {
232: return this .originalPageContext.pushBody();
233: }
234:
235: /**
236: * @see PageContext#release()
237: */
238: public void release() {
239: this .originalPageContext.release();
240: }
241:
242: /**
243: * @see PageContext#removeAttribute(String)
244: */
245: public void removeAttribute(String theName) {
246: this .originalPageContext.removeAttribute(theName);
247: }
248:
249: /**
250: * @see PageContext#removeAttribute(String, int)
251: */
252: public void removeAttribute(String theName, int theScope) {
253: this .originalPageContext.removeAttribute(theName, theScope);
254: }
255:
256: /**
257: * @see PageContext#setAttribute(String, Object)
258: */
259: public void setAttribute(String theName, Object theAttribute) {
260: this .originalPageContext.setAttribute(theName, theAttribute);
261: }
262:
263: /**
264: * @see PageContext#setAttribute(String, Object)
265: */
266: public void setAttribute(String theName, Object theAttribute,
267: int theScope) {
268: this.originalPageContext.setAttribute(theName, theAttribute,
269: theScope);
270: }
271: }
|