javajspbuilder.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 698 行 · 第 1/2 页
JAVA
698 行
/* * 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 SoftwareFoundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * * @author Scott Ferguson */package com.caucho.jsp.java;import com.caucho.jsp.*;import com.caucho.jsp.cfg.*;import com.caucho.log.Log;import com.caucho.util.CompileException;import com.caucho.util.L10N;import com.caucho.util.LineCompileException;import com.caucho.vfs.PersistentDependency;import com.caucho.xml.QName;import javax.servlet.jsp.tagext.SimpleTag;import javax.servlet.jsp.tagext.Tag;import javax.servlet.jsp.tagext.TagInfo;import java.util.ArrayList;import java.util.HashMap;import java.util.logging.Level;import java.util.logging.Logger;/** * Generates the nodes for JSP code. */public class JavaJspBuilder extends JspBuilder { public static final String JSTL_CORE_URI = "http://java.sun.com/jsp/jstl/core"; public static final String JSTL_EL_CORE_URI = "http://java.sun.com/jstl/core"; public static final String JSTL_RT_CORE_URI = "http://java.sun.com/jstl/core_rt"; public static final String JSTL_FMT_URI = "http://java.sun.com/jsp/jstl/fmt"; public static final String JSTL_EL_FMT_URI = "http://java.sun.com/jstl/fmt"; public static final String JSTL_RT_FMT_URI = "http://java.sun.com/jstl/fmt_rt"; public static final String JSTL_XML_URI = "http://java.sun.com/jsp/jstl/xml"; public static final String JSTL_EL_XML_URI = "http://java.sun.com/jstl/xml"; public static final String JSTL_RT_XML_URI = "http://java.sun.com/jstl/xml_rt"; public static final String JSTL_SQL_URI = "http://java.sun.com/jsp/jstl/sql"; public static final String JSTL_EL_SQL_URI = "http://java.sun.com/jstl/sql"; public static final String JSTL_RT_SQL_URI = "http://java.sun.com/jstl/sql_rt"; public static final String JSF_CORE_URI = "http://java.sun.com/jsf/core"; private static L10N L = new L10N(JavaJspBuilder.class); private static Logger log = Logger.getLogger(JavaJspBuilder.class.getName()); static final int IGNORE = 0; static final int DIRECTIVE_PAGE = IGNORE + 1; static final int TEXT = DIRECTIVE_PAGE + 1; static final int EXPR = TEXT + 1; static final int SCRIPTLET = EXPR + 1; static final int DECLARATION = SCRIPTLET + 1; static final int FUNCTION = DECLARATION + 1; static final int SET = FUNCTION + 1; static final int INCLUDE = SET + 1; static final int FORWARD = INCLUDE + 1; static final int REQUEST = INCLUDE + 1; static final int USE_BEAN = REQUEST + 1; static final int GET_PROPERTY = USE_BEAN + 1; static final int SET_PROPERTY = GET_PROPERTY + 1; static final int TAG = GET_PROPERTY + 1; static final int PLUGIN = TAG + 1; static final int ROOT = PLUGIN + 1; static final int JSP_TEXT = ROOT + 1; static final int JSP_ATTRIBUTE = JSP_TEXT + 1; static final int JSP_BODY = JSP_ATTRIBUTE + 1; static final int IF = JSP_BODY + 1; static final int FOREACH = IF + 1; static final int EXPR_EL = FOREACH + 1; static HashMap<QName,Class> _tagMap; static HashMap<QName,Class> _fastTagMap; static HashMap<QName,Class> _jsfTagMap; private JavaJspGenerator _gen; private JspNode _rootNode; private JspNode _currentNode; private JspNode _openNode; private boolean _isPrototype; /** * Creates the JSP builder. */ public JavaJspBuilder() { } /** * Returns the generator. */ public JspGenerator getGenerator() { return _gen; } /** * Returns the root node. */ public JspNode getRootNode() { return _rootNode; } /** * Sets the prototype mode. */ public void setPrototype(boolean prototype) { _isPrototype = prototype; } /** * Gets the prototype mode. */ public boolean isPrototype() { return _isPrototype; } /** * Starts the document */ public void startDocument() throws JspParseException { try { // jsp/031a if (_rootNode != null) return; if (_parseState.isTag()) _gen = new JavaTagGenerator(_tagManager); else _gen = new JavaJspGenerator(_tagManager); _gen.setParseState(getParseState()); _gen.setJspCompiler(getJspCompiler()); _gen.setJspParser(getJspParser()); _gen.setRequireSource(getRequireSource()); _rootNode = new JspTop(); _rootNode.setParseState(getParseState()); _rootNode.setGenerator(_gen); _rootNode.setStartLocation(_sourcePath, _filename, _line); _gen.setRootNode(_rootNode); _gen.init(); _currentNode = _rootNode; } catch (Exception e) { throw JspParseException.create(e); } } /** * Starts the document */ public void endDocument() throws JspParseException { } /** * Starts an element. * * @param qname the name of the element to start */ public void startElement(QName qname) throws JspParseException { Class cl = null; if (isFastJstl()) cl = _fastTagMap.get(qname); if (cl == null && isFastJsf()) { Class type = _jsfTagMap.get(qname); if (JsfFacetNode.class.equals(type) && _currentNode != null && !JsfTagNode.class.isAssignableFrom(_currentNode.getClass())) { } else { cl = type; } } if (cl == null) cl = _tagMap.get(qname); if (cl != null) { try { JspNode node = (JspNode) cl.newInstance(); node.setGenerator(_gen); node.setParseState(_parseState); node.setQName(qname); node.setParent(_currentNode); node.setStartLocation(_sourcePath, _filename, _line); _openNode = node; return; } catch (Exception e) { throw new JspParseException(e); } } if (isPrototype()) { JspXmlElement elt = new JspXmlElement(); elt.setGenerator(_gen); elt.setParseState(_parseState); elt.setQName(qname); elt.setParent(_currentNode); elt.setStartLocation(_sourcePath, _filename, _line); _openNode = elt; return; } if (JspNode.JSP_NS.equals(qname.getNamespace())) throw new JspParseException(L.l("unknown JSP <{0}>", qname.getName())); TagInfo tagInfo; try { tagInfo = _gen.getTag(qname); } catch (JspParseException e) { throw error(e); } if (tagInfo == null) { JspXmlElement elt = new JspXmlElement(); elt.setGenerator(_gen); elt.setParseState(_parseState); elt.setQName(qname); elt.setParent(_currentNode); elt.setStartLocation(_sourcePath, _filename, _line); _openNode = elt; return; } Class tagClass = null; try { tagClass = _gen.getTagClass(qname); } catch (ClassNotFoundException e) { tagClass = JspTagFileSupport.class; log.log(Level.FINE, e.toString(), e); } catch (Exception e) { throw error(e); } if (tagInfo == null || tagClass == null) throw _gen.error(L.l("<{0}> is an unknown tag.", qname.getName())); if (tagInfo instanceof TagInfoExt) { TagInfoExt tagInfoExt = (TagInfoExt) tagInfo; ArrayList<PersistentDependency> dependList = tagInfoExt.getDependList(); for (int i = 0; i < dependList.size(); i++) { _gen.addDepend(dependList.get(i)); } } if (JspTagSupport.class.isAssignableFrom(tagClass) && ! JspTagFileSupport.class.equals(tagClass)) { // jsp/1004 _gen.addTagFileClass(tagClass.getName()); } if (JspTagFileSupport.class.isAssignableFrom(tagClass)) { TagFileTag customTag = new TagFileTag(); customTag.setGenerator(_gen); customTag.setParseState(_parseState); customTag.setQName(qname); customTag.setParent(_currentNode); customTag.setTagInfo(tagInfo); customTag.setTagClass(tagClass); _openNode = customTag; _openNode.setStartLocation(_sourcePath, _filename, _line); } else if (Tag.class.isAssignableFrom(tagClass)) { CustomTag customTag = new CustomTag(); customTag.setGenerator(_gen); customTag.setParseState(_parseState); customTag.setQName(qname); customTag.setParent(_currentNode); customTag.setTagInfo(tagInfo); customTag.setTagClass(tagClass); _openNode = customTag; _openNode.setStartLocation(_sourcePath, _filename, _line); if (tagInfo instanceof TagInfoImpl) { TldTag tldTag = ((TagInfoImpl) tagInfo).getTldTag(); if (tldTag instanceof JsfTag) { JsfTag jsfTag = (JsfTag) tldTag; JsfTagNode jsfTagNode = new JsfTagNode(); jsfTagNode.setGenerator(_gen); jsfTagNode.setParseState(_parseState); jsfTagNode.setQName(qname); jsfTagNode.setParent(_currentNode); jsfTagNode.setComponentClass(jsfTag.getComponentClass()); _openNode = jsfTagNode; _openNode.setStartLocation(_sourcePath, _filename, _line); return; } } } else if (SimpleTag.class.isAssignableFrom(tagClass)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?