An Attributes implementation that can perform more operations
than the attribute list helper supplied with the standard SAX2
distribution.
| Method from sax.helpers.AttributesImpl Detail: |
public void addAttribute(String raw,
String type,
String value) {
addAttribute(null, null, raw, type, value);
}
|
public void addAttribute(String uri,
String local,
String raw,
String type,
String value) {
ListNode node = new ListNode(uri, local, raw, type, value);
if (length == 0) {
head = node;
}
else {
tail.next = node;
}
tail = node;
length++;
}
|
public int getIndex(String raw) {
ListNode place = head;
int index = 0;
while (place != null) {
if (place.raw.equals(raw)) {
return index;
}
index++;
place = place.next;
}
return -1;
}
Returns the index of the specified attribute. |
public int getIndex(String uri,
String local) {
ListNode place = head;
int index = 0;
while (place != null) {
if (place.uri.equals(uri) && place.local.equals(local)) {
return index;
}
index++;
place = place.next;
}
return -1;
}
Returns the index of the specified attribute. |
public int getLength() {
return length;
}
Returns the number of attributes. |
public AttributesImpl.ListNode getListNode(String uri,
String local) {
if (uri != null && local != null) {
ListNode place = head;
while (place != null) {
if (place.uri != null && place.local != null &&
place.uri.equals(uri) && place.local.equals(local)) {
return place;
}
place = place.next;
}
}
return null;
}
Returns the first node with the specified uri and local. |
public String getLocalName(int index) {
ListNode node = getListNodeAt(index);
return node != null ? node.local : null;
}
Returns the attribute local name by index. |
public String getQName(int index) {
ListNode node = getListNodeAt(index);
return node != null ? node.raw : null;
}
Returns the attribute raw name by index. |
public String getType(int index) {
ListNode node = getListNodeAt(index);
return (node != null) ? node.type : null;
}
Returns the attribute type by index. |
public String getType(String raw) {
ListNode node = getListNode(raw);
return (node != null) ? node.type : null;
}
Returns the attribute type by raw name. |
public String getType(String uri,
String local) {
ListNode node = getListNode(uri, local);
return (node != null) ? node.type : null;
}
Returns the attribute type by uri and local. |
public String getURI(int index) {
ListNode node = getListNodeAt(index);
return node != null ? node.uri : null;
}
Returns the attribute URI by index. |
public String getValue(int index) {
ListNode node = getListNodeAt(index);
return (node != null) ? node.value : null;
}
Returns the attribute value by index. |
public String getValue(String raw) {
ListNode node = getListNode(raw);
return (node != null) ? node.value : null;
}
Returns the attribute value by raw name. |
public String getValue(String uri,
String local) {
ListNode node = getListNode(uri, local);
return (node != null) ? node.value : null;
}
Returns the attribute value by uri and local. |
public void insertAttributeAt(int index,
String raw,
String type,
String value) {
insertAttributeAt(index, null, null, raw, type, value);
}
|
public void insertAttributeAt(int index,
String uri,
String local,
String raw,
String type,
String value) {
// if list is empty, add attribute
if (length == 0 || index >= length) {
addAttribute(uri, local, raw, type, value);
return;
}
// insert at beginning of list
ListNode node = new ListNode(uri, local, raw, type, value);
if (index < 1) {
node.next = head;
head = node;
}
else {
ListNode prev = getListNodeAt(index - 1);
node.next = prev.next;
prev.next = node;
}
length++;
}
|
public void removeAttribute(String raw) {
removeAttributeAt(getIndex(raw));
}
Removes the specified attribute. |
public void removeAttribute(String uri,
String local) {
removeAttributeAt(getIndex(uri, local));
}
Removes the specified attribute. |
public void removeAttributeAt(int index) {
if (length == 0) {
return;
}
if (index == 0) {
head = head.next;
if (head == null) {
tail = null;
}
length--;
}
else {
ListNode prev = getListNodeAt(index - 1);
ListNode node = getListNodeAt(index);
if (node != null) {
prev.next = node.next;
if (node == tail) {
tail = prev;
}
length--;
}
}
}
|
public String toString() {
StringBuffer str = new StringBuffer();
str.append('[");
str.append("len=");
str.append(length);
str.append(", {");
for (ListNode place = head; place != null; place = place.next) {
str.append(place.toString());
if (place.next != null) {
str.append(", ");
}
}
str.append("}]");
return str.toString();
}
Returns a string representation of this object. |