本文整理汇总了Java中org.xml.sax.AttributeList.getName方法的典型用法代码示例。如果您正苦于以下问题:Java AttributeList.getName方法的具体用法?Java AttributeList.getName怎么用?Java AttributeList.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xml.sax.AttributeList
的用法示例。
在下文中一共展示了AttributeList.getName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.xml.sax.AttributeList; //导入方法依赖的package包/类
/**
* Initialisation routine called after handler creation
* with the element name and attributes. The attributes which
* this handler can deal with are: <code>"default"</code>,
* <code>"name"</code>, <code>"id"</code> and <code>"basedir"</code>.
*
* @param tag Name of the element which caused this handler
* to be created. Should not be <code>null</code>.
* Ignored in this implementation.
* @param attrs Attributes of the element which caused this
* handler to be created. Must not be <code>null</code>.
*
* @exception SAXParseException if an unexpected attribute is
* encountered or if the <code>"default"</code> attribute
* is missing.
*/
public void init(String tag, AttributeList attrs) throws SAXParseException {
String def = null;
String name = null;
String id = null;
String baseDir = null;
for (int i = 0; i < attrs.getLength(); i++) {
String key = attrs.getName(i);
String value = attrs.getValue(i);
if ("default".equals(key)) {
def = value;
} else if ("name".equals(key)) {
name = value;
} else if ("id".equals(key)) {
id = value;
} else if ("basedir".equals(key)) {
baseDir = value;
} else {
throw new SAXParseException(
"Unexpected attribute \"" + attrs.getName(i)
+ "\"", helperImpl.locator);
}
}
if (def != null && !def.isEmpty()) {
helperImpl.project.setDefault(def);
} else {
throw new BuildException("The default attribute is required");
}
if (name != null) {
helperImpl.project.setName(name);
helperImpl.project.addReference(name, helperImpl.project);
}
if (id != null) {
helperImpl.project.addReference(id, helperImpl.project);
}
if (helperImpl.project.getProperty("basedir") != null) {
helperImpl.project.setBasedir(helperImpl.project.getProperty("basedir"));
} else {
if (baseDir == null) {
helperImpl.project.setBasedir(helperImpl.buildFileParent.getAbsolutePath());
} else {
// check whether the user has specified an absolute path
if ((new File(baseDir)).isAbsolute()) {
helperImpl.project.setBasedir(baseDir);
} else {
File resolvedBaseDir = FILE_UTILS.resolveFile(helperImpl.buildFileParent,
baseDir);
helperImpl.project.setBaseDir(resolvedBaseDir);
}
}
}
helperImpl.project.addTarget("", helperImpl.implicitTarget);
}
示例2: startElement
import org.xml.sax.AttributeList; //导入方法依赖的package包/类
/** Start element. */
public void startElement(String name, AttributeList attributes)
throws SAXException {
printIndent();
fOut.print("startElement(");
fOut.print("name=");
printQuotedString(name);
fOut.print(',');
fOut.print("attributes=");
if (attributes == null) {
fOut.println("null");
}
else {
fOut.print('{');
int length = attributes.getLength();
for (int i = 0; i < length; i++) {
if (i > 0) {
System.out.print(',');
}
String attrName = attributes.getName(i);
String attrType = attributes.getType(i);
String attrValue = attributes.getValue(i);
fOut.print('{');
fOut.print("name=");
printQuotedString(attrName);
fOut.print(',');
fOut.print("type=");
printQuotedString(attrType);
fOut.print(',');
fOut.print("value=");
printQuotedString(attrValue);
fOut.print('}');
}
fOut.print('}');
}
fOut.println(')');
fOut.flush();
fIndent++;
}