001: /*
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright (c) 1999 The Apache Software Foundation. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution, if
020: * any, must include the following acknowlegement:
021: * "This product includes software developed by the
022: * Apache Software Foundation (http://www.apache.org/)."
023: * Alternately, this acknowlegement may appear in the software itself,
024: * if and wherever such third-party acknowlegements normally appear.
025: *
026: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
027: * Foundation" must not be used to endorse or promote products derived
028: * from this software without prior written permission. For written
029: * permission, please contact apache@apache.org.
030: *
031: * 5. Products derived from this software may not be called "Apache"
032: * nor may "Apache" appear in their names without prior written
033: * permission of the Apache Group.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: *
049: * This software consists of voluntary contributions made by many
050: * individuals on behalf of the Apache Software Foundation. For more
051: * information on the Apache Software Foundation, please see
052: * <http://www.apache.org/>.
053: *
054: */
055: package com.rimfaxe.webserver.runtime;
056:
057: import javax.servlet.Servlet;
058: import javax.servlet.ServletRequest;
059: import javax.servlet.ServletResponse;
060:
061: import javax.servlet.jsp.JspFactory;
062: import javax.servlet.jsp.JspEngineInfo;
063: import javax.servlet.jsp.PageContext;
064:
065: import java.security.AccessController;
066: import java.security.PrivilegedAction;
067:
068: /**
069: * Implementation of JspFactory from the spec. Helps create
070: * PageContext and other animals.
071: *
072: * @author Anil K. Vijendran
073: */
074: public class JspFactoryImpl extends JspFactory {
075:
076: protected class PrivilegedGetPageContext implements
077: PrivilegedAction {
078: private JspFactoryImpl factory;
079: private Servlet servlet;
080: private ServletRequest request;
081: private ServletResponse response;
082: private String errorPageURL;
083: private boolean needsSession;
084: private int bufferSize;
085: private boolean autoflush;
086:
087: PrivilegedGetPageContext(JspFactoryImpl factory,
088: Servlet servlet, ServletRequest request,
089: ServletResponse response, String errorPageURL,
090: boolean needsSession, int bufferSize, boolean autoflush) {
091: this .factory = factory;
092: this .servlet = servlet;
093: this .request = request;
094: this .response = response;
095: this .errorPageURL = errorPageURL;
096: this .needsSession = needsSession;
097: this .bufferSize = bufferSize;
098: this .autoflush = autoflush;
099: }
100:
101: public Object run() {
102: return factory.internalGetPageContext(servlet, request,
103: response, errorPageURL, needsSession, bufferSize,
104: autoflush);
105: }
106: }
107:
108: protected class PrivilegedReleasePageContext implements
109: PrivilegedAction {
110: private JspFactoryImpl factory;
111: private PageContext pageContext;
112:
113: PrivilegedReleasePageContext(JspFactoryImpl factory,
114: PageContext pageContext) {
115: this .factory = factory;
116: this .pageContext = pageContext;
117: }
118:
119: public Object run() {
120: factory.internalReleasePageContext(pageContext);
121: return null;
122: }
123: }
124:
125: private SimplePool pool = new SimplePool(100);
126: private static final boolean usePool = true;
127:
128: public PageContext getPageContext(Servlet servlet,
129: ServletRequest request, ServletResponse response,
130: String errorPageURL, boolean needsSession, int bufferSize,
131: boolean autoflush) {
132:
133: return internalGetPageContext(servlet, request, response,
134: errorPageURL, needsSession, bufferSize, autoflush);
135:
136: }
137:
138: protected PageContext internalGetPageContext(Servlet servlet,
139: ServletRequest request, ServletResponse response,
140: String errorPageURL, boolean needsSession, int bufferSize,
141: boolean autoflush) {
142: try {
143: PageContext pc;
144: if (usePool) {
145: pc = (PageContextImpl) pool.get();
146: if (pc == null) {
147: pc = new PageContextImpl(this );
148: }
149: } else {
150: pc = new PageContextImpl(this );
151: }
152: pc.initialize(servlet, request, response, errorPageURL,
153: needsSession, bufferSize, autoflush);
154: return pc;
155: } catch (Throwable ex) {
156: /* FIXME: need to do something reasonable here!! */
157:
158: return null;
159: }
160: }
161:
162: public void releasePageContext(PageContext pc) {
163: if (pc == null)
164: return;
165: if (System.getSecurityManager() != null) {
166: PrivilegedReleasePageContext dp = new PrivilegedReleasePageContext(
167: (JspFactoryImpl) this , pc);
168: AccessController.doPrivileged(dp);
169: } else {
170: internalReleasePageContext(pc);
171: }
172: }
173:
174: private void internalReleasePageContext(PageContext pc) {
175: pc.release();
176: if (usePool) {
177: pool.put(pc);
178: }
179: }
180:
181: static class SunJspEngineInfo extends JspEngineInfo {
182:
183: final static String SpecificationVersion = "1.2";
184:
185: public String getSpecificationVersion() {
186: return SpecificationVersion;
187: }
188: }
189:
190: static JspEngineInfo info = new SunJspEngineInfo();
191:
192: public JspEngineInfo getEngineInfo() {
193: return info;
194: }
195: }
|