javajspgenerator.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,451 行 · 第 1/5 页
JAVA
2,451 行
/* * 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.java;import com.caucho.config.types.Signature;import com.caucho.java.CompileClassNotFound;import com.caucho.java.LineMap;import com.caucho.java.LineMapWriter;import com.caucho.jsp.*;import com.caucho.jsp.cfg.TldFunction;import com.caucho.jsp.el.JspELParser;import com.caucho.loader.DynamicClassLoader;import com.caucho.log.Log;import com.caucho.make.ClassDependency;import com.caucho.server.util.CauchoSystem;import com.caucho.util.IntMap;import com.caucho.util.L10N;import com.caucho.i18n.*;import com.caucho.vfs.*;import com.caucho.xml.QName;import com.caucho.xpath.NamespaceContext;import com.caucho.xpath.XPath;import com.caucho.xpath.XPathParseException;import javax.el.ELContext;import javax.servlet.jsp.el.ELException;import javax.servlet.jsp.tagext.PageData;import javax.servlet.jsp.tagext.Tag;import javax.servlet.jsp.tagext.TagInfo;import javax.servlet.jsp.tagext.TagLibraryValidator;import javax.servlet.jsp.tagext.ValidationMessage;import java.io.IOException;import java.lang.reflect.Array;import java.lang.reflect.Method;import java.math.BigDecimal;import java.math.BigInteger;import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.logging.Level;import java.util.logging.Logger;/** * Generates JSP code. JavaGenerator, JavaScriptGenerator, and * StaticGenerator specialize the JspGenerator for language-specific * requirements. * * <p>JspParser parses the JSP file into an XML-DOM tree. JspGenerator * generates code from that tree. */public class JavaJspGenerator extends JspGenerator { private static final L10N L = new L10N(JavaJspGenerator.class); private static final Logger log = Logger.getLogger(JavaJspGenerator.class.getName()); static final String IE_CLSID = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"; static final String IE_URL = "http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0"; static final String NS_URL = "http://java.sun.com/products/plugin/"; static HashMap<String,Class> _primitiveClasses; static HashMap<String,String> _primitives; protected JspNode _rootNode; protected ParseState _parseState; /* * Variables storing the JSP directives. */ protected boolean _ideHack = false; /* * Variables controlling caching * isUncacheable overrides isCacheable. */ protected boolean _isCacheable; protected boolean _isUncacheable; protected ArrayList<Depend> _cacheDepends = new ArrayList<Depend>(); // dependencies for the source file itself protected ArrayList<PersistentDependency> _depends = new ArrayList<PersistentDependency>(); long _lastModified; // XXX: obsolete? protected TagInstance _topTag; protected int _tagId; // XXX: needed in combination with XTP boolean _alwaysModified; protected ParseTagManager _tagManager; protected JspPageConfig _config = new JspPageConfig(); protected String _fullClassName; protected String _className; private HashMap<String,Class> _classes; private ClassLoader _parentLoader; private HashSet<String> _declaredVariables = new HashSet<String>(); private String _filename; private final JspGenELContext _elContext; private HashMap<String,Method> _elFunctionMap = new HashMap<String,Method>(); private ArrayList<Taglib> _tagLibraryList = new ArrayList<Taglib>(); private ArrayList<String> _tagFileClassList = new ArrayList<String>(); private PageData _pageData; protected IntMap _strings = new IntMap(); private ArrayList<String> _exprList = new ArrayList<String>(); private ArrayList<ValueExpr> _valueExprList = new ArrayList<ValueExpr>(); private ArrayList<MethodExpr> _methodExprList = new ArrayList<MethodExpr>(); private ArrayList<com.caucho.xpath.Expr> _xpathExprList = new ArrayList<com.caucho.xpath.Expr>(); private ArrayList<JspFragmentNode> _fragmentList = new ArrayList<JspFragmentNode>(); private String _workPath; private String _sourceName; protected String _pkg; private int _uniqueId = 0; private int _jspId = 1; private boolean _hasReleaseTag; private boolean _hasBundle = false; private boolean _hasBundlePrefix = false; private boolean _requireSource = false; private boolean _isOmitXmlDeclaration = false; private String _doctypeSystem; private String _doctypePublic; private String _doctypeRootElement; private boolean _isJsfPrologueInit; private boolean _isStatic = false; protected ArrayList<JspDeclaration> _declarations = new ArrayList<JspDeclaration>(); public JavaJspGenerator(ParseTagManager tagManager) { _elContext = new JspGenELContext(this); _tagManager = tagManager; _topTag = new TagInstance(tagManager); } public TagInstance getRootTag() { return _topTag; } protected void setParseState(ParseState parseState) { _parseState = parseState; } public ParseState getParseState() { return _parseState; } public void setPageConfig(JspPageConfig pageConfig) { _config = pageConfig; } void setStaticEncoding(boolean staticEncoding) { _config.setStaticEncoding(staticEncoding); } void setRequireSource(boolean requireSource) { _requireSource = requireSource; } void setIdeHack(boolean ideHack) { _ideHack = ideHack; } String getPackagePrefix() { return ""; } Path getAppDir() { return _jspCompiler.getAppDir(); } /** * Returns true for XML. */ boolean isXml() { // jsp/0362 return _parseState.isXml(); } /** * Returns true if the XML declaration should be set. */ boolean isOmitXmlDeclaration() { return _isOmitXmlDeclaration; } /** * Returns true if the XML declaration should be set. */ void setOmitXmlDeclaration(boolean omitXml) { _isOmitXmlDeclaration = omitXml; } /** * Sets the dtd system name */ void setDoctypeSystem(String doctypeSystem) { _doctypeSystem = doctypeSystem; } /** * Gets the dtd system name */ String getDoctypeSystem() { return _doctypeSystem; } /** * Sets the dtd public name */ void setDoctypePublic(String doctypePublic) { _doctypePublic = doctypePublic; } /** * Gets the dtd public name */ String getDoctypePublic() { return _doctypePublic; } /** * Gets the dtd root element name */ void setDoctypeRootElement(String doctypeRootElement) { _doctypeRootElement = doctypeRootElement; } /** * Gets the dtd root element name */ String getDoctypeRootElement() { return _doctypeRootElement; } /** * Returns the character encoding. */ String getCharacterEncoding() { return _parseState.getCharEncoding(); } Path getClassDir() { return _jspCompiler.getClassDir(); } /** * Sets the root JSP node. */ public void setRootNode(JspNode node) { _rootNode = node; } public JspPageConfig getConfig() { return _config; } public boolean isTag() { return false; } public void init() { _isOmitXmlDeclaration = ! isXml(); } public boolean hasScripting() { return _rootNode.hasScripting(); } public boolean isJsfPrologueInit() { return _isJsfPrologueInit; } public void setJsfPrologueInit(boolean isInit) { _isJsfPrologueInit = isInit; } /** * Adds a taglib. */ public void addTaglib(String prefix, String uri) throws JspParseException { addTaglib(prefix, uri, false); } /** * Adds a taglib. */ public void addOptionalTaglib(String prefix, String uri) throws JspParseException { addTaglib(prefix, uri, true); } /** * Adds a taglib. */ public Taglib addTaglib(String prefix, String uri, boolean isOptional) throws JspParseException { if (log.isLoggable(Level.FINEST)) log.finest("taglib prefix=" + prefix + " uri:" + uri); Taglib taglib; try { taglib = _tagManager.addTaglib(prefix, uri); } catch (JspParseException e) { if (isOptional) { log.log(Level.FINE, e.toString(), e); return null; } throw e; } if (taglib == null && isOptional && ! uri.startsWith("urn:jsptld:") && ! uri.startsWith("urn:jsptagdir:")) return null; if (taglib == null) { throw error(L.l("'{0}' has no matching taglib-uri. Taglibs specified with an absolute URI must either be:\n" + "1) specified in the web.xml\n" + "2) defined in a jar's .tld in META-INF\n" + "3) defined in a .tld in WEB-INF\n" + "4) predefined by Resin", uri)); } taglib = addLibrary(taglib); ArrayList<TldFunction> functions = taglib.getFunctionList(); for (int i = 0; i < functions.size(); i++) { TldFunction function = functions.get(i); String name = taglib.getPrefixString() + ":" + function.getName(); _elFunctionMap.put(name, function.getMethod()); } return taglib; } void addTagFileClass(String cl) { if ("com.caucho.jsp.java.JspTagFileSupport".equals(cl)) throw new IllegalStateException(); if (! _tagFileClassList.contains(cl)) _tagFileClassList.add(cl); } private Taglib addLibrary(Taglib taglib) throws JspParseException { for (int i = 0; i < _tagLibraryList.size(); i++) { Taglib oldTaglib = _tagLibraryList.get(i); if (oldTaglib.getURI().equals(taglib.getURI())) return oldTaglib; } /* // taglib = taglib.copy(); for (int i = 0; i < _tagLibraryList.size(); i++) { Taglib oldTaglib = _tagLibraryList.get(i); oldTaglib.addTaglib(taglib); taglib.addTaglib(oldTaglib); } */ _tagLibraryList.add(taglib); return taglib; } Method resolveFunction(String prefix, String localName) { if (prefix.equals("")) return _elFunctionMap.get(localName); else return _elFunctionMap.get(prefix + ':' + localName); } /** * Adds a taglib. */ public void addTaglibDir(String prefix, String tagdir) throws JspParseException { Taglib taglib = _tagManager.addTaglibDir(prefix, tagdir); ArrayList<TldFunction> functions = taglib.getFunctionList(); for (int i = 0; i < functions.size(); i++) { TldFunction function = functions.get(i); String name = taglib.getPrefixString() + ":" + function.getName(); _elFunctionMap.put(name, function.getMethod()); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?