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:
034: import javax.servlet.ServletConfig;
035: import javax.servlet.ServletException;
036: import javax.servlet.jsp.JspFactory;
037:
038: /**
039: * Handles JSP pages. Most of the work is done in the JspManager and QServlet.
040: *
041: * @see JspManager
042: */
043: public class JspServlet extends QServlet {
044: static final String COPYRIGHT = "Copyright (c) 1998-2008 Caucho Technology. All rights reserved.";
045:
046: private boolean _isXml = false;
047: private boolean _loadTldOnInit = false;
048: private int _pageCacheMax = 256;
049:
050: /**
051: * Set true when JSP pages should default to xml.
052: */
053: public void setXml(boolean isXml) {
054: _isXml = isXml;
055: }
056:
057: /**
058: * Set true when JSP pages should load tld files.
059: */
060: public void setLoadTldOnInit(boolean isPreload) {
061: _loadTldOnInit = isPreload;
062: }
063:
064: /**
065: * Set true when JSP pages should default to xml.
066: */
067: public void setPageCacheMax(int max) {
068: _pageCacheMax = max;
069: }
070:
071: /**
072: * Initializes the servlet. Primarily, this sets the PageManager to the
073: * correct JspManager.
074: */
075: public void init(ServletConfig conf) throws ServletException {
076: super .init(conf);
077:
078: JspManager manager = new JspManager();
079:
080: WebApp webApp = (WebApp) getServletContext();
081:
082: manager.setXml(_isXml);
083: manager.setLoadTldOnInit(_loadTldOnInit
084: || webApp.createJsp().isLoadTldOnInit());
085: manager.setPageCacheMax(_pageCacheMax);
086:
087: manager.initWebApp(webApp);
088:
089: setManager(manager);
090:
091: manager.init();
092:
093: if (JspFactory.getDefaultFactory() == null)
094: JspFactory.setDefaultFactory(new QJspFactory());
095: }
096:
097: /**
098: * Static initialization
099: */
100: public static void initStatic() {
101: if (JspFactory.getDefaultFactory() == null)
102: JspFactory.setDefaultFactory(new QJspFactory());
103: }
104:
105: public String getServletInfo() {
106: return "JSP";
107: }
108:
109: public String toString() {
110: return getClass().getSimpleName() + "[" + getServletContext()
111: + "]";
112: }
113: }
|