page.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 670 行 · 第 1/2 页
JAVA
670 行
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * * @author Scott Ferguson */package com.caucho.jsp;import com.caucho.jsp.cfg.JspPropertyGroup;import com.caucho.loader.Environment;import com.caucho.log.Log;import com.caucho.server.connection.CauchoResponse;import com.caucho.server.connection.ToCharResponseAdapter;import com.caucho.server.webapp.WebApp;import com.caucho.util.Alarm;import com.caucho.util.Base64;import com.caucho.util.CharBuffer;import com.caucho.util.QDate;import com.caucho.vfs.Depend;import com.caucho.vfs.Dependency;import com.caucho.vfs.Path;import com.caucho.vfs.PersistentDependency;import javax.servlet.Servlet;import javax.servlet.ServletConfig;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.lang.reflect.Method;import java.util.ArrayList;import java.util.Enumeration;import java.util.HashMap;import java.util.logging.Level;import java.util.logging.Logger;/** * Represents a compiled JSP page. */abstract public class Page implements Servlet, ServletConfig, CauchoPage { protected static final Logger _caucho_log = Log.open(Page.class); private ServletConfig _config; private WebApp _webApp; private ArrayList<PersistentDependency> _depends; private ArrayList<Depend> _cacheDepends; private String _media; protected String _contentType; protected boolean _alwaysModified; protected boolean _neverModified; private PageManager.Entry _entry; private long _lastModified; private String _lastModifiedString; private String _etag; private QDate _calendar; private long _updateInterval = Environment.getDependencyCheckInterval(); private long _lastUpdateCheck; private JspManager _jspManager; private boolean _isRecompiling = false; private int _useCount; private boolean _isDead = true; public void init(Path path) throws ServletException { } void _caucho_setContentType(String contentType) { _contentType = contentType; } void _caucho_setUpdateInterval(long updateInterval) { _updateInterval = updateInterval; } void _caucho_setJspManager(JspManager manager) { _jspManager = manager; } void _caucho_unload() { if (_jspManager != null) _jspManager.unload(this); } void _caucho_setEntry(PageManager.Entry entry) { _entry = entry; } protected void _caucho_setContentType(String contentType, String encoding) { if (encoding != null && encoding.equals("ISO-8859-1")) encoding = null; _contentType = contentType; } /** * Marks the page as uncacheable. */ void _caucho_setUncacheable() { _cacheDepends = null; } /** * When called treats the JSP page as always modified, i.e. always forcing * recompilation. */ protected void _caucho_setAlwaysModified() { if (_cacheDepends == null) _alwaysModified = true; } /** * When called treats the JSP page as always modified, i.e. always forcing * recompilation. */ protected void _caucho_setModified() { _alwaysModified = true; } /** * Set if the page is never modified. Some users want to deploy * the JSP classes without the JSP source. */ protected void _caucho_setNeverModified(boolean modified) { _neverModified = modified; } /** * Adds a dependency to the page. * * @param path the file the JSP page is dependent on. */ protected void _caucho_addDepend(Path path) { PersistentDependency depend = path.createDepend(); if (depend instanceof Depend) ((Depend) depend).setRequireSource(getRequireSource()); _caucho_addDepend(depend); } /** * Adds a dependency to the page. * * @param path the file the JSP page is dependent on. */ protected void _caucho_addDepend(PersistentDependency depend) { if (_depends == null) _depends = new ArrayList<PersistentDependency>(); if (! _depends.contains(depend)) _depends.add(depend); } /** * Adds an array of dependencies to the page. */ protected void _caucho_addDepend(ArrayList<PersistentDependency> dependList) { if (dependList == null) return; for (int i = 0; i < dependList.size(); i++) _caucho_addDepend(dependList.get(i)); } /** * Adds a JSP source dependency. If the source file changes, the JSP must * be recompiled. * * @param path the path to the file * @param lastModified the last modified time * @param length the length of the file */ protected void _caucho_addDepend(Path path, long lastModified, long length) { if (_depends == null) _depends = new ArrayList<PersistentDependency>(); Depend depend = new Depend(path, lastModified, length); depend.setRequireSource(getRequireSource()); _caucho_addDepend(depend); } /** * Marks the page as cacheable. */ protected void _caucho_setCacheable() { _cacheDepends = new ArrayList<Depend>(); _alwaysModified = false; } /** * Adds a single cache dependency. A cache dependency will cause * the page to be rerun, but will not force a recompilation of the JSP. * * @param path the path to the file * @param lastModified the last modified time * @param length the length of the file */ protected void _caucho_addCacheDepend(Path path, long lastModified, long length) { if (_cacheDepends == null) _cacheDepends = new ArrayList<Depend>(); Depend depend = new Depend(path, lastModified, length); if (! _cacheDepends.contains(depend)) _cacheDepends.add(depend); } /** * Adds an array of dependencies which will change the results of * running the page. * * @param depends an array list of Depend */ void _caucho_setCacheable(ArrayList<Path> depends) { _cacheDepends = new ArrayList<Depend>(); for (int i = 0; i < depends.size(); i++) { Path path = depends.get(i); Depend depend = new Depend(path); depend.setRequireSource(getRequireSource()); if (! _cacheDepends.contains(depend)) _cacheDepends.add(depend); } } /** * Returns true if the underlying source has been modified. */ public boolean _caucho_isModified() { if (_alwaysModified || _isDead) return true; if (_depends == null) return false; for (int i = 0; i < _depends.size(); i++) { Dependency depend = _depends.get(i); if (depend.isModified()) return true; } return false; } /*** * Returns true if the underlying source has been modified. */ public boolean cauchoIsModified() { long now = Alarm.getCurrentTime(); if (_alwaysModified || _isDead) return true; else if (now < _lastUpdateCheck + _updateInterval) return false; /* XXX: this check is redundant, because the invocation has already * checked it. ClassLoader classLoader = getClass().getClassLoader(); if (classLoader instanceof DynamicClassLoader) { DynamicClassLoader dynLoader; dynLoader = (DynamicClassLoader) getClass().getClassLoader(); if (dynLoader.isModified()) return true; } */ if (_neverModified) { _lastUpdateCheck = now; if (_depends == null) return false; for (int i = 0; i < _depends.size(); i++) { Dependency depend = _depends.get(i); if (depend.isModified()) return true; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?