node.java
来自「精通tomcat书籍原代码,希望大家共同学习」· Java 代码 · 共 2,370 行 · 第 1/5 页
JAVA
2,370 行
public ChildInfo getChildInfo() {
return childInfo;
}
}
/**
* Represents a template text string
*/
public static class TemplateText extends Node {
private ArrayList extraSmap = null;
public TemplateText(String text, Mark start, Node parent) {
super(null, null, text, start, parent);
}
public void accept(Visitor v) throws JasperException {
v.visit(this);
}
/**
* Trim all whitespace from the left of the template text
*/
public void ltrim() {
int index = 0;
while ((index < text.length()) && (text.charAt(index) <= ' ')) {
index++;
}
text = text.substring(index);
}
public void setText(String text) {
this.text = text;
}
/**
* Trim all whitespace from the right of the template text
*/
public void rtrim() {
int index = text.length();
while( (index > 0) && (text.charAt(index-1) <= ' ') ) {
index--;
}
text = text.substring(0, index);
}
/**
* Returns true if this template text contains whitespace only.
*/
public boolean isAllSpace() {
boolean isAllSpace = true;
for (int i=0; i<text.length(); i++) {
if (!Character.isWhitespace(text.charAt(i))) {
isAllSpace = false;
break;
}
}
return isAllSpace;
}
/**
* Add a source to Java line mapping
* @param srcLine The postion of the source line, relative to the line
* at the start of this node. The corresponding java line is
* assumed to be consecutive, i.e. one more than the last.
*/
public void addSmap(int srcLine) {
if (extraSmap == null) {
extraSmap = new ArrayList();
}
extraSmap.add(new Integer(srcLine));
}
public ArrayList getExtraSmap() {
return extraSmap;
}
}
/*********************************************************************
* Auxillary classes used in Node
*/
/**
* Represents attributes that can be request time expressions.
*
* Can either be a plain attribute, an attribute that represents a
* request time expression value, or a named attribute (specified using
* the jsp:attribute standard action).
*/
public static class JspAttribute {
private String qName;
private String uri;
private String localName;
private String value;
private boolean expression;
private boolean dynamic;
private ELNode.Nodes el;
// If true, this JspAttribute represents a <jsp:attribute>
private boolean namedAttribute;
// The node in the parse tree for the NamedAttribute
private NamedAttribute namedAttributeNode;
JspAttribute(String qName, String uri, String localName, String value,
boolean expr, ELNode.Nodes el, boolean dyn ) {
this.qName = qName;
this.uri = uri;
this.localName = localName;
this.value = value;
this.namedAttributeNode = null;
this.expression = expr;
this.el = el;
this.dynamic = dyn;
this.namedAttribute = false;
}
/**
* Use this constructor if the JspAttribute represents a
* named attribute. In this case, we have to store the nodes of
* the body of the attribute.
*/
JspAttribute(NamedAttribute na, boolean dyn) {
this.qName = na.getName();
this.localName = na.getLocalName();
this.value = null;
this.namedAttributeNode = na;
this.expression = false;
this.el = null;
this.dynamic = dyn;
this.namedAttribute = true;
}
/**
* @return The name of the attribute
*/
public String getName() {
return qName;
}
/**
* @return The local name of the attribute
*/
public String getLocalName() {
return localName;
}
/**
* @return The namespace of the attribute, or null if in the default
* namespace
*/
public String getURI() {
return uri;
}
/**
* Only makes sense if namedAttribute is false.
*
* @return the value for the attribute, or the expression string
* (stripped of "<%=", "%>", "%=", or "%"
* but containing "${" and "}" for EL expressions)
*/
public String getValue() {
return value;
}
/**
* Only makes sense if namedAttribute is true.
*
* @return the nodes that evaluate to the body of this attribute.
*/
public NamedAttribute getNamedAttributeNode() {
return namedAttributeNode;
}
/**
* @return true if the value represents a traditional rtexprvalue
*/
public boolean isExpression() {
return expression;
}
/**
* @return true if the value represents a NamedAttribute value.
*/
public boolean isNamedAttribute() {
return namedAttribute;
}
/**
* @return true if the value represents an expression that should
* be fed to the expression interpreter
* @return false for string literals or rtexprvalues that should
* not be interpreted or reevaluated
*/
public boolean isELInterpreterInput() {
return el != null;
}
/**
* @return true if the value is a string literal known at translation
* time.
*/
public boolean isLiteral() {
return !expression && (el != null) && !namedAttribute;
}
/**
* XXX
*/
public boolean isDynamic() {
return dynamic;
}
public ELNode.Nodes getEL() {
return el;
}
}
/**
* An ordered list of Node, used to represent the body of an element, or
* a jsp page of jsp document.
*/
public static class Nodes {
private List list;
private Node.Root root; // null if this is not a page
private boolean generatedInBuffer;
public Nodes() {
list = new Vector();
}
public Nodes(Node.Root root) {
this.root = root;
list = new Vector();
list.add(root);
}
/**
* Appends a node to the list
* @param n The node to add
*/
public void add(Node n) {
list.add(n);
root = null;
}
/**
* Removes the given node from the list.
* @param n The node to be removed
*/
public void remove(Node n) {
list.remove(n);
}
/**
* Visit the nodes in the list with the supplied visitor
* @param v The visitor used
*/
public void visit(Visitor v) throws JasperException {
Iterator iter = list.iterator();
while (iter.hasNext()) {
Node n = (Node) iter.next();
n.accept(v);
}
}
public int size() {
return list.size();
}
public Node getNode(int index) {
Node n = null;
try {
n = (Node) list.get(index);
} catch (ArrayIndexOutOfBoundsException e) {
}
return n;
}
public Node.Root getRoot() {
return root;
}
public boolean isGeneratedInBuffer() {
return generatedInBuffer;
}
public void setGeneratedInBuffer(boolean g) {
generatedInBuffer = g;
}
}
/**
* A visitor class for visiting the node. This class also provides the
* default action (i.e. nop) for each of the child class of the Node.
* An actual visitor should extend this class and supply the visit
* method for the nodes that it cares.
*/
public static class Visitor {
/**
* This method provides a place to put actions that are common to
* all nodes. Override this in the child visitor class if need to.
*/
protected void doVisit(Node n) throws JasperException {
}
/**
* Visit the body of a node, using the current visitor
*/
protected void visitBody(Node n) throws JasperException {
if (n.getBody() != null) {
n.getBody().visit(this);
}
}
public void visit(Root n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(JspRoot n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(PageDirective n) throws JasperException {
doVisit(n);
}
public void visit(TagDirective n) throws JasperException {
doVisit(n);
}
public void visit(IncludeDirective n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(TaglibDirective n) throws JasperException {
doVisit(n);
}
public void visit(AttributeDirective n) throws JasperException {
doVisit(n);
}
public void visit(VariableDirective n) throws JasperException {
doVisit(n);
}
public void visit(Comment n) throws JasperException {
doVisit(n);
}
public void visit(Declaration n) throws JasperException {
doVisit(n);
}
public void visit(Expression n) throws JasperException {
doVisit(n);
}
public void visit(Scriptlet n) throws JasperException {
doVisit(n);
}
public void visit(ELExpression n) throws JasperException {
doVisit(n);
}
public void visit(IncludeAction n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(ForwardAction n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(GetProperty n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(SetProperty n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(ParamAction n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(ParamsAction n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(FallBackAction n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(UseBean n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(PlugIn n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(CustomTag n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(UninterpretedTag n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(JspElement n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(JspText n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(NamedAttribute n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(JspBody n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(InvokeAction n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(DoBodyAction n) throws JasperException {
doVisit(n);
visitBody(n);
}
public void visit(TemplateText n) throws JasperException {
doVisit(n);
}
public void visit(JspOutput n) throws JasperException {
doVisit(n);
}
public void visit(AttributeGenerator n) throws JasperException {
doVisit(n);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?