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 class
Element.Attribute
Class representing an XML attribute.class
Element.AttributeSequence
Sequence representing the attributes declared by this element.class
Element.ElementDictionary
Dictionary representing the attributes declared by this element.class
Element.NamespaceDictionary
Dictionary 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 int
add(Node node)
Adds a node to this element.void
clear()
Removes all nodes from this element.Node
get(int index)
Returns the node at the given index.Element.AttributeSequence
getAttributes()
java.util.Comparator<Node>
getComparator()
Returns the collection's sort order.java.lang.String
getDefaultNamespaceURI()
Returns the element's default namespace URI.Element.ElementDictionary
getElementDictionary()
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.int
getLength()
Returns the number of nodes contained by this element.ListenerList<ListListener<Node>>
getListListeners()
Returns the list listener list.java.lang.String
getLocalName()
java.lang.String
getName()
Returns the fully-qualified name of the element.java.lang.String
getNamespacePrefix()
Returns the element's namespace prefix.Element.NamespaceDictionary
getNamespaces()
java.lang.String
getNamespaceURI(java.lang.String prefix)
Determines the namespace URI corresponding to the given prefix by traversing the element's ancestry.java.lang.String
getText()
Returns the text content of this element.int
indexOf(Node node)
Determines the index of the given node within this element.void
insert(Node node, int index)
Inserts a node at a specific location within this element.boolean
isEmpty()
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.int
remove(Node node)
Removes a node from this element.void
setComparator(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.void
setDefaultNamespaceURI(java.lang.String defaultNamespaceURI)
Sets the element's default namespace URI.java.lang.String
toString()
Node
update(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
null
if 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
null
if 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, ornull
if 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, ornull
to determine the default namespace for this element.- Returns:
- The namespace URI corresponding to the given prefix, or
null
if 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:
add
in interfaceList<Node>
- Specified by:
add
in 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:List
Updates the item at the given index.- Specified by:
update
in interfaceList<Node>
- Specified by:
update
in 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:
remove
in interfaceSequence<Node>
- Parameters:
node
- The node to remove.- Returns:
- The index of the node before it was removed, or
-1
if 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:
clear
in interfaceCollection<Node>
- Specified by:
clear
in 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:Collection
Returns the collection's sort order.- Specified by:
getComparator
in 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:Collection
Sets 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:
setComparator
in interfaceCollection<Node>
- Specified by:
setComparator
in 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:
iterator
in interfacejava.lang.Iterable<Node>
-
isEmpty
public boolean isEmpty()
Determines if this element defines any attributes.- Specified by:
isEmpty
in interfaceCollection<Node>
- Returns:
true
if this element does not define any attributes;false
otherwise.
-
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
null
if this element does not contain text.
-
getListListeners
public ListenerList<ListListener<Node>> getListListeners()
Description copied from interface:List
Returns the list listener list.- Specified by:
getListListeners
in 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:
toString
in classjava.lang.Object
-
-