下面列出了怎么用javax.servlet.jsp.tagext.TagAttributeInfo的API类实例代码及写法,或者点击链接到github查看源代码。
public JasperTagInfo(String tagName,
String tagClassName,
String bodyContent,
String infoString,
TagLibraryInfo taglib,
TagExtraInfo tagExtraInfo,
TagAttributeInfo[] attributeInfo,
String displayName,
String smallIcon,
String largeIcon,
TagVariableInfo[] tvi,
String mapName) {
super(tagName, tagClassName, bodyContent, infoString, taglib,
tagExtraInfo, attributeInfo, displayName, smallIcon, largeIcon,
tvi);
this.dynamicAttrsMapName = mapName;
}
public TagInfo getTagInfo() throws JasperException {
if (name == null) {
// XXX Get it from tag file name
}
if (bodycontent == null) {
bodycontent = TagInfo.BODY_CONTENT_SCRIPTLESS;
}
String tagClassName = JspUtil.getTagHandlerClassName(
path, tagLibInfo.getReliableURN(), err);
TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector
.size()];
variableVector.copyInto(tagVariableInfos);
TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector
.size()];
attributeVector.copyInto(tagAttributeInfo);
return new JasperTagInfo(name, tagClassName, bodycontent,
description, tagLibInfo, null, tagAttributeInfo,
displayName, smallIcon, largeIcon, tagVariableInfos,
dynamicAttrsMapName);
}
private void checkUniqueName(String name, String type, Node n,
TagAttributeInfo attr) throws JasperException {
HashMap<String, NameEntry> table = (VAR_NAME_FROM.equals(type)) ? nameFromTable : nameTable;
NameEntry nameEntry = table.get(name);
if (nameEntry != null) {
if (!TAG_DYNAMIC.equals(type) ||
!TAG_DYNAMIC.equals(nameEntry.getType())) {
int line = nameEntry.getNode().getStart().getLineNumber();
err.jspError(n, "jsp.error.tagfile.nameNotUnique", type,
nameEntry.getType(), Integer.toString(line));
}
} else {
table.put(name, new NameEntry(type, n, attr));
}
}
/**
* Perform miscellaneous checks after the nodes are visited.
*/
void postCheck() throws JasperException {
// Check that var.name-from-attributes has valid values.
for (Entry<String, NameEntry> entry : nameFromTable.entrySet()) {
String key = entry.getKey();
NameEntry nameEntry = nameTable.get(key);
NameEntry nameFromEntry = entry.getValue();
Node nameFromNode = nameFromEntry.getNode();
if (nameEntry == null) {
err.jspError(nameFromNode,
"jsp.error.tagfile.nameFrom.noAttribute", key);
} else {
Node node = nameEntry.getNode();
TagAttributeInfo tagAttr = nameEntry.getTagAttributeInfo();
if (!"java.lang.String".equals(tagAttr.getTypeName())
|| !tagAttr.isRequired()
|| tagAttr.canBeRequestTime()) {
err.jspError(nameFromNode,
"jsp.error.tagfile.nameFrom.badAttribute",
key, Integer.toString(node.getStart()
.getLineNumber()));
}
}
}
}
public String tagInfoToString(TagInfo tag, String indent) {
StringBuilder sb = new StringBuilder();
if (tag != null) {
sb.append(indent).append("tag name : ").append(tag.getTagName()).append('\n'); // NOI18N
sb.append(indent).append(" class : ").append(tag.getTagClassName()).append('\n'); // NOI18N
sb.append(indent).append(" attribs : ["); // NOI18N
TagAttributeInfo attrs[] = tag.getAttributes();
for (int i = 0; i < attrs.length; i++) {
sb.append(attrs[i].getName());
if (i < attrs.length - 1) {
sb.append(", "); // NOI18N
}
}
sb.append("]\n"); // NOI18N
}
else {
sb.append(indent).append("taginfo is null\n"); // NOI18N
}
return sb.toString();
}
public JasperTagInfo(String tagName,
String tagClassName,
String bodyContent,
String infoString,
TagLibraryInfo taglib,
TagExtraInfo tagExtraInfo,
TagAttributeInfo[] attributeInfo,
String displayName,
String smallIcon,
String largeIcon,
TagVariableInfo[] tvi,
String mapName) {
super(tagName, tagClassName, bodyContent, infoString, taglib,
tagExtraInfo, attributeInfo, displayName, smallIcon, largeIcon,
tvi);
this.dynamicAttrsMapName = mapName;
}
public TagInfo getTagInfo() throws JasperException {
if (name == null) {
// XXX Get it from tag file name
}
if (bodycontent == null) {
bodycontent = TagInfo.BODY_CONTENT_SCRIPTLESS;
}
String tagClassName = JspUtil.getTagHandlerClassName(
path, tagLibInfo.getReliableURN(), err);
TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector
.size()];
variableVector.copyInto(tagVariableInfos);
TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector
.size()];
attributeVector.copyInto(tagAttributeInfo);
return new JasperTagInfo(name, tagClassName, bodycontent,
description, tagLibInfo, tei, tagAttributeInfo,
displayName, smallIcon, largeIcon, tagVariableInfos,
dynamicAttrsMapName);
}
private void checkUniqueName(String name, String type, Node n,
TagAttributeInfo attr) throws JasperException {
HashMap<String, NameEntry> table = (type == VAR_NAME_FROM) ? nameFromTable : nameTable;
NameEntry nameEntry = table.get(name);
if (nameEntry != null) {
if (!TAG_DYNAMIC.equals(type) ||
!TAG_DYNAMIC.equals(nameEntry.getType())) {
int line = nameEntry.getNode().getStart().getLineNumber();
err.jspError(n, "jsp.error.tagfile.nameNotUnique", type,
nameEntry.getType(), Integer.toString(line));
}
} else {
table.put(name, new NameEntry(type, n, attr));
}
}
/**
* Perform miscellaneous checks after the nodes are visited.
*/
void postCheck() throws JasperException {
// Check that var.name-from-attributes has valid values.
for (Entry<String, NameEntry> entry : nameFromTable.entrySet()) {
String key = entry.getKey();
NameEntry nameEntry = nameTable.get(key);
NameEntry nameFromEntry = entry.getValue();
Node nameFromNode = nameFromEntry.getNode();
if (nameEntry == null) {
err.jspError(nameFromNode,
"jsp.error.tagfile.nameFrom.noAttribute", key);
} else {
Node node = nameEntry.getNode();
TagAttributeInfo tagAttr = nameEntry.getTagAttributeInfo();
if (!"java.lang.String".equals(tagAttr.getTypeName())
|| !tagAttr.isRequired()
|| tagAttr.canBeRequestTime()) {
err.jspError(nameFromNode,
"jsp.error.tagfile.nameFrom.badAttribute",
key, Integer.toString(node.getStart()
.getLineNumber()));
}
}
}
}
public JasperTagInfo(String tagName,
String tagClassName,
String bodyContent,
String infoString,
TagLibraryInfo taglib,
TagExtraInfo tagExtraInfo,
TagAttributeInfo[] attributeInfo,
String displayName,
String smallIcon,
String largeIcon,
TagVariableInfo[] tvi,
String mapName) {
super(tagName, tagClassName, bodyContent, infoString, taglib,
tagExtraInfo, attributeInfo, displayName, smallIcon, largeIcon,
tvi);
this.dynamicAttrsMapName = mapName;
}
public TagInfo getTagInfo() throws JasperException {
if (name == null) {
// XXX Get it from tag file name
}
if (bodycontent == null) {
bodycontent = TagInfo.BODY_CONTENT_SCRIPTLESS;
}
String tagClassName = JspUtil.getTagHandlerClassName(
path, tagLibInfo.getReliableURN(), err);
TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector
.size()];
variableVector.copyInto(tagVariableInfos);
TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector
.size()];
attributeVector.copyInto(tagAttributeInfo);
return new JasperTagInfo(name, tagClassName, bodycontent,
description, tagLibInfo, tei, tagAttributeInfo,
displayName, smallIcon, largeIcon, tagVariableInfos,
dynamicAttrsMapName);
}
private void checkUniqueName(String name, String type, Node n,
TagAttributeInfo attr) throws JasperException {
HashMap<String, NameEntry> table = (VAR_NAME_FROM.equals(type)) ? nameFromTable : nameTable;
NameEntry nameEntry = table.get(name);
if (nameEntry != null) {
if (!TAG_DYNAMIC.equals(type) ||
!TAG_DYNAMIC.equals(nameEntry.getType())) {
int line = nameEntry.getNode().getStart().getLineNumber();
err.jspError(n, "jsp.error.tagfile.nameNotUnique", type,
nameEntry.getType(), Integer.toString(line));
}
} else {
table.put(name, new NameEntry(type, n, attr));
}
}
/**
* Perform miscellaneous checks after the nodes are visited.
*/
void postCheck() throws JasperException {
// Check that var.name-from-attributes has valid values.
for (Entry<String, NameEntry> entry : nameFromTable.entrySet()) {
String key = entry.getKey();
NameEntry nameEntry = nameTable.get(key);
NameEntry nameFromEntry = entry.getValue();
Node nameFromNode = nameFromEntry.getNode();
if (nameEntry == null) {
err.jspError(nameFromNode,
"jsp.error.tagfile.nameFrom.noAttribute", key);
} else {
Node node = nameEntry.getNode();
TagAttributeInfo tagAttr = nameEntry.getTagAttributeInfo();
if (!"java.lang.String".equals(tagAttr.getTypeName())
|| !tagAttr.isRequired()
|| tagAttr.canBeRequestTime()) {
err.jspError(nameFromNode,
"jsp.error.tagfile.nameFrom.badAttribute",
key, Integer.toString(node.getStart()
.getLineNumber()));
}
}
}
}
private void checkUniqueName(String name, Name type, Node n,
TagAttributeInfo attr)
throws JasperException {
HashMap<String, NameEntry> table =
(type == Name.VAR_NAME_FROM)? nameFromTable: nameTable;
NameEntry nameEntry = table.get(name);
if (nameEntry != null) {
if (type != Name.TAG_DYNAMIC
|| nameEntry.getType() != Name.TAG_DYNAMIC) {
int line = nameEntry.getNode().getStart().getLineNumber();
err.jspError(n, "jsp.error.tagfile.nameNotUnique",
type.getAttribute(), type.getDirective(),
nameEntry.getType().getAttribute(),
nameEntry.getType().getDirective(),
Integer.toString(line));
}
} else {
table.put(name, new NameEntry(type, n, attr));
}
}
public TagAttributeInfo toTagAttributeInfo() {
if (fragment) {
// JSP8.5.2: for a fragment type is fixed and rexprvalue is true
type = "javax.servlet.jsp.tagext.JspFragment";
requestTime = true;
} else if (deferredValue) {
type = "javax.el.ValueExpression";
if (expectedTypeName == null) {
expectedTypeName = "java.lang.Object";
}
} else if (deferredMethod) {
type = "javax.el.MethodExpression";
if (methodSignature == null) {
methodSignature = "java.lang.Object method()";
}
}
// According to JSP spec, for static values (those determined at
// translation time) the type is fixed at java.lang.String.
if (!requestTime && type == null) {
type = "java.lang.String";
}
return new TagAttributeInfo(
name,
required,
type,
requestTime,
fragment,
description,
deferredValue,
deferredMethod,
expectedTypeName,
methodSignature);
}
/**
* Checks to see if the attribute of the given name is of type
* JspFragment.
*
* @param name The attribute to check
*
* @return {@code true} if it is a 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;
}
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;
}
/**
* 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, TagAttributeInfo tai, 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;
this.tai = tai;
this.uri = null;
}
/** Adds to the list of items <code>compItemList</code> new Attribute items.
* Only those which are not already in tagDir
* @param sup the syntax support
* @param compItemList list to add to
* @param tagDir tag or directive element
* @param attributeItems list of strings containing suitable values (String or TagAttributeInfo)
* @param currentAttr current attribute, may be null
*/
private void addAttributeItems(CompletionResultSet result, int offset, JspSyntaxSupport sup,
SyntaxElement.TagDirective tagDir, List attributeItems, String currentAttr) {
for (int i = 0; i < attributeItems.size(); i++) {
Object item = attributeItems.get(i);
String attr;
if (item instanceof TagAttributeInfo)
attr = ((TagAttributeInfo)item).getName();
else
attr = (String)item;
boolean isThere = tagDir.getAttributes().keySet().contains(attr);
if (!isThere || attr.equalsIgnoreCase(currentAttr) ||
(currentAttr != null && attr.startsWith(currentAttr) && attr.length()>currentAttr.length() && !isThere)) {
if (item instanceof TagAttributeInfo)
//XXX This is hack for fixing issue #45302 - CC is to aggressive.
//The definition of the tag and declaration doesn't allow
//define something like "prefix [uri | tagdir]". In the future
//it should be rewritten definition of declaration, which allow
//to do it.
if ("taglib".equalsIgnoreCase(tagDir.getName())){ //NOI18N
if (attr.equalsIgnoreCase("prefix") //NOI18N
|| (attr.equalsIgnoreCase("uri") && !tagDir.getAttributes().keySet().contains("tagdir")) //NOI18N
|| (attr.equalsIgnoreCase("tagdir") && !tagDir.getAttributes().keySet().contains("uri"))) //NOI18N
result.addItem(JspCompletionItem.createAttribute(offset, (TagAttributeInfo)item));
} else {
result.addItem(JspCompletionItem.createAttribute(offset, (TagAttributeInfo)item));
} else
result.addItem(JspCompletionItem.createAttribute((String)item, offset));
}
}
}
@Override //method called from default action
public boolean substituteText(JTextComponent c, int len) {
String suffix = isEmpty ? "/>" : ">"; // NOI18N
if (hasAttributes) {
suffix = "";
}
if (!getItemText().startsWith("/")) { // NOI18N
if (!shift) {
return super.substituteText(c, len, 0);
} // NOI18N
boolean hasAttrs = true;
if (tagInfo != null) {
TagAttributeInfo[] tAttrs = tagInfo.getAttributes();
hasAttrs = (tAttrs != null) ? (tAttrs.length > 0) : true;
}
if (hasAttrs) {
return substituteText(c,
getItemText() + (hasAttributes ? "" : " ") + suffix,
len,
suffix.length());
} // NOI18N
else {
return substituteText(c, getItemText() + suffix, len, 0);
}
} else // closing tag
{
return substituteText(c, getItemText().substring(1) + ">", len, 0);
} // NOI18N
}
/**
* 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;
}
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;
}
/**
* 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, TagAttributeInfo tai, 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;
this.tai = null;
}
public TagFileDirectiveVisitor(Compiler compiler,
TagLibraryInfo tagLibInfo, String name, String path) {
err = compiler.getErrorDispatcher();
this.tagLibInfo = tagLibInfo;
this.name = name;
this.path = path;
attributeVector = new Vector<TagAttributeInfo>();
variableVector = new Vector<TagVariableInfo>();
}
/**
* 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;
}
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;
}
/**
* 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, TagAttributeInfo tai, 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;
this.tai = null;
}
public TagFileDirectiveVisitor(Compiler compiler,
TagLibraryInfo tagLibInfo, String name, String path) {
err = compiler.getErrorDispatcher();
this.tagLibInfo = tagLibInfo;
this.name = name;
this.path = path;
attributeVector = new Vector<TagAttributeInfo>();
variableVector = new Vector<TagVariableInfo>();
}
/**
* 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 TagFileDirectiveVisitor(Compiler compiler,
TagLibraryInfo tagLibInfo,
String name,
String path) {
err = compiler.getErrorDispatcher();
this.tagLibInfo = tagLibInfo;
this.name = name;
this.path = path;
attributeVector = new ArrayList<TagAttributeInfo>();
variableVector = new ArrayList<TagVariableInfo>();
jspVersionDouble = Double.valueOf(tagLibInfo.getRequiredVersion());
}