📄 node.java
字号:
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);
}
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 final ELNode.Nodes el;
private final TagAttributeInfo tai;
// If true, this JspAttribute represents a <jsp:attribute>
private boolean namedAttribute;
// The node in the parse tree for the NamedAttribute
private NamedAttribute namedAttributeNode;
JspAttribute(TagAttributeInfo tai, 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;
this.tai = tai;
}
/**
* Allow node to validate itself
*
* @param ef
* @param ctx
* @throws ELException
*/
public void validateEL(ExpressionFactory ef, ELContext ctx)
throws ELException {
if (this.el != null) {
// determine exact type
ValueExpression ve = ef.createValueExpression(ctx, this.value,
String.class);
}
}
/**
* 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, TagAttributeInf
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -