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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsp;
030:
031: import com.caucho.vfs.Path;
032:
033: import javax.servlet.ServletConfig;
034: import javax.servlet.ServletException;
035: import javax.servlet.ServletRequest;
036: import javax.servlet.ServletResponse;
037: import javax.servlet.jsp.HttpJspPage;
038: import java.io.IOException;
039:
040: /**
041: * Wraps Java JSP files using 'extends' in a page. Since a JSP file which
042: * uses 'extends' does not subclass from Page, we need to wrap it with
043: * a Page-compatible class.
044: *
045: * <p>Because it inherits from Page, the wrapped page still be recompiled
046: * when the underlying page changes.
047: */
048: class WrapperPage extends Page {
049: private HttpJspPage _child;
050: private CauchoPage _childPage;
051:
052: WrapperPage(HttpJspPage child) throws IOException {
053: _child = child;
054:
055: if (_child instanceof CauchoPage)
056: _childPage = (CauchoPage) child;
057: }
058:
059: public void init(Path path) throws ServletException {
060: if (_childPage != null)
061: _childPage.init(path);
062: }
063:
064: /**
065: * Forward the initialization to the wrapped page.
066: */
067: final public void init(ServletConfig config)
068: throws ServletException {
069: super .init(config);
070:
071: _child.init(config);
072: }
073:
074: /**
075: * Returns the underlying page.
076: */
077: public HttpJspPage getWrappedPage() {
078: return _child;
079: }
080:
081: public boolean _caucho_isModified() {
082: if (_childPage != null)
083: return _childPage._caucho_isModified();
084: else
085: return false;
086: }
087:
088: public long _caucho_lastModified() {
089: if (_childPage != null)
090: return _childPage._caucho_lastModified();
091: else
092: return 0;
093: }
094:
095: /**
096: * Forwards the request to the child page.
097: */
098: public void service(ServletRequest request, ServletResponse response)
099: throws IOException, ServletException {
100: _child.service(request, response);
101: }
102:
103: /**
104: * Forward the destruction to the wrapped page.
105: */
106: final public void destroy() {
107: try {
108: setDead();
109:
110: _child.destroy();
111: } catch (Exception e) {
112: }
113: }
114: }
|