jspcompilerinstance.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 756 行 · 第 1/2 页

JAVA
756
字号
/* * 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.java.JavaCompiler;import com.caucho.java.LineMap;import com.caucho.jsp.cfg.JspConfig;import com.caucho.jsp.cfg.JspPropertyGroup;import com.caucho.jsp.java.JspTagSupport;import com.caucho.jsp.java.TagTaglib;import com.caucho.log.Log;import com.caucho.server.webapp.WebApp;import com.caucho.vfs.Path;import com.caucho.vfs.PersistentDependency;import com.caucho.xml.Xml;import com.caucho.jsf.cfg.JsfPropertyGroup;import org.xml.sax.SAXException;import javax.servlet.jsp.tagext.TagInfo;import javax.servlet.jsp.tagext.TagLibraryInfo;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.util.ArrayList;import java.util.logging.Level;import java.util.logging.Logger;/** * Compilation interface for JSP pages. */public class JspCompilerInstance {  private static final Logger log = Log.open(JspCompilerInstance.class);  // The underlying compiler  private JspCompiler _jspCompiler;  // The path to the JSP source  private Path _jspPath;  // The JSP uri (user-name)  private String _uri;  // The JSP class name  private String _className;  private JspPropertyGroup _jspPropertyGroup;  private JsfPropertyGroup _jsfPropertyGroup;  // The builder  private JspBuilder _jspBuilder;  // true for XML parsing  private boolean _isXml;  // true for prototype parsing.  private boolean _isPrototype;  // true for generated source (like XTP)  private boolean _isGeneratedSource;  // The parse state  private ParseState _parseState;  // The tag manager  private ParseTagManager _tagManager;  // The parser  private JspParser _parser;  // The compiled page  private Page _page;  // The generator  private JspGenerator _generator;  private ArrayList<String> _preludeList = new ArrayList<String>();  private ArrayList<String> _codaList = new ArrayList<String>();  private ArrayList<PersistentDependency> _dependList =    new ArrayList<PersistentDependency>();  /**   * Creates a JSP compiler instance.   */  JspCompilerInstance(JspCompiler compiler)  {    _jspCompiler = compiler;    _isXml = _jspCompiler.isXml();  }  /**   * Sets the builder.   */  void setJspBuilder(JspBuilder builder)  {    _jspBuilder = builder;  }  /**   * Sets the path.   */  void setJspPath(Path path)  {    _jspPath = path;  }  /**   * Sets the uri   */  void setURI(String uri)  {    _uri = uri;  }  /**   * Sets true for xml   */  void setXML(boolean isXml)  {    _isXml = isXml;  }  /*   * Sets true for generated source   */  void setGeneratedSource(boolean isGeneratedSource)  {    _isGeneratedSource = isGeneratedSource;  }  /*   * Sets true for generated source   */  public boolean isGeneratedSource()  {    return _isGeneratedSource;  }  /**   * Sets the class name.   */  void setClassName(String className)  {    _className = className;  }  /**   * Adds a dependency.   */  public void addDepend(PersistentDependency depend)  {    _dependList.add(depend);  }  /**   * Adds a dependency.   */  public void addDependList(ArrayList<PersistentDependency> dependList)  {    if (dependList != null)      _dependList.addAll(dependList);  }  /**   * Returns the jsp configuration.   */  public JspPropertyGroup getJspPropertyGroup()  {    return _jspPropertyGroup;  }  /**   * Returns true for prototype compilation.   */  public boolean isPrototype()  {    return _isPrototype;  }  /**   * Set true for prototype compilation.   */  public void setPrototype(boolean prototype)  {    _isPrototype = prototype;  }  /**   * Initialize the instance.   */  void init()    throws Exception  {    _parseState = new ParseState();    String uriPwd;    if (_uri != null) {      int p = _uri.lastIndexOf('/');      uriPwd = p <= 0 ? "/" : _uri.substring(0, p + 1);    }    else {      uriPwd = "/";    }        _parseState.setUriPwd(uriPwd);    if (_className == null)      _className = JavaCompiler.mangleName("jsp/" + _uri);    // default to true if ends with x    if (_uri.endsWith("x"))      _parseState.setXml(true);    WebApp app = _jspCompiler.getWebApp();    Path appDir = _jspCompiler.getAppDir();    if (appDir == null && app != null)      appDir = app.getAppDir();    if (app != null && app.has23Config())      _parseState.setELIgnoredDefault(true);    JspConfig jspConfig = null;    if (jspConfig == null && app != null)      jspConfig = (JspConfig) app.getExtension("jsp-config");    ArrayList<JspPropertyGroup> jspList = new ArrayList<JspPropertyGroup>();    _jspPropertyGroup = null;    if (_jspPropertyGroup == null) {      _jspPropertyGroup = _jspCompiler.getJspPropertyGroup();      if (_jspPropertyGroup != null) {	jspList.add(_jspPropertyGroup);      }    }    if (_jspPropertyGroup == null && app != null) {      _jspPropertyGroup = app.getJsp();            if (_jspPropertyGroup != null)	jspList.add(_jspPropertyGroup);    }    if (_jspPropertyGroup == null) {      _jspPropertyGroup = _jspCompiler.getJspPropertyGroup();            if (_jspPropertyGroup != null)	jspList.add(_jspPropertyGroup);    }    if (jspConfig != null) {      jspList.addAll(jspConfig.findJspPropertyGroupList(_uri));      _parseState.setELIgnoredDefault(false);    }    JspResourceManager resourceManager = _jspCompiler.getResourceManager();    if (resourceManager != null) {    }    else if (app != null)      resourceManager = new AppResourceManager(app);    else {      resourceManager = new AppDirResourceManager(appDir);    }    TagFileManager tagFileManager = _jspCompiler.getTagFileManager();    TaglibManager taglibManager = _jspCompiler.getTaglibManager();    JspPageConfig pageConfig = new JspPageConfig();    for (JspPropertyGroup jspPropertyGroup : jspList) {      ArrayList<String> preludeList = jspPropertyGroup.getIncludePreludeList();      for (int i = 0; preludeList != null && i < preludeList.size(); i++) {        String prelude = preludeList.get(i);        _preludeList.add(prelude);      }      ArrayList<String> codaList = jspPropertyGroup.getIncludeCodaList();      for (int i = 0; codaList != null && i < codaList.size(); i++) {        String coda = codaList.get(i);        _codaList.add(coda);      }      _parseState.setJspPropertyGroup(jspPropertyGroup);      _parseState.setSession(jspPropertyGroup.isSession());      _parseState.setScriptingInvalid(jspPropertyGroup.isScriptingInvalid());            if (jspPropertyGroup.isELIgnored() != null)	_parseState.setELIgnored(Boolean.TRUE.equals(jspPropertyGroup.isELIgnored()))	  ;      _parseState.setVelocityEnabled(jspPropertyGroup.isVelocityEnabled());      _parseState.setPageEncoding(jspPropertyGroup.getPageEncoding());            if (Boolean.TRUE.equals(jspPropertyGroup.isXml()))	_parseState.setXml(true);            if (Boolean.FALSE.equals(jspPropertyGroup.isXml()))	_parseState.setForbidXml(true);            if (jspPropertyGroup.getPageEncoding() != null) {	try {	  _parseState.setPageEncoding(jspPropertyGroup.getPageEncoding());	} catch (JspParseException e) {	}      }      pageConfig.setStaticEncoding(jspPropertyGroup.isStaticEncoding());      _parseState.setRecycleTags(jspPropertyGroup.isRecycleTags());            _parseState.setTrimWhitespace(jspPropertyGroup.isTrimDirectiveWhitespaces());      _parseState.setDeferredSyntaxAllowedAsLiteral(jspPropertyGroup.isDeferredSyntaxAllowedAsLiteral());      if (jspPropertyGroup.getTldFileSet() != null)        taglibManager.setTldFileSet(jspPropertyGroup.getTldFileSet());    }    if (_jsfPropertyGroup == null)      _jsfPropertyGroup = _jspCompiler.getJsfPropertyGroup();    if (_jsfPropertyGroup == null && app != null)       _jsfPropertyGroup = app.getJsf();    _parseState.setResourceManager(resourceManager);    LineMap lineMap = null;    _tagManager = new ParseTagManager(resourceManager,                                      taglibManager,                                      tagFileManager);    _jspBuilder = new com.caucho.jsp.java.JavaJspBuilder();    _jspBuilder.setParseState(_parseState);    _jspBuilder.setJspCompiler(_jspCompiler);    _jspBuilder.setJspPropertyGroup(_jspPropertyGroup);    _jspBuilder.setJsfPropertyGroup(_jsfPropertyGroup);    _jspBuilder.setTagManager(_tagManager);    _jspBuilder.setPageConfig(pageConfig);    _jspBuilder.setPrototype(_isPrototype);    _parser = new JspParser();    _parser.setJspBuilder(_jspBuilder);    _parser.setParseState(_parseState);    _parser.setTagManager(_tagManager);    _jspBuilder.setJspParser(_parser);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?