jspcompiler.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 857 行 · 第 1/2 页
JAVA
857 行
/* * 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.config.*;import com.caucho.config.program.ConfigProgram;import com.caucho.config.program.ContainerProgram;import com.caucho.config.types.*;import com.caucho.java.*;import com.caucho.jsp.cfg.JspConfig;import com.caucho.jsp.cfg.JspPropertyGroup;import com.caucho.jsp.cfg.JspTaglib;import com.caucho.loader.CompilingLoader;import com.caucho.loader.DirectoryLoader;import com.caucho.loader.DynamicClassLoader;import com.caucho.loader.EnvironmentBean;import com.caucho.loader.EnvironmentClassLoader;import com.caucho.loader.SimpleLoader;import com.caucho.log.Log;import com.caucho.server.util.CauchoSystem;import com.caucho.server.webapp.WebApp;import com.caucho.server.webapp.WebAppController;import com.caucho.util.L10N;import com.caucho.vfs.Path;import com.caucho.vfs.Vfs;import com.caucho.jsf.cfg.JsfPropertyGroup;import javax.annotation.*;import javax.servlet.SingleThreadModel;import javax.servlet.jsp.HttpJspPage;import javax.servlet.jsp.JspPage;import java.io.IOException;import java.io.InputStream;import java.util.ArrayList;import java.util.HashSet;import java.util.logging.Level;import java.util.logging.Logger;/** * Compilation interface for JSP pages. */public class JspCompiler implements EnvironmentBean { private static final L10N L = new L10N(JspCompiler.class); private static final Logger log = Log.open(JspCompiler.class); private ClassLoader _loader; private WebApp _app; private Path _classDir; private Path _appDir; private JspResourceManager _resourceManager; private TaglibManager _taglibManager; private final TagFileManager _tagFileManager; private JspPropertyGroup _jspPropertyGroup; private JsfPropertyGroup _jsfPropertyGroup; private boolean _isXml; private ArrayList<String> _preludeList = new ArrayList<String>(); private ArrayList<String> _codaList = new ArrayList<String>(); private HashSet<String> _compilingTags = new HashSet<String>(); private boolean _hasRecursiveCompile; private ArrayList<JspCompilerInstance> _pending = new ArrayList<JspCompilerInstance>(); public JspCompiler() { _loader = EnvironmentClassLoader.create(); _tagFileManager = new TagFileManager(this); } /** * Returns the classloader for configuration. */ public ClassLoader getClassLoader() { return _loader; } /** * Returns the classloader for configuration. */ private void setClassLoader(ClassLoader loader) { _loader = loader; } /** * Sets the destination class directory. */ public void setClassDir(Path path) { _classDir = path; } /** * Sets the destination class directory. */ public void setClassDirectory(Path path) { setClassDir(path); } /** * Gets the destination class directory. */ public Path getClassDir() { if (_classDir != null) return _classDir; else return CauchoSystem.getWorkPath(); } /** * Sets the source webApp directory. */ public void setAppDir(Path path) { _appDir = path; } /** * Gets the source webApp directory. */ public Path getAppDir() { if (_appDir != null) return _appDir; else if (_app != null) return _app.getAppDir(); else return null; } /** * Adds a prelude include. */ public void addPrelude(String prelude) { _preludeList.add(prelude); } /** * Adds a coda include. */ public void addCoda(String coda) { _codaList.add(coda); } /** * Set true when XML is the default parser. */ public void setXml(boolean isXml) { _isXml = isXml; } /** * True when XML is the default parser. */ public boolean isXml() { return _isXml; } /** * Sets the resource manager. */ public void setResourceManager(JspResourceManager manager) { _resourceManager = manager; } /** * Gets the resource manager. */ public JspResourceManager getResourceManager() { return _resourceManager; } /** * Gets the tag file manager. */ public TagFileManager getTagFileManager() { return _tagFileManager; } public TaglibManager getTaglibManager() throws JspParseException, IOException { synchronized (this) { if (_taglibManager == null) { WebApp app = getWebApp(); Path appDir = getAppDir(); if (appDir == null && app != null) appDir = app.getAppDir(); JspResourceManager resourceManager = getResourceManager(); if (resourceManager != null) { } else if (app != null) resourceManager = new AppResourceManager(app); else { resourceManager = new AppDirResourceManager(appDir); } _taglibManager = new TaglibManager(resourceManager, app, _tagFileManager); _taglibManager.setWebApp(app); JspConfig jspConfig = null; if (app != null) jspConfig = (JspConfig) app.getExtension("jsp-config"); if (jspConfig != null) { ArrayList<JspTaglib> tldMapList = jspConfig.getTaglibList(); for (int i = 0; i < tldMapList.size(); i++) { JspTaglib taglib = tldMapList.get(i); _taglibManager.addLocationMap(taglib.getTaglibUri(), taglib.getTaglibLocation()); } } if (app != null) { ArrayList<JspTaglib> taglibs = app.getTaglibList(); for (int i = 0; taglibs != null && i < taglibs.size(); i++) { JspTaglib taglib = taglibs.get(i); _taglibManager.addLocationMap(taglib.getTaglibUri(), taglib.getTaglibLocation()); } } } } return _taglibManager; } /** * Sets the JspPropertyGroup */ public JspPropertyGroup createJsp() { if (_jspPropertyGroup == null) { _jspPropertyGroup = new JspPropertyGroup(); } return _jspPropertyGroup; } /** * Sets the JspPropertyGroup */ public JspPropertyGroup getJspPropertyGroup() { return _jspPropertyGroup; } /** * Sets JsfPropertyGropu */ public JsfPropertyGroup createJsf() { if (_jsfPropertyGroup == null) _jsfPropertyGroup = new JsfPropertyGroup(); return _jsfPropertyGroup; } /** * Gets JsfPropertyGroup */ public JsfPropertyGroup getJsfPropertyGroup() { return _jsfPropertyGroup; } /** * Initialize values based on the ServletContext. When the calling code * has the ServletContext available, it can take advantage of it. */ public WebApp createWebApp(Path rootDirectory) { if (_app == null) { if (rootDirectory == null) rootDirectory = getAppDir(); WebAppController controller = new WebAppController("", "", rootDirectory, null); _app = controller.getDeployInstance(); } return _app; } /** * Initialize values based on the ServletContext. When the calling code * has the ServletContext available, it can take advantage of it. */ public void setWebApp(WebApp app) { _app = app; if (_resourceManager == null) _resourceManager = new AppResourceManager(_app); } /** * Initialize values based on the ServletContext. When the calling code * has the ServletContext available, it can take advantage of it. */ public ApplicationConfig createApplication() { return new ApplicationConfig(); } /** * Returns the app. */ public WebApp getWebApp() { return _app; } /** * Adds a new tag being compiled. */ public boolean addTag(String className) { if (_compilingTags.contains(className)) { _hasRecursiveCompile = true; return true; } _compilingTags.add(className); return false; } /** * Has recursive compile. */ public boolean hasRecursiveCompile() { return _hasRecursiveCompile; } /** * Mangles the name. */ public static String urlToClassName(String name) { return JavaCompiler.mangleName("jsp/" + name); } /** * Adds a pending compilation. */ void addPending(JspCompilerInstance pending) { _pending.add(pending); } /** * Compiles pending compilations. */ void compilePending() throws Exception { if (_pending.size() == 0) return; ArrayList<JspCompilerInstance> pendingList; pendingList = new ArrayList<JspCompilerInstance>(_pending); for (int i = 0; i < pendingList.size(); i++) { JspCompilerInstance pending = pendingList.get(i); pending.completeTag(); } _pending.clear(); } /** * Compiles the JSP file specified with jspFile. * * @param jspPath the path to the JSP source
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?