Package org.apache.pivot.xml
Class Element
- java.lang.Object
-
- org.apache.pivot.xml.Node
-
- org.apache.pivot.xml.Element
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classElement.AttributeClass representing an XML attribute.classElement.AttributeSequenceSequence representing the attributes declared by this element.classElement.ElementDictionaryDictionary representing the attributes declared by this element.classElement.NamespaceDictionaryDictionary representing the namespaces declared by this element.-
Nested classes/interfaces inherited from interface org.apache.pivot.collections.List
List.ItemIterator<T>, List.ListListenerList<T>
-
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Sequence
Sequence.Tree<T>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intadd(Node node)Adds a node to this element.voidclear()Removes all nodes from this element.Nodeget(int index)Returns the node at the given index.Element.AttributeSequencegetAttributes()java.util.Comparator<Node>getComparator()Returns the collection's sort order.java.lang.StringgetDefaultNamespaceURI()Returns the element's default namespace URI.Element.ElementDictionarygetElementDictionary()ListenerList<ElementListener>getElementListeners()List<Element>getElements(java.lang.String name)Returns the sub-elements of of this element whose tag names match the given name.intgetLength()Returns the number of nodes contained by this element.ListenerList<ListListener<Node>>getListListeners()Returns the list listener list.java.lang.StringgetLocalName()java.lang.StringgetName()Returns the fully-qualified name of the element.java.lang.StringgetNamespacePrefix()Returns the element's namespace prefix.Element.NamespaceDictionarygetNamespaces()java.lang.StringgetNamespaceURI(java.lang.String prefix)Determines the namespace URI corresponding to the given prefix by traversing the element's ancestry.java.lang.StringgetText()Returns the text content of this element.intindexOf(Node node)Determines the index of the given node within this element.voidinsert(Node node, int index)Inserts a node at a specific location within this element.booleanisEmpty()Determines if this element defines any attributes.java.util.Iterator<Node>iterator()Returns an iterator over this elements child nodes.Sequence<Node>remove(int index, int count)Removes a range of nodes from this element.intremove(Node node)Removes a node from this element.voidsetComparator(java.util.Comparator<Node> comparator)Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.voidsetDefaultNamespaceURI(java.lang.String defaultNamespaceURI)Sets the element's default namespace URI.java.lang.StringtoString()Nodeupdate(int index, Node node)Updates the item at the given index.-
Methods inherited from class org.apache.pivot.xml.Node
getNodeListeners, getParent, setParent
-
-
-
-
Method Detail
-
getNamespacePrefix
public java.lang.String getNamespacePrefix()
Returns the element's namespace prefix.- Returns:
- The element's namespace prefix, or
nullif the element belongs to the default namespace.
-
getLocalName
public java.lang.String getLocalName()
- Returns:
- The element's local name.
-
getName
public java.lang.String getName()
Returns the fully-qualified name of the element.- Returns:
- The local name if no namespace is defined, or the fully-qualified name if there is a namespace.
-
getDefaultNamespaceURI
public java.lang.String getDefaultNamespaceURI()
Returns the element's default namespace URI.- Returns:
- The default namespace URI declared by this element, or
nullif this element does not declare a default namespace.
-
setDefaultNamespaceURI
public void setDefaultNamespaceURI(java.lang.String defaultNamespaceURI)
Sets the element's default namespace URI.- Parameters:
defaultNamespaceURI- The default namespace URI declared by this element, ornullif this element does not declare a default namespace.
-
getNamespaces
public Element.NamespaceDictionary getNamespaces()
- Returns:
- The element's namespace dictionary.
-
getNamespaceURI
public java.lang.String getNamespaceURI(java.lang.String prefix)
Determines the namespace URI corresponding to the given prefix by traversing the element's ancestry.- Parameters:
prefix- The namespace prefix to look up, ornullto determine the default namespace for this element.- Returns:
- The namespace URI corresponding to the given prefix, or
nullif a URI could not be found.
-
getElementDictionary
public Element.ElementDictionary getElementDictionary()
- Returns:
- The element's element dictionary.
-
getAttributes
public Element.AttributeSequence getAttributes()
- Returns:
- The element's attribute dictionary.
-
add
public int add(Node node)
Adds a node to this element.- Specified by:
addin interfaceList<Node>- Specified by:
addin interfaceSequence<Node>- Parameters:
node- The node to be added.- Returns:
- The index at which the node was added.
- Throws:
java.lang.IllegalArgumentException- if the node already has a parent.- See Also:
ListListener.itemInserted(List, int)
-
insert
public void insert(Node node, int index)
Inserts a node at a specific location within this element.
-
update
@UnsupportedOperation public Node update(int index, Node node)
Description copied from interface:ListUpdates the item at the given index.- Specified by:
updatein interfaceList<Node>- Specified by:
updatein interfaceSequence<Node>- Parameters:
index- The index of the item to update.node- The item that will replace any existing value at the given index.- Returns:
- The item that was previously stored at the given index.
- Throws:
java.lang.UnsupportedOperationException- This method is not supported.- See Also:
ListListener.itemUpdated(List, int, Object)
-
remove
public int remove(Node node)
Removes a node from this element.- Specified by:
removein interfaceSequence<Node>- Parameters:
node- The node to remove.- Returns:
- The index of the node before it was removed, or
-1if the node was not found. - See Also:
Sequence.remove(int, int)
-
remove
public Sequence<Node> remove(int index, int count)
Removes a range of nodes from this element.
-
clear
public void clear()
Removes all nodes from this element.- Specified by:
clearin interfaceCollection<Node>- Specified by:
clearin interfaceList<Node>- See Also:
ListListener.itemsRemoved(List, int, Sequence)
-
get
public Node get(int index)
Returns the node at the given index.
-
indexOf
public int indexOf(Node node)
Determines the index of the given node within this element.
-
getLength
public int getLength()
Returns the number of nodes contained by this element.
-
getComparator
public java.util.Comparator<Node> getComparator()
Description copied from interface:CollectionReturns the collection's sort order.- Specified by:
getComparatorin interfaceCollection<Node>- Returns:
null; elements cannot be sorted.- See Also:
Collection.setComparator(Comparator)
-
setComparator
@UnsupportedOperation public void setComparator(java.util.Comparator<Node> comparator)
Description copied from interface:CollectionSets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.Calling this method more than once with the same comparator will re-sort the collection.
- Specified by:
setComparatorin interfaceCollection<Node>- Specified by:
setComparatorin interfaceList<Node>- Parameters:
comparator- The comparator used to order elements in the collection, or null if the collection is unsorted.- Throws:
java.lang.UnsupportedOperationException- Elements cannot be sorted.- See Also:
ListListener.comparatorChanged(List, Comparator)
-
iterator
public java.util.Iterator<Node> iterator()
Returns an iterator over this elements child nodes.- Specified by:
iteratorin interfacejava.lang.Iterable<Node>
-
isEmpty
public boolean isEmpty()
Determines if this element defines any attributes.- Specified by:
isEmptyin interfaceCollection<Node>- Returns:
trueif this element does not define any attributes;falseotherwise.
-
getElements
public List<Element> getElements(java.lang.String name)
Returns the sub-elements of of this element whose tag names match the given name.- Parameters:
name- The tag name to match.- Returns:
- A list containing the matching elements. The list will be empty if no elements matched the given tag name.
-
getText
public java.lang.String getText()
Returns the text content of this element. An element is defined to contain text when it contains a single child that is an instance ofTextNode.- Returns:
- The text content of the element, or
nullif this element does not contain text.
-
getListListeners
public ListenerList<ListListener<Node>> getListListeners()
Description copied from interface:ListReturns the list listener list.- Specified by:
getListListenersin interfaceList<Node>- Returns:
- The element's listener list.
-
getElementListeners
public ListenerList<ElementListener> getElementListeners()
- Returns:
- The element listener list.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-