Methods Summary |
---|
public int | addAttribute(org.apache.xerces.xni.QName name, java.lang.String type, java.lang.String value)Adds an attribute. The attribute's non-normalized value of the
attribute will have the same value as the attribute value until
set using the setNonNormalizedValue method. Also,
the added attribute will be marked as specified in the XML instance
document unless set otherwise using the setSpecified
method.
Note: If an attribute of the same name already
exists, the old values for the attribute are replaced by the new
values.
int index;
if (fLength < SIZE_LIMIT) {
index = name.uri != null && !name.uri.equals("")
? getIndexFast(name.uri, name.localpart)
: getIndexFast(name.rawname);
if (index == -1) {
index = fLength;
if (fLength++ == fAttributes.length) {
Attribute[] attributes = new Attribute[fAttributes.length + 4];
System.arraycopy(fAttributes, 0, attributes, 0, fAttributes.length);
for (int i = fAttributes.length; i < attributes.length; i++) {
attributes[i] = new Attribute();
}
fAttributes = attributes;
}
}
}
else if (name.uri == null ||
name.uri.length() == 0 ||
(index = getIndexFast(name.uri, name.localpart)) == -1) {
/**
* If attributes were removed from the list after the table
* becomes in use this isn't reflected in the table view. It's
* assumed that once a user starts removing attributes they're
* not likely to add more. We only make the view consistent if
* the user of this class adds attributes, removes them, and
* then adds more.
*/
if (!fIsTableViewConsistent || fLength == SIZE_LIMIT) {
prepareAndPopulateTableView();
fIsTableViewConsistent = true;
}
int bucket = getTableViewBucket(name.rawname);
// The chain is stale.
// This must be a unique attribute.
if (fAttributeTableViewChainState[bucket] != fLargeCount) {
index = fLength;
if (fLength++ == fAttributes.length) {
Attribute[] attributes = new Attribute[fAttributes.length << 1];
System.arraycopy(fAttributes, 0, attributes, 0, fAttributes.length);
for (int i = fAttributes.length; i < attributes.length; i++) {
attributes[i] = new Attribute();
}
fAttributes = attributes;
}
// Update table view.
fAttributeTableViewChainState[bucket] = fLargeCount;
fAttributes[index].next = null;
fAttributeTableView[bucket] = fAttributes[index];
}
// This chain is active.
// We need to check if any of the attributes has the same rawname.
else {
// Search the table.
Attribute found = fAttributeTableView[bucket];
while (found != null) {
if (found.name.rawname == name.rawname) {
break;
}
found = found.next;
}
// This attribute is unique.
if (found == null) {
index = fLength;
if (fLength++ == fAttributes.length) {
Attribute[] attributes = new Attribute[fAttributes.length << 1];
System.arraycopy(fAttributes, 0, attributes, 0, fAttributes.length);
for (int i = fAttributes.length; i < attributes.length; i++) {
attributes[i] = new Attribute();
}
fAttributes = attributes;
}
// Update table view
fAttributes[index].next = fAttributeTableView[bucket];
fAttributeTableView[bucket] = fAttributes[index];
}
// Duplicate. We still need to find the index.
else {
index = getIndexFast(name.rawname);
}
}
}
// set values
Attribute attribute = fAttributes[index];
attribute.name.setValues(name);
attribute.type = type;
attribute.value = value;
attribute.nonNormalizedValue = value;
attribute.specified = false;
// clear augmentations
attribute.augs.removeAllItems();
return index;
|
public void | addAttributeNS(org.apache.xerces.xni.QName name, java.lang.String type, java.lang.String value)Adds an attribute. The attribute's non-normalized value of the
attribute will have the same value as the attribute value until
set using the setNonNormalizedValue method. Also,
the added attribute will be marked as specified in the XML instance
document unless set otherwise using the setSpecified
method.
This method differs from addAttribute in that it
does not check if an attribute of the same name already exists
in the list before adding it. In order to improve performance
of namespace processing, this method allows uniqueness checks
to be deferred until all the namespace information is available
after the entire attribute specification has been read.
Caution: If this method is called it should
not be mixed with calls to addAttribute unless
it has been determined that all the attribute names are unique.
int index = fLength;
if (fLength++ == fAttributes.length) {
Attribute[] attributes;
if (fLength < SIZE_LIMIT) {
attributes = new Attribute[fAttributes.length + 4];
}
else {
attributes = new Attribute[fAttributes.length << 1];
}
System.arraycopy(fAttributes, 0, attributes, 0, fAttributes.length);
for (int i = fAttributes.length; i < attributes.length; i++) {
attributes[i] = new Attribute();
}
fAttributes = attributes;
}
// set values
Attribute attribute = fAttributes[index];
attribute.name.setValues(name);
attribute.type = type;
attribute.value = value;
attribute.nonNormalizedValue = value;
attribute.specified = false;
// clear augmentations
attribute.augs.removeAllItems();
|
public org.apache.xerces.xni.QName | checkDuplicatesNS()Checks for duplicate expanded names (local part and namespace name
pairs) in the attribute specification. If a duplicate is found its
name is returned.
This should be called once all the in-scope namespaces for the element
enclosing these attributes is known, and after all the attributes
have gone through namespace binding.
// If the list is small check for duplicates using pairwise comparison.
if (fLength <= SIZE_LIMIT) {
for (int i = 0; i < fLength - 1; ++i) {
Attribute att1 = fAttributes[i];
for (int j = i + 1; j < fLength; ++j) {
Attribute att2 = fAttributes[j];
if (att1.name.localpart == att2.name.localpart &&
att1.name.uri == att2.name.uri) {
return att2.name;
}
}
}
}
// If the list is large check duplicates using a hash table.
else {
// We don't want this table view to be read if someone calls
// addAttribute so we invalidate it up front.
fIsTableViewConsistent = false;
prepareTableView();
Attribute attr;
int bucket;
for (int i = fLength - 1; i >= 0; --i) {
attr = fAttributes[i];
bucket = getTableViewBucket(attr.name.localpart, attr.name.uri);
// The chain is stale.
// This must be a unique attribute.
if (fAttributeTableViewChainState[bucket] != fLargeCount) {
fAttributeTableViewChainState[bucket] = fLargeCount;
attr.next = null;
fAttributeTableView[bucket] = attr;
}
// This chain is active.
// We need to check if any of the attributes has the same name.
else {
// Search the table.
Attribute found = fAttributeTableView[bucket];
while (found != null) {
if (found.name.localpart == attr.name.localpart &&
found.name.uri == attr.name.uri) {
return attr.name;
}
found = found.next;
}
// Update table view
attr.next = fAttributeTableView[bucket];
fAttributeTableView[bucket] = attr;
}
}
}
return null;
|
protected void | cleanTableView()Purges all elements from the table view.
if (++fLargeCount < 0) {
// Overflow. We actually need to visit the chain state array.
if (fAttributeTableViewChainState != null) {
for (int i = fTableViewBuckets - 1; i >= 0; --i) {
fAttributeTableViewChainState[i] = 0;
}
}
fLargeCount = 1;
}
|
public org.apache.xerces.xni.Augmentations | getAugmentations(java.lang.String uri, java.lang.String localName)Look up an augmentations by Namespace name.
int index = getIndex(uri, localName);
return index != -1 ? fAttributes[index].augs : null;
|
public org.apache.xerces.xni.Augmentations | getAugmentations(java.lang.String qName)Look up an augmentation by XML 1.0 qualified name.
int index = getIndex(qName);
return index != -1 ? fAttributes[index].augs : null;
|
public org.apache.xerces.xni.Augmentations | getAugmentations(int attributeIndex)Look up an augmentations by attributes index.
if (attributeIndex < 0 || attributeIndex >= fLength) {
return null;
}
return fAttributes[attributeIndex].augs;
|
public int | getIndex(java.lang.String qName)Look up the index of an attribute by XML 1.0 qualified name.
for (int i = 0; i < fLength; i++) {
Attribute attribute = fAttributes[i];
if (attribute.name.rawname != null &&
attribute.name.rawname.equals(qName)) {
return i;
}
}
return -1;
|
public int | getIndex(java.lang.String uri, java.lang.String localPart)Look up the index of an attribute by Namespace name.
for (int i = 0; i < fLength; i++) {
Attribute attribute = fAttributes[i];
if (attribute.name.localpart != null &&
attribute.name.localpart.equals(localPart) &&
((uri==attribute.name.uri) ||
(uri!=null && attribute.name.uri!=null && attribute.name.uri.equals(uri))))
{
return i;
}
}
return -1;
|
public int | getIndexFast(java.lang.String qName)Look up the index of an attribute by XML 1.0 qualified name.
Note:
This method uses reference comparison, and thus should
only be used internally. We cannot use this method in any
code exposed to users as they may not pass in unique strings.
for (int i = 0; i < fLength; ++i) {
Attribute attribute = fAttributes[i];
if (attribute.name.rawname == qName) {
return i;
}
}
return -1;
|
public int | getIndexFast(java.lang.String uri, java.lang.String localPart)Look up the index of an attribute by Namespace name.
Note:
This method uses reference comparison, and thus should
only be used internally. We cannot use this method in any
code exposed to users as they may not pass in unique strings.
for (int i = 0; i < fLength; ++i) {
Attribute attribute = fAttributes[i];
if (attribute.name.localpart == localPart &&
attribute.name.uri == uri) {
return i;
}
}
return -1;
|
public int | getLength()Return the number of attributes in the list.
Once you know the number of attributes, you can iterate
through the list.
return fLength;
|
public java.lang.String | getLocalName(int index)Look up an attribute's local name by index.
if (!fNamespaces) {
return "";
}
if (index < 0 || index >= fLength) {
return null;
}
return fAttributes[index].name.localpart;
|
public java.lang.String | getName(int index)Return the name of an attribute in this list (by position).
The names must be unique: the SAX parser shall not include the
same attribute twice. Attributes without values (those declared
#IMPLIED without a value specified in the start tag) will be
omitted from the list.
If the attribute name has a namespace prefix, the prefix
will still be attached.
if (index < 0 || index >= fLength) {
return null;
}
return fAttributes[index].name.rawname;
|
public void | getName(int attrIndex, org.apache.xerces.xni.QName attrName)Sets the fields in the given QName structure with the values
of the attribute name at the specified index.
attrName.setValues(fAttributes[attrIndex].name);
|
public java.lang.String | getNonNormalizedValue(int attrIndex)Returns the non-normalized value of the attribute at the specified
index. If no non-normalized value is set, this method will return
the same value as the getValue(int) method.
String value = fAttributes[attrIndex].nonNormalizedValue;
return value;
|
public java.lang.String | getPrefix(int index)Returns the prefix of the attribute at the specified index.
if (index < 0 || index >= fLength) {
return null;
}
String prefix = fAttributes[index].name.prefix;
// REVISIT: The empty string is not entered in the symbol table!
return prefix != null ? prefix : "";
|
public java.lang.String | getQName(int index)Look up an attribute's XML 1.0 qualified name by index.
if (index < 0 || index >= fLength) {
return null;
}
String rawname = fAttributes[index].name.rawname;
return rawname != null ? rawname : "";
|
private java.lang.String | getReportableType(java.lang.String type)Returns the value passed in or NMTOKEN if it's an enumerated type.
if (type.charAt(0) == '(") {
return "NMTOKEN";
}
return type;
|
public boolean | getSchemaId(int index)
if (index < 0 || index >= fLength) {
return false;
}
return fAttributes[index].schemaId;
|
public boolean | getSchemaId(java.lang.String qname)
int index = getIndex(qname);
return index != -1 ? fAttributes[index].schemaId : false;
|
public boolean | getSchemaId(java.lang.String uri, java.lang.String localName)
if (!fNamespaces) {
return false;
}
int index = getIndex(uri, localName);
return index != -1 ? fAttributes[index].schemaId : false;
|
protected int | getTableViewBucket(java.lang.String qname)Returns the position in the table view
where the given attribute name would be hashed.
return (qname.hashCode() & 0x7FFFFFFF) % fTableViewBuckets;
|
protected int | getTableViewBucket(java.lang.String localpart, java.lang.String uri)Returns the position in the table view
where the given attribute name would be hashed.
if (uri == null) {
return (localpart.hashCode() & 0x7FFFFFFF) % fTableViewBuckets;
}
else {
return ((localpart.hashCode() + uri.hashCode())
& 0x7FFFFFFF) % fTableViewBuckets;
}
|
public java.lang.String | getType(int index)Look up an attribute's type by index.
The attribute type is one of the strings "CDATA", "ID",
"IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
or "NOTATION" (always in upper case).
If the parser has not read a declaration for the attribute,
or if the parser does not report attribute types, then it must
return the value "CDATA" as stated in the XML 1.0 Recommentation
(clause 3.3.3, "Attribute-Value Normalization").
For an enumerated attribute that is not a notation, the
parser will report the type as "NMTOKEN".
if (index < 0 || index >= fLength) {
return null;
}
return getReportableType(fAttributes[index].type);
|
public java.lang.String | getType(java.lang.String qname)Look up an attribute's type by XML 1.0 qualified name.
See {@link #getType(int) getType(int)} for a description
of the possible types.
int index = getIndex(qname);
return index != -1 ? getReportableType(fAttributes[index].type) : null;
|
public java.lang.String | getType(java.lang.String uri, java.lang.String localName)Look up an attribute's type by Namespace name.
See {@link #getType(int) getType(int)} for a description
of the possible types.
if (!fNamespaces) {
return null;
}
int index = getIndex(uri, localName);
return index != -1 ? getReportableType(fAttributes[index].type) : null;
|
public java.lang.String | getURI(int index)Look up an attribute's Namespace URI by index.
if (index < 0 || index >= fLength) {
return null;
}
String uri = fAttributes[index].name.uri;
return uri;
|
public java.lang.String | getValue(int index)Look up an attribute's value by index.
If the attribute value is a list of tokens (IDREFS,
ENTITIES, or NMTOKENS), the tokens will be concatenated
into a single string with each token separated by a
single space.
if (index < 0 || index >= fLength) {
return null;
}
return fAttributes[index].value;
|
public java.lang.String | getValue(java.lang.String qname)Look up an attribute's value by XML 1.0 qualified name.
See {@link #getValue(int) getValue(int)} for a description
of the possible values.
int index = getIndex(qname);
return index != -1 ? fAttributes[index].value : null;
|
public java.lang.String | getValue(java.lang.String uri, java.lang.String localName)Look up an attribute's value by Namespace name.
See {@link #getValue(int) getValue(int)} for a description
of the possible values.
int index = getIndex(uri, localName);
return index != -1 ? getValue(index) : null;
|
public boolean | isSpecified(int attrIndex)Returns true if the attribute is specified in the instance document.
return fAttributes[attrIndex].specified;
|
protected void | prepareAndPopulateTableView()Prepares the table view of the attributes list for use,
and populates it with the attributes which have been
previously read.
prepareTableView();
// Need to populate the hash table with the attributes we've scanned so far.
Attribute attr;
int bucket;
for (int i = 0; i < fLength; ++i) {
attr = fAttributes[i];
bucket = getTableViewBucket(attr.name.rawname);
if (fAttributeTableViewChainState[bucket] != fLargeCount) {
fAttributeTableViewChainState[bucket] = fLargeCount;
attr.next = null;
fAttributeTableView[bucket] = attr;
}
else {
// Update table view
attr.next = fAttributeTableView[bucket];
fAttributeTableView[bucket] = attr;
}
}
|
protected void | prepareTableView()Prepares the table view of the attributes list for use.
if (fAttributeTableView == null) {
fAttributeTableView = new Attribute[fTableViewBuckets];
fAttributeTableViewChainState = new int[fTableViewBuckets];
}
else {
cleanTableView();
}
|
public void | removeAllAttributes()Removes all of the attributes. This method will also remove all
entities associated to the attributes.
fLength = 0;
|
public void | removeAttributeAt(int attrIndex)Removes the attribute at the specified index.
Note: This operation changes the indexes of all
attributes following the attribute at the specified index.
fIsTableViewConsistent = false;
if (attrIndex < fLength - 1) {
Attribute removedAttr = fAttributes[attrIndex];
System.arraycopy(fAttributes, attrIndex + 1,
fAttributes, attrIndex, fLength - attrIndex - 1);
// Make the discarded Attribute object available for re-use
// by tucking it after the Attributes that are still in use
fAttributes[fLength-1] = removedAttr;
}
fLength--;
|
public void | setAugmentations(int attrIndex, org.apache.xerces.xni.Augmentations augs)Sets the augmentations of the attribute at the specified index.
fAttributes[attrIndex].augs = augs;
|
public void | setName(int attrIndex, org.apache.xerces.xni.QName attrName)Sets the name of the attribute at the specified index.
fAttributes[attrIndex].name.setValues(attrName);
|
public void | setNamespaces(boolean namespaces)Sets whether namespace processing is being performed. This state
is needed to return the correct value from the getLocalName method.
fNamespaces = namespaces;
|
public void | setNonNormalizedValue(int attrIndex, java.lang.String attrValue)Sets the non-normalized value of the attribute at the specified
index.
if (attrValue == null) {
attrValue = fAttributes[attrIndex].value;
}
fAttributes[attrIndex].nonNormalizedValue = attrValue;
|
public void | setSchemaId(int attrIndex, boolean schemaId)
fAttributes[attrIndex].schemaId = schemaId;
|
public void | setSpecified(int attrIndex, boolean specified)Sets whether an attribute is specified in the instance document
or not.
fAttributes[attrIndex].specified = specified;
|
public void | setType(int attrIndex, java.lang.String attrType)Sets the type of the attribute at the specified index.
fAttributes[attrIndex].type = attrType;
|
public void | setURI(int attrIndex, java.lang.String uri)Sets the uri of the attribute at the specified index.
fAttributes[attrIndex].name.uri = uri;
|
public void | setValue(int attrIndex, java.lang.String attrValue)Sets the value of the attribute at the specified index. This
method will overwrite the non-normalized value of the attribute.
Attribute attribute = fAttributes[attrIndex];
attribute.value = attrValue;
attribute.nonNormalizedValue = attrValue;
|