jspnode.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,836 行 · 第 1/4 页

JAVA
1,836
字号
/* * 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.el.Expr;import com.caucho.jsp.JspLineParseException;import com.caucho.jsp.JspParseException;import com.caucho.jsp.JspParser;import com.caucho.jsp.Namespace;import com.caucho.jsp.ParseState;import com.caucho.jsp.TagInstance;import com.caucho.log.Log;import com.caucho.util.CharBuffer;import com.caucho.util.CompileException;import com.caucho.util.L10N;import com.caucho.util.LineCompileException;import com.caucho.vfs.Path;import com.caucho.vfs.WriteStream;import com.caucho.xml.QName;import com.caucho.xml.XmlChar;import com.caucho.xpath.NamespaceContext;import com.caucho.xpath.XPath;import javax.el.MethodExpression;import javax.el.ValueExpression;import javax.servlet.jsp.tagext.JspFragment;import javax.servlet.jsp.tagext.TagAttributeInfo;import java.beans.PropertyEditor;import java.beans.PropertyEditorManager;import java.io.IOException;import java.lang.reflect.Method;import java.math.BigDecimal;import java.math.BigInteger;import java.util.ArrayList;import java.util.logging.Level;import java.util.logging.Logger;public abstract class JspNode {  static final L10N L = new L10N(JspNode.class);  static final Logger log = Log.open(JspNode.class);  static final String JSP_NS = JspParser.JSP_NS;  protected Path _sourcePath;  protected String _filename;  protected int _startLine;  protected int _endAttributeLine;  protected int _endLine;  protected Namespace _ns;    protected JavaJspGenerator _gen;  protected ParseState _parseState;  protected QName _name;  protected JspNode _parent;  protected JspNode()  {  }  /**   * Sets the Java generator.   */  public void setGenerator(JavaJspGenerator gen)  {    _gen = gen;  }  /**   * Sets the parse state   */  public void setParseState(ParseState parseState)  {    _parseState = parseState;  }  /**   * Returns the qname of the node.   */  public QName getQName()  {    return _name;  }  /**   * Sets the node's qname   */  public void setQName(QName name)  {    _name = name;  }  /**   * Returns the qname of the node.   */  public String getTagName()  {    if (_name != null)      return _name.getName();    else      return "jsp:unknown";  }    /**   * Returns the parent node.   */  public JspNode getParent()  {    return _parent;  }  /**   * Sets the parent node   */  public void setParent(JspNode parent)  {    _parent = parent;  }  /**   * Sets the start location of the node.   */  public void setStartLocation(Path sourcePath, String filename, int line)  {    _sourcePath = sourcePath;    _filename = filename;    _startLine = line;    _endAttributeLine = line;  }  /**   * Sets the end location of the node.   */  public void setEndAttributeLocation(String filename, int line)  {    if (_filename != null && _filename.equals(filename))      _endAttributeLine = line;  }  /**   * Sets the end location of the node.   */  public void setEndLocation(String filename, int line)  {    if (_filename != null && _filename.equals(filename))      _endLine = line;  }  /**   * Gets the filename of the node   */  public String getFilename()  {    return _filename;  }  /**   * Gets the starting line number   */  public int getStartLine()  {    return _startLine;  }  /**   * Gets the attribute ending line number   */  public int getEndAttributeLine()  {    return _endAttributeLine;  }  /**   * Gets the ending line number   */  public int getEndLine()  {    return _endLine;  }    /**   * True if the node only has static text.   */  public boolean isStatic()  {    return false;  }  /**   * True if this is a jstl node.   */  public boolean isJstl()  {    return false;  }  /**   * Returns the static text.   */  public String getStaticText()  {    CharBuffer cb = CharBuffer.allocate();    getStaticText(cb);    return cb.close();  }  /**   * Returns the static text.   */  public void getStaticText(CharBuffer cb)  {  }    /**   * True if the node has scripting (counting rtexpr)   */  public boolean hasScripting()  {    return false;  }    /**   * True if the node has scripting element (i.e. not counting rtexpr values)   */  public boolean hasScriptingElement()  {    return false;  }    /**   * Finds the first scripting node   */  public JspNode findScriptingNode()  {    if (hasScripting())      return this;    else      return null;  }  /**   * Returns the body content.   */  public String getBodyContent()  {    return "jsp";  }    /**   * True if the node contains a child tag.   */  public boolean hasCustomTag()  {    return false;  }    /**   * True if the node contains a child tag.   */  public boolean hasTag()  {    return hasCustomTag();  }  /**   * Returns the tag name for the current tag.   */  public String getCustomTagName()  {    return null;  }  /**   * Returns true for a simple tag.   */  public boolean isSimpleTag()  {    return false;  }  /**   * Returns parent tag node   */  public JspNode getParentTagNode()  {    if (getCustomTagName() != null)      return this;    else {      JspNode parent = getParent();      if (parent != null)	return parent.getParentTagNode();      else	return null;    }  }  /**   * Returns parent tag node   */  public String getParentTagName()  {    if (getCustomTagName() != null)      return getCustomTagName();    else {      JspNode parent = getParent();      if (parent != null)	return parent.getParentTagName();      else	return null;    }  }  /**   * Returns true if the namespace decl has been printed.   */  public boolean hasNamespace(String prefix, String uri)  {    if (_parent == null)      return false;    else      return _parent.hasNamespace(prefix, uri);  }  /**   * Adds a namespace, e.g. from a prefix declaration.   */  public final void addNamespace(String prefix, String value)  {    addNamespaceRec(prefix, value);  }  /**   * Adds a namespace, e.g. from a prefix declaration.   */  public final void setNamespace(Namespace ns)  {    _ns = ns;  }  /**   * Returns the XPath namespace context.   */  public final NamespaceContext getNamespaceContext()  {    NamespaceContext ns = null;    for (Namespace ptr = _ns; ptr != null; ptr = ptr.getNext()) {      // jsp/1g58      if (! "".equals(ptr.getPrefix()))	ns = new NamespaceContext(ns, ptr.getPrefix(), ptr.getURI());    }    return ns;  }  /**   * Adds a namespace, e.g. from a prefix declaration.   */  public void addNamespaceRec(String prefix, String value)  {    if (_parent != null)      _parent.addNamespaceRec(prefix, value);  }  /**   * Adds a namespace, e.g. from a prefix declaration.   */  public String getNamespacePrefix(String uri)  {    if (_parent != null)      return _parent.getNamespacePrefix(uri);    else      return null;  }  /**   * Returns true if the namespace decl has been printed.   */  public boolean hasNamespace(QName name)  {    return hasNamespace(name.getPrefix(), name.getNamespaceURI());  }  /**   * Adds an attribute.   */  public void addAttribute(QName name, String value)    throws JspParseException  {    throw error(L.l("attribute '{0}' is not allowed in <{1}>.",                    name.getName(), getTagName()));  }  /**   * Adds a JspAttribute attribute.   *   * @param name the name of the attribute.   * @param value the value of the attribute.   */  public void addAttribute(QName name, JspAttribute value)    throws JspParseException  {    if (value.isStatic()) {      addAttribute(name, value.getStaticText().trim());    }    else      throw error(L.l("attribute '{0}' is not allowed in <{1}>.",		      name.getName(), getTagName()));  }  /**   * Called after all the attributes from the tag.   */  public void endAttributes()    throws JspParseException  {  }  /**   * Adds text.   */  public JspNode addText(String text)    throws JspParseException  {    for (int i = 0; i < text.length(); i++) {      char ch = text.charAt(i);

⌨️ 快捷键说明

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