001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: // ====================================================================
021: //
022: // The Apache Software License, Version 1.1
023: //
024: // Copyright (c) 1999 The Apache Software Foundation. All rights
025: // reserved.
026: //
027: // Redistribution and use in source and binary forms, with or without
028: // modification, are permitted provided that the following conditions
029: // are met:
030: //
031: // 1. Redistributions of source code must retain the above copyright
032: // notice, this list of conditions and the following disclaimer.
033: //
034: // 2. Redistributions in binary form must reproduce the above copyright
035: // notice, this list of conditions and the following disclaimer in
036: // the documentation and/or other materials provided with the
037: // distribution.
038: //
039: // 3. The end-user documentation included with the redistribution, if
040: // any, must include the following acknowlegement:
041: // "This product includes software developed by the
042: // Apache Software Foundation (http://www.apache.org/)."
043: // Alternately, this acknowlegement may appear in the software itself,
044: // if and wherever such third-party acknowlegements normally appear.
045: //
046: // 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
047: // Foundation" must not be used to endorse or promote products derived
048: // from this software without prior written permission. For written
049: // permission, please contact apache@apache.org.
050: //
051: // 5. Products derived from this software may not be called "Apache"
052: // nor may "Apache" appear in their names without prior written
053: // permission of the Apache Group.
054: //
055: // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
056: // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
057: // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
058: // DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
059: // ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
060: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
061: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
062: // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
063: // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
064: // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
065: // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
066: // SUCH DAMAGE.
067: // ====================================================================
068: //
069: // This software consists of voluntary contributions made by many
070: // individuals on behalf of the Apache Software Foundation. For more
071: // information on the Apache Software Foundation, please see
072: // <http://www.apache.org/>.
073:
074: package com.salmonllc.jsp.engine;
075:
076: /////////////////////////
077: //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/engine/JspFactoryImpl.java $
078: //$Author: Dan $
079: //$Revision: 15 $
080: //$Modtime: 9/22/04 10:34a $
081: /////////////////////////
082: import javax.servlet.jsp.*;
083: import javax.servlet.http.*;
084:
085: import com.salmonllc.html.HttpServletResponseDummy;
086: import com.salmonllc.jsp.*;
087: import com.salmonllc.jsp.tags.PageTag;
088:
089: /**
090: * This class is an implementation of the J2EE JSP factory.
091: * It is used by the JSPServlet to facilitate multiple passes
092: * through the _jspservice method when a salmon JSP is initialized
093: */
094: public class JspFactoryImpl extends JspFactory {
095: JspFactory _realFactory = null;
096:
097: /**
098: * Creates a new JSPFactory.
099: * @param realFactory The real factory used by the J2EE Engine
100: */
101: public JspFactoryImpl(JspFactory realFactory) {
102: super ();
103: _realFactory = realFactory;
104:
105: }
106:
107: /**
108: * Returns information on the J2EE Engine
109: */
110: public javax.servlet.jsp.JspEngineInfo getEngineInfo() {
111: return _realFactory.getEngineInfo();
112: }
113:
114: /**
115: * Creates a new page context
116: */
117: public javax.servlet.jsp.PageContext getPageContext(
118: javax.servlet.Servlet arg1,
119: javax.servlet.ServletRequest arg2,
120: javax.servlet.ServletResponse arg3, String arg4,
121: boolean arg5, int arg6, boolean arg7) {
122: boolean isInitializing = true;
123: boolean isContextSalmon = (arg1 instanceof com.salmonllc.jsp.JspServlet);
124: HttpServletRequest req = (HttpServletRequest) arg2;
125:
126: String sessID = req
127: .getParameter(PageTag.getSessionIdentifier());
128: HttpSession sess = PageTag.getSession(sessID);
129: if (sess == null)
130: sess = req.getSession(false);
131: JspController cont = null;
132: if (sess != null) {
133: cont = (JspController) sess.getAttribute("$jsp$"
134: + com.salmonllc.jsp.tags.PageTag
135: .generateSessionName(req));
136: if (cont != null) {
137: isInitializing = cont.isInitializing();
138: if (cont.getPageContext() != null)
139: isContextSalmon = (cont.getPageContext()
140: .getResponse() instanceof HttpServletResponseDummy);
141: }
142: }
143:
144: if (isInitializing && isContextSalmon)
145: return _realFactory.getPageContext(arg1, arg2,
146: new HttpServletResponseDummy(
147: (HttpServletResponse) arg3, cont), arg4,
148: arg5, arg6, arg7);
149: else
150: return _realFactory.getPageContext(arg1, arg2, arg3, arg4,
151: arg5, arg6, arg7);
152:
153: }
154:
155: /**
156: * Frees the resources used by a page context object
157: */
158: public void releasePageContext(javax.servlet.jsp.PageContext arg1) {
159: if (!(arg1 instanceof com.salmonllc.jsp.engine.PageContextImpl))
160: _realFactory.releasePageContext(arg1);
161: else
162: ((com.salmonllc.jsp.engine.PageContextImpl) arg1).release();
163: }
164:
165: /**
166: * Resets the factory to the real one for the J2EE engine
167: */
168: public void resetFactory() {
169: JspFactory.setDefaultFactory(_realFactory);
170: }
171: }
|