JavaTM 2 Platform
Standard Ed. 6

org.xml.sax.helpers
类 AttributesImpl

java.lang.Object
  继承者 org.xml.sax.helpers.AttributesImpl
所有已实现的接口:
Attributes
直接已知子类:
Attributes2Impl

public class AttributesImpl
extends Object
implements Attributes

Attributes 接口的默认实现。

此模块(包括源代码和文档)位于公共域中,对该模块不提供担保有关更多信息,请参阅http://www.saxproject.org

此类提供 SAX2 Attributes 接口的默认实现,并附带操纵器,以便可以修改或重用列表。

此类有两种典型的用途:

  1. startElement 事件中捕获 Attributes 对象的持久快照;或
  2. 在 SAX2 驱动程序或过滤器中构造或修改 Attributes 对象。

此类可以替换现已不推荐使用的 SAX1 AttributeListImpl 类;除了支持更新的 Attributes 接口(而不是不推荐使用的 AttributeList 接口)外,它还包括使用单个数组(而不是向量集)更加有效的实现。

从以下版本开始:
SAX 2.0

构造方法摘要
AttributesImpl()
          构造一个新的空 AttributesImpl 对象。
AttributesImpl(Attributes atts)
          复制现有 Attributes 对象。
 
方法摘要
 void addAttribute(String uri, String localName, String qName, String type, String value)
          将属性添加到列表的末尾。
 void clear()
          为了重用而清除属性列表。
 int getIndex(String qName)
          通过限定(加前缀的)名称查找属性的索引。
 int getIndex(String uri, String localName)
          通过名称空间名称查找属性的索引。
 int getLength()
          返回列表中的属性个数。
 String getLocalName(int index)
          返回属性的本地名称。
 String getQName(int index)
          返回属性的限定(加前缀的)名称。
 String getType(int index)
          通过索引返回属性的类型。
 String getType(String qName)
          通过限定(加前缀的)名称查找属性的类型。
 String getType(String uri, String localName)
          通过限定名称空间的名称查找属性的类型。
 String getURI(int index)
          返回属性的名称空间 URI。
 String getValue(int index)
          通过索引返回属性的值。
 String getValue(String qName)
          通过限定(加前缀的)名称查找属性的值。
 String getValue(String uri, String localName)
          通过限定名称空间的名称查找属性的值。
 void removeAttribute(int index)
          从列表移除属性。
 void setAttribute(int index, String uri, String localName, String qName, String type, String value)
          在列表中设置属性。
 void setAttributes(Attributes atts)
          复制整个 Attributes 对象。
 void setLocalName(int index, String localName)
          设置特定属性的本地名称。
 void setQName(int index, String qName)
          设置特定属性的限定名称。
 void setType(int index, String type)
          设置特定属性的类型。
 void setURI(int index, String uri)
          设置特定属性的名称空间 URI。
 void setValue(int index, String value)
          设置特定属性的值。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

AttributesImpl

public AttributesImpl()
构造一个新的空 AttributesImpl 对象。


AttributesImpl

public AttributesImpl(Attributes atts)
复制现有 Attributes 对象。

startElement 事件中,此构造方法特别有用。

参数:
atts - 现有 Attributes 对象。
方法详细信息

getLength

public int getLength()
返回列表中的属性个数。

指定者:
接口 Attributes 中的 getLength
返回:
此列表中的属性个数。
另请参见:
Attributes.getLength()

getURI

public String getURI(int index)
返回属性的名称空间 URI。

指定者:
接口 Attributes 中的 getURI
参数:
index - 属性的索引(从零开始)。
返回:
名称空间 URI,如果没有可用的,则返回空字符串;如果索引超出范围,则返回 null。
另请参见:
Attributes.getURI(int)

getLocalName

public String getLocalName(int index)
返回属性的本地名称。

指定者:
接口 Attributes 中的 getLocalName
参数:
index - 属性的索引(从零开始)。
返回:
属性的本地名称,如果没有,则返回空字符串;如果索引超出范围,则返回 null。
另请参见:
Attributes.getLocalName(int)

getQName

public String getQName(int index)
返回属性的限定(加前缀的)名称。

指定者:
接口 Attributes 中的 getQName
参数:
index - 属性的索引(从零开始)。
返回:
属性的限定名称,如果没有可用的,则返回空字符串;如果索引超出范围,则返回 null。
另请参见:
Attributes.getQName(int)

getType

public String getType(int index)
通过索引返回属性的类型。

指定者:
接口 Attributes 中的 getType
参数:
index - 属性的索引(从零开始)。
返回:
属性的类型,如果类型是未知的,则返回 "CDATA";如果索引超出范围,则返回 null。
另请参见:
Attributes.getType(int)

getValue

public String getValue(int index)
通过索引返回属性的值。

指定者:
接口 Attributes 中的 getValue
参数:
index - 属性的索引(从零开始)。
返回:
属性的值,如果索引超出范围,则返回 null。
另请参见:
Attributes.getValue(int)

getIndex

public int getIndex(String uri,
                    String localName)
通过名称空间名称查找属性的索引。

在许多情况下,查找一次名称并使用索引查询方法而不重复使用名称查询方法是非常有效的。

指定者:
接口 Attributes 中的 getIndex
参数:
uri - 属性的名称空间 URI,如果没有可用的,则为空字符串。
localName - 属性的本地名称。
返回:
属性的索引,如果没有任何内容相匹配,则返回 -1。
另请参见:
Attributes.getIndex(java.lang.String,java.lang.String)

getIndex

public int getIndex(String qName)
通过限定(加前缀的)名称查找属性的索引。

指定者:
接口 Attributes 中的 getIndex
参数:
qName - 限定的名称。
返回:
属性的索引,如果没有任何内容相匹配,则返回 -1。
另请参见:
Attributes.getIndex(java.lang.String)

getType

public String getType(String uri,
                      String localName)
通过限定名称空间的名称查找属性的类型。

指定者:
接口 Attributes 中的 getType
参数:
uri - 名称空间 URI,对于不带显式的名称空间 URI 的名称,则为空字符串。
localName - 本地名称。
返回:
属性的类型,如果没有任何匹配的属性,则为 null。
另请参见:
Attributes.getType(java.lang.String,java.lang.String)

getType

public String getType(String qName)
通过限定(加前缀的)名称查找属性的类型。

指定者:
接口 Attributes 中的 getType
参数:
qName - 限定的名称。
返回:
属性的类型,如果没有任何匹配的属性,则为 null。
另请参见:
Attributes.getType(java.lang.String)

getValue

public String getValue(String uri,
                       String localName)
通过限定名称空间的名称查找属性的值。

指定者:
接口 Attributes 中的 getValue
参数:
uri - 名称空间 URI,对于不带显式名称空间 URI 的名称,则为空字符串。
localName - 本地名称。
返回:
属性的值,如果没有任何匹配的属性,则为 null。
另请参见:
Attributes.getValue(java.lang.String,java.lang.String)

getValue

public String getValue(String qName)
通过限定(加前缀的)名称查找属性的值。

指定者:
接口 Attributes 中的 getValue
参数:
qName - 限定的名称。
返回:
属性的值,如果没有任何匹配的属性,则为 null。
另请参见:
Attributes.getValue(java.lang.String)

clear

public void clear()
为了重用而清除属性列表。

注意,此调用几乎不释放内存:保存当前数组,以便重用。


setAttributes

public void setAttributes(Attributes atts)
复制整个 Attributes 对象。

重用现有对象比不断分配新对象更高效。

参数:
atts - 要复制的属性。

addAttribute

public void addAttribute(String uri,
                         String localName,
                         String qName,
                         String type,
                         String value)
将属性添加到列表的末尾。

由于速度的原因,此方法将不进行检查以查看属性是否已在列表中:这由应用程序负责。

参数:
uri - 名称空间 URI,如果没有可用的,或不是正在执行名称空间处理,则为空字符串。
localName - 本地名称,如果不是正在执行名称空间处理,则为空字符串。
qName - 限定(加前缀的)名称,如果限定名称不可用,则为空字符串。
type - 字符串形式的属性类型。
value - 属性值。

setAttribute

public void setAttribute(int index,
                         String uri,
                         String localName,
                         String qName,
                         String type,
                         String value)
在列表中设置属性。

由于速度的原因,此方法不检查名称是否冲突或格式是否良好:此类检查由应用程序负责。

参数:
index - 属性的索引(从零开始)。
uri - 名称空间 URI,如果没有,或不是正在执行名称空间处理,则为空字符串。
localName - 本地名称,如果不是正在执行名称空间处理,则为空字符串。
qName - 限定的名称,如果限定的名称不可用,则为空字符串。
type - 字符串形式的属性类型。
value - 属性值。
抛出:
ArrayIndexOutOfBoundsException - 当提供的索引不指向列表中的属性时。

removeAttribute

public void removeAttribute(int index)
从列表移除属性。

参数:
index - 属性的索引(从零开始)。
抛出:
ArrayIndexOutOfBoundsException - 当提供的索引不指向列表中的属性时。

setURI

public void setURI(int index,
                   String uri)
设置特定属性的名称空间 URI。

参数:
index - 属性的索引(从零开始)。
uri - 属性的名称空间 URI,如果没有,则为空字符串。
抛出:
ArrayIndexOutOfBoundsException - 当提供的索引不指向列表中的属性时。

setLocalName

public void setLocalName(int index,
                         String localName)
设置特定属性的本地名称。

参数:
index - 属性的索引(从零开始)。
localName - 属性的本地名称,如果没有,则为空字符串。
抛出:
ArrayIndexOutOfBoundsException - 当提供的索引不指向列表中的属性时。

setQName

public void setQName(int index,
                     String qName)
设置特定属性的限定名称。

参数:
index - 属性的索引(从零开始)。
qName - 属性的限定名称,如果没有,则为空字符串。
抛出:
ArrayIndexOutOfBoundsException - 当提供的索引不指向列表中的属性时。

setType

public void setType(int index,
                    String type)
设置特定属性的类型。

参数:
index - 属性的索引(从零开始)。
type - 属性的类型。
抛出:
ArrayIndexOutOfBoundsException - 当提供的索引不指向列表中的属性时。

setValue

public void setValue(int index,
                     String value)
设置特定属性的值。

参数:
index - 属性的索引(从零开始)。
value - 属性的值。
抛出:
ArrayIndexOutOfBoundsException - 当提供的索引不指向列表中的属性时。

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only