node.java
来自「精通tomcat书籍原代码,希望大家共同学习」· Java 代码 · 共 2,370 行 · 第 1/5 页
JAVA
2,370 行
super(qName, localName, attrs, nonTaglibXmlnsAttrs, taglibAttrs,
start, parent);
this.uri = uri;
this.prefix = prefix;
this.tagFileInfo = tagFileInfo;
this.tagInfo = tagFileInfo.getTagInfo();
this.customNestingLevel = makeCustomNestingLevel();
this.childInfo = new ChildInfo();
this.implementsIterationTag = false;
this.implementsBodyTag = false;
this.implementsTryCatchFinally = false;
this.implementsSimpleTag = true;
this.implementsDynamicAttributes = tagInfo.hasDynamicAttributes();
}
public void accept(Visitor v) throws JasperException {
v.visit(this);
}
/**
* @return The URI namespace that this custom action belongs to
*/
public String getURI() {
return this.uri;
}
/**
* @return The tag prefix
*/
public String getPrefix() {
return prefix;
}
public void setJspAttributes(JspAttribute[] jspAttrs) {
this.jspAttrs = jspAttrs;
}
public JspAttribute[] getJspAttributes() {
return jspAttrs;
}
public ChildInfo getChildInfo() {
return childInfo;
}
public void setTagData(TagData tagData) {
this.tagData = tagData;
this.varInfos = tagInfo.getVariableInfo(tagData);
if (this.varInfos == null) {
this.varInfos = ZERO_VARIABLE_INFO;
}
}
public TagData getTagData() {
return tagData;
}
public void setTagHandlerPoolName(String s) {
tagHandlerPoolName = s;
}
public String getTagHandlerPoolName() {
return tagHandlerPoolName;
}
public TagInfo getTagInfo() {
return tagInfo;
}
public TagFileInfo getTagFileInfo() {
return tagFileInfo;
}
/*
* @return true if this custom action is supported by a tag file,
* false otherwise
*/
public boolean isTagFile() {
return tagFileInfo != null;
}
public Class getTagHandlerClass() {
return tagHandlerClass;
}
public void setTagHandlerClass(Class hc) {
tagHandlerClass = hc;
}
public boolean implementsIterationTag() {
return implementsIterationTag;
}
public boolean implementsBodyTag() {
return implementsBodyTag;
}
public boolean implementsTryCatchFinally() {
return implementsTryCatchFinally;
}
public boolean implementsSimpleTag() {
return implementsSimpleTag;
}
public boolean implementsDynamicAttributes() {
return implementsDynamicAttributes;
}
public TagVariableInfo[] getTagVariableInfos() {
return tagInfo.getTagVariableInfos();
}
public VariableInfo[] getVariableInfos() {
return varInfos;
}
public void setCustomTagParent(Node.CustomTag n) {
this.customTagParent = n;
}
public Node.CustomTag getCustomTagParent() {
return this.customTagParent;
}
public void setNumCount(Integer count) {
this.numCount = count;
}
public Integer getNumCount() {
return this.numCount;
}
public void setScriptingVars(Vector vec, int scope) {
switch (scope) {
case VariableInfo.AT_BEGIN:
this.atBeginScriptingVars = vec;
break;
case VariableInfo.AT_END:
this.atEndScriptingVars = vec;
break;
case VariableInfo.NESTED:
this.nestedScriptingVars = vec;
break;
}
}
/*
* Gets the scripting variables for the given scope that need to be
* declared.
*/
public Vector getScriptingVars(int scope) {
Vector vec = null;
switch (scope) {
case VariableInfo.AT_BEGIN:
vec = this.atBeginScriptingVars;
break;
case VariableInfo.AT_END:
vec = this.atEndScriptingVars;
break;
case VariableInfo.NESTED:
vec = this.nestedScriptingVars;
break;
}
return vec;
}
/*
* Gets this custom tag's custom nesting level, which is given as
* the number of times this custom tag is nested inside itself.
*/
public int getCustomNestingLevel() {
return customNestingLevel;
}
/**
* Checks to see if the attribute of the given name is of type
* JspFragment.
*/
public boolean checkIfAttributeIsJspFragment( String name ) {
boolean result = false;
TagAttributeInfo[] attributes = tagInfo.getAttributes();
for (int i = 0; i < attributes.length; i++) {
if (attributes[i].getName().equals(name) &&
attributes[i].isFragment()) {
result = true;
break;
}
}
return result;
}
public void setUseTagPlugin(boolean use) {
useTagPlugin = use;
}
public boolean useTagPlugin() {
return useTagPlugin;
}
public void setTagPluginContext(TagPluginContext tagPluginContext) {
this.tagPluginContext = tagPluginContext;
}
public TagPluginContext getTagPluginContext() {
return tagPluginContext;
}
public void setAtSTag(Nodes sTag) {
atSTag = sTag;
}
public Nodes getAtSTag() {
return atSTag;
}
public void setAtETag(Nodes eTag) {
atETag = eTag;
}
public Nodes getAtETag() {
return atETag;
}
/*
* Computes this custom tag's custom nesting level, which corresponds
* to the number of times this custom tag is nested inside itself.
*
* Example:
*
* <g:h>
* <a:b> -- nesting level 0
* <c:d>
* <e:f>
* <a:b> -- nesting level 1
* <a:b> -- nesting level 2
* </a:b>
* </a:b>
* <a:b> -- nesting level 1
* </a:b>
* </e:f>
* </c:d>
* </a:b>
* </g:h>
*
* @return Custom tag's nesting level
*/
private int makeCustomNestingLevel() {
int n = 0;
Node p = parent;
while (p != null) {
if ((p instanceof Node.CustomTag)
&& qName.equals(((Node.CustomTag) p).qName)) {
n++;
}
p = p.parent;
}
return n;
}
/**
* Returns true if this custom action has an empty body, and false
* otherwise.
*
* A custom action is considered to have an empty body if the
* following holds true:
* - getBody() returns null, or
* - all immediate children are jsp:attribute actions, or
* - the action's jsp:body is empty.
*/
public boolean hasEmptyBody() {
boolean hasEmptyBody = true;
Nodes nodes = getBody();
if (nodes != null) {
int numChildNodes = nodes.size();
for (int i=0; i<numChildNodes; i++) {
Node n = nodes.getNode(i);
if (!(n instanceof NamedAttribute)) {
if (n instanceof JspBody) {
hasEmptyBody = (n.getBody() == null);
} else {
hasEmptyBody = false;
}
break;
}
}
}
return hasEmptyBody;
}
}
/**
* Used as a placeholder for the evaluation code of a custom action
* attribute (used by the tag plugin machinery only).
*/
public static class AttributeGenerator extends Node {
String name; // name of the attribute
CustomTag tag; // The tag this attribute belongs to
public AttributeGenerator(Mark start, String name, CustomTag tag) {
super(start, null);
this.name = name;
this.tag = tag;
}
public void accept(Visitor v) throws JasperException {
v.visit(this);
}
public String getName() {
return name;
}
public CustomTag getTag() {
return tag;
}
}
/**
* Represents the body of a <jsp:text> element
*/
public static class JspText extends Node {
public JspText(String qName, Attributes nonTaglibXmlnsAttrs,
Attributes taglibAttrs, Mark start, Node parent) {
super(qName, TEXT_ACTION, null, nonTaglibXmlnsAttrs, taglibAttrs,
start, parent);
}
public void accept(Visitor v) throws JasperException {
v.visit(this);
}
}
/**
* Represents a Named Attribute (<jsp:attribute>)
*/
public static class NamedAttribute extends Node {
// A unique temporary variable name suitable for code generation
private String temporaryVariableName;
// True if this node is to be trimmed, or false otherwise
private boolean trim = true;
private ChildInfo childInfo;
private String name;
private String localName;
private String prefix;
public NamedAttribute(Attributes attrs, Mark start, Node parent) {
this(JSP_ATTRIBUTE_ACTION, attrs, null, null, start, parent);
}
public NamedAttribute(String qName, Attributes attrs,
Attributes nonTaglibXmlnsAttrs,
Attributes taglibAttrs,
Mark start, Node parent) {
super(qName, ATTRIBUTE_ACTION, attrs, nonTaglibXmlnsAttrs,
taglibAttrs, start, parent);
temporaryVariableName = JspUtil.nextTemporaryVariableName();
if( "false".equals( this.getAttributeValue( "trim" ) ) ) {
// (if null or true, leave default of true)
trim = false;
}
childInfo = new ChildInfo();
name = this.getAttributeValue("name");
if (name != null) {
// Mandatary attribute "name" will be checked in Validator
localName = name;
int index = name.indexOf(':');
if (index != -1) {
prefix = name.substring(0, index);
localName = name.substring(index+1);
}
}
}
public void accept(Visitor v) throws JasperException {
v.visit(this);
}
public String getName() {
return this.name;
}
public String getLocalName() {
return this.localName;
}
public String getPrefix() {
return this.prefix;
}
public ChildInfo getChildInfo() {
return this.childInfo;
}
public boolean isTrim() {
return trim;
}
/**
* @return A unique temporary variable name to store the result in.
* (this probably could go elsewhere, but it's convenient here)
*/
public String getTemporaryVariableName() {
return temporaryVariableName;
}
/*
* Get the attribute value from this named attribute (<jsp:attribute>).
* Since this method is only for attributes that are not rtexpr,
* we can assume the body of the jsp:attribute is a template text.
*/
public String getText() {
class AttributeVisitor extends Visitor {
String attrValue = null;
public void visit(TemplateText txt) {
attrValue = new String(txt.getText());
}
public String getAttrValue() {
return attrValue;
}
}
// According to JSP 2.0, if the body of the <jsp:attribute>
// action is empty, it is equivalent of specifying "" as the value
// of the attribute.
String text = "";
if (getBody() != null) {
AttributeVisitor attributeVisitor = new AttributeVisitor();
try {
getBody().visit(attributeVisitor);
} catch (JasperException e) {
}
text = attributeVisitor.getAttrValue();
}
return text;
}
}
/**
* Represents a JspBody node (<jsp:body>)
*/
public static class JspBody extends Node {
private ChildInfo childInfo;
public JspBody(Mark start, Node parent) {
this(JSP_BODY_ACTION, null, null, start, parent);
}
public JspBody(String qName, Attributes nonTaglibXmlnsAttrs,
Attributes taglibAttrs, Mark start, Node parent) {
super(qName, BODY_ACTION, null, nonTaglibXmlnsAttrs, taglibAttrs,
start, parent);
this.childInfo = new ChildInfo();
}
public void accept(Visitor v) throws JasperException {
v.visit(this);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?