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.server.webapp.WebApp;
033: import com.caucho.util.FreeList;
034:
035: import javax.servlet.Servlet;
036: import javax.servlet.ServletContext;
037: import javax.servlet.ServletRequest;
038: import javax.servlet.ServletResponse;
039: import javax.servlet.http.HttpSession;
040: import javax.servlet.jsp.JspApplicationContext;
041: import javax.servlet.jsp.JspEngineInfo;
042: import javax.servlet.jsp.JspFactory;
043: import javax.servlet.jsp.PageContext;
044:
045: public class QJspFactory extends JspFactory {
046: private static JspEngineInfo _engineInfo = new EngineInfo();
047:
048: private static FreeList<PageContextImpl> _freePages = new FreeList<PageContextImpl>(
049: 256);
050:
051: private static QJspFactory _factory;
052:
053: static public QJspFactory create() {
054: if (_factory == null)
055: _factory = new QJspFactory();
056:
057: return _factory;
058: }
059:
060: public static PageContextImpl allocatePageContext(Servlet servlet,
061: ServletRequest request, ServletResponse response,
062: String errorPageURL, boolean needsSession, int buffer,
063: boolean autoFlush) {
064: PageContextImpl pc = _freePages.allocate();
065: if (pc == null)
066: pc = new PageContextImpl();
067:
068: try {
069: pc.initialize(servlet, request, response, errorPageURL,
070: needsSession, buffer, autoFlush);
071: } catch (Exception e) {
072: }
073:
074: return pc;
075: }
076:
077: /**
078: * The jsp page context initialization.
079: */
080: public static PageContextImpl allocatePageContext(Servlet servlet,
081: WebApp app, ServletRequest request,
082: ServletResponse response, String errorPageURL,
083: HttpSession session, int buffer, boolean autoFlush,
084: boolean isPrintNullAsBlank) {
085: PageContextImpl pc = _freePages.allocate();
086: if (pc == null)
087: pc = new PageContextImpl();
088:
089: pc.initialize(servlet, app, request, response, errorPageURL,
090: session, buffer, autoFlush, isPrintNullAsBlank);
091:
092: return pc;
093: }
094:
095: public PageContext getPageContext(Servlet servlet,
096: ServletRequest request, ServletResponse response,
097: String errorPageURL, boolean needsSession, int buffer,
098: boolean autoFlush) {
099: return allocatePageContext(servlet, request, response,
100: errorPageURL, needsSession, buffer, autoFlush);
101: }
102:
103: /**
104: * Frees a page context after the JSP page is done with it.
105: *
106: * @param pc the PageContext to free
107: */
108: public void releasePageContext(PageContext pc) {
109: if (pc != null) {
110: pc.release();
111:
112: if (pc instanceof PageContextImpl)
113: _freePages.free((PageContextImpl) pc);
114: }
115: }
116:
117: public static void freePageContext(PageContext pc) {
118: if (pc != null) {
119: pc.release();
120:
121: if (pc instanceof PageContextImpl)
122: _freePages.free((PageContextImpl) pc);
123: }
124: }
125:
126: // This doesn't appear in the spec, but apparantly exists in some jsdk.jar
127: public String getSpecificationVersion() {
128: return getEngineInfo().getSpecificationVersion();
129: }
130:
131: public JspEngineInfo getEngineInfo() {
132: return _engineInfo;
133: }
134:
135: public JspApplicationContext getJspApplicationContext(
136: ServletContext context) {
137: return ((WebApp) context).getJspApplicationContext();
138: }
139:
140: static class EngineInfo extends JspEngineInfo {
141: public String getSpecificationVersion() {
142: return "2.1";
143: }
144: }
145: }
|