Package org.jdom
Interface Parent
- All Superinterfaces:
Cloneable
,Serializable
Superclass for JDOM objects which are allowed to contain
Content
content.-
Method Summary
Modifier and TypeMethodDescriptionclone()
Obtain a deep, unattached copy of this parent and it's children.Returns a list containing detached clones of this parent's content list.getContent
(int index) Returns the child at the given index.getContent
(Filter filter) Returns as aList
the content of this parent that matches the supplied filter.int
Returns the number of children in this parent's content list.Returns anIterator
that walks over all descendants in document order.getDescendants
(Filter filter) Returns anIterator
that walks over all descendants in document order applying the Filter to return only elements that match the filter rule.Return this parent's owning document or null if the branch containing this parent is currently not attached to a document.Return this parent's parent, or null if this parent is currently not attached to another parent.int
Returns the index of the supplied child in the content list, or -1 if not a child of this parent.Removes all content from this parent and returns the detached children.removeContent
(int index) Removes and returns the child at the given index, or returns null if there's no such child.boolean
removeContent
(Content child) Removes a single child node from the content list.removeContent
(Filter filter) Removes from this parent all child content matching the given filter and returns a list of the detached children.
-
Method Details
-
getContentSize
int getContentSize()Returns the number of children in this parent's content list. Children may be anyContent
type.- Returns:
- number of children
-
indexOf
Returns the index of the supplied child in the content list, or -1 if not a child of this parent.- Parameters:
child
- child to search for- Returns:
- index of child, or -1 if not found
-
cloneContent
List cloneContent()Returns a list containing detached clones of this parent's content list.- Returns:
- list of cloned child content
-
getContent
Returns the child at the given index.- Parameters:
index
- location of desired child- Returns:
- child at the given index
- Throws:
IndexOutOfBoundsException
- if index is negative or beyond the current number of childrenIllegalStateException
- if parent is a Document and the root element is not set
-
getContent
List getContent()Returns the full content of this parent as aList
which contains objects of typeContent
. The returned list is "live" and in document order. Any modifications to it affect the element's actual contents. Modifications are checked for conformance to XML 1.0 rules.Sequential traversal through the List is best done with an Iterator since the underlying implement of
List.size()
may require walking the entire list and indexed lookups may require starting at the beginning each time.- Returns:
- a list of the content of the parent
- Throws:
IllegalStateException
- if parent is a Document and the root element is not set
-
getContent
Returns as aList
the content of this parent that matches the supplied filter. The returned list is "live" and in document order. Any modifications to it affect the element's actual contents. Modifications are checked for conformance to XML 1.0 rules.Sequential traversal through the List is best done with an Iterator since the underlying implement of
List.size()
may require walking the entire list and indexed lookups may require starting at the beginning each time.- Parameters:
filter
- filter to apply- Returns:
- a list of the content of the parent matching the filter
- Throws:
IllegalStateException
- if parent is a Document and the root element is not set
-
removeContent
List removeContent()Removes all content from this parent and returns the detached children.- Returns:
- list of the old content detached from this parent
-
removeContent
Removes from this parent all child content matching the given filter and returns a list of the detached children.- Parameters:
filter
- filter to apply- Returns:
- list of the detached children matching the filter
-
removeContent
Removes a single child node from the content list.- Parameters:
child
- child to remove- Returns:
- whether the removal occurred
-
removeContent
Removes and returns the child at the given index, or returns null if there's no such child.- Parameters:
index
- index of child to remove- Returns:
- detached child at given index or null if no
- Throws:
IndexOutOfBoundsException
- if index is negative or beyond the current number of children
-
clone
Object clone()Obtain a deep, unattached copy of this parent and it's children.- Returns:
- a deep copy of this parent and it's children.
-
getDescendants
Iterator getDescendants()Returns anIterator
that walks over all descendants in document order.- Returns:
- an iterator to walk descendants
-
getDescendants
Returns anIterator
that walks over all descendants in document order applying the Filter to return only elements that match the filter rule. With filters you can match only Elements, only Comments, Elements or Comments, only Elements with a given name and/or prefix, and so on.- Parameters:
filter
- filter to select which descendants to see- Returns:
- an iterator to walk descendants that match a filter
-
getParent
Parent getParent()Return this parent's parent, or null if this parent is currently not attached to another parent. This is the same method as in Content but also added to Parent to allow more easy up-the-tree walking.- Returns:
- this parent's parent or null if none
-
getDocument
Document getDocument()Return this parent's owning document or null if the branch containing this parent is currently not attached to a document.- Returns:
- this child's owning document or null if none
-