Top Description Methods
org.jdom2

public Interface Parent

extends Cloneable, NamespaceAware, Serializable
Known Direct Implementers
org.jdom2.Document, org.jdom2.Element
Imports
java.io.Serializable, java.util.*, org.jdom2.filter.Filter, .Filters, org.jdom2.util.IteratorIterable

Interface for JDOM objects which are allowed to contain Content content - Element and Document.
Authors
Bradley S. Huffman, Jason Hunter, Rolf Lear
See Also
org.jdom2.Content, org.jdom2.Document, org.jdom2.Element

Method Summary

Modifier and TypeMethod and Description
public Parent

Returns:

the Parent instance on which the method was called
addContent
(Content
child to append to end of content list
child
)

Appends the child to the end of the content list.

public Parent

Returns:

the document on which the method was called
addContent
(Collection<? extends Content>
collection to append
c
)

Appends all children in the given collection to the end of the content list.

public Parent

Returns:

the parent on which the method was called
addContent
(int
location for adding the collection
index
,
Content
child to insert
child
)

Inserts the child into the content list at the given index.

public Parent

Returns:

the parent on which the method was called
addContent
(int
location for adding the collection
index
,
Collection<? extends Content>
collection to insert
c
)

Inserts the content in a collection into the content list at the given index.

public void
canContainContent(Content
The content to be checked
content
,
int
The location where the content would be put.
index
,
boolean
true if the intention is to replace the content already at the index.
replace
)

Test whether this Parent instance can contain the specified content at the specified position.

public Object

Returns:

a deep copy of this parent and its children.
clone
()

Obtain a deep, unattached copy of this parent and its children.

public List<Content>

Returns:

list of cloned child content
cloneContent
()

Returns a list containing detached clones of this parent's content list.

public Content

Returns:

child at the given index
getContent
(int
location of desired child
index
)

Returns the child at the given index.

public List<Content>

Returns:

a list of the content of the parent
getContent
()

Returns the full content of this parent as a java.util.List which contains objects of type Content.

public <
The Generic type of the returned content (the Filter's type)
E extends Content
>
List<E>

Returns:

a list of the content of the parent matching the filter
getContent
(Filter<E>
filter to apply. Note that the Filters class has a number of predefined, useful filters.
filter
)

Returns as a java.util.List the content of this parent that matches the supplied filter.

public int

Returns:

number of children
getContentSize
()

Returns the number of children in this parent's content list.

public IteratorIterable<Content>

Returns:

an iterator to walk descendants
getDescendants
()

Returns an java.util.Iterator that walks over all descendants in document order.

public <
The generic type of the returned descendant data
E extends Content
>
IteratorIterable<E>

Returns:

an iterator to walk descendants that match a filter
getDescendants
(Filter<E>
filter to select which descendants to see Note that the Filters class has a number of predefined, useful filters.
filter
)

Returns an java.util.Iterator that walks over all descendants in document order applying the Filter to return only content that match the filter rule.

public Document

Returns:

this child's owning document or null if none
getDocument
()

Return this parent's owning document or null if the branch containing this parent is currently not attached to a document.

public Parent

Returns:

this parent's parent or null if none
getParent
()

Return this parent's parent, or null if this parent is currently not attached to another parent.

public int

Returns:

index of child, or -1 if not found
indexOf
(Content
child to search for
child
)

Returns the index of the supplied child in the content list, or -1 if not a child of this parent.

public List<Content>

Returns:

list of the old content detached from this parent
removeContent
()

Removes all content from this parent and returns the detached children.

public <
The Generic type of the content to remove.
E extends Content
>
List<E>

Returns:

list of the detached children matching the filter
removeContent
(Filter<E>
filter to apply Note that the Filters class has a number of predefined, useful filters.
filter
)

Removes from this parent all child content matching the given filter and returns a list of the detached children.

public boolean

Returns:

whether the removal occurred
removeContent
(Content
child to remove
child
)

Removes a single child node from the content list.

public Content

Returns:

detached child at given index or null if no
removeContent
(int
index of child to remove
index
)

Removes and returns the child at the given index, or returns null if there's no such child.

Inherited from org.jdom2.NamespaceAware:
getNamespacesInheritedgetNamespacesInScopegetNamespacesIntroduced

Method Detail

addContentback to summary
public Parent addContent(Content child)

Appends the child to the end of the content list.

Parameters
child:Content

child to append to end of content list

Returns:Parent

the Parent instance on which the method was called

Exceptions
IllegalAddException:
if the given child already has a parent.
addContentback to summary
public Parent addContent(Collection<? extends Content> c)

Appends all children in the given collection to the end of the content list. In event of an exception during add the original content will be unchanged and the objects in the supplied collection will be unaltered.

Parameters
c:Collection<? extends Content>

collection to append

Returns:Parent

the document on which the method was called

Exceptions
IllegalAddException:
if any item in the collection already has a parent or is of an illegal type.
addContentback to summary
public Parent addContent(int index, Content child)

Inserts the child into the content list at the given index.

Parameters
index:int

location for adding the collection

child:Content

child to insert

Returns:Parent

the parent on which the method was called

Exceptions
IndexOutOfBoundsException:
if index is negative or beyond the current number of children
IllegalAddException:
if the given child already has a parent.
addContentback to summary
public Parent addContent(int index, Collection<? extends Content> c)

Inserts the content in a collection into the content list at the given index. In event of an exception the original content will be unchanged and the objects in the supplied collection will be unaltered.

Parameters
index:int

location for adding the collection

c:Collection<? extends Content>

collection to insert

Returns:Parent

the parent on which the method was called

Exceptions
IndexOutOfBoundsException:
if index is negative or beyond the current number of children
IllegalAddException:
if any item in the collection already has a parent or is of an illegal type.
canContainContentback to summary
public void canContainContent(Content content, int index, boolean replace) throws IllegalAddException

Test whether this Parent instance can contain the specified content at the specified position.

Parameters
content:Content

The content to be checked

index:int

The location where the content would be put.

replace:boolean

true if the intention is to replace the content already at the index.

Exceptions
IllegalAddException:
if there is a problem with the content
cloneback to summary
public Object clone()

Obtain a deep, unattached copy of this parent and its children.

Returns:Object

a deep copy of this parent and its children.

cloneContentback to summary
public List<Content> cloneContent()

Returns a list containing detached clones of this parent's content list.

Returns:List<Content>

list of cloned child content

getContentback to summary
public Content getContent(int index)

Returns the child at the given index.

Parameters
index:int

location of desired child

Returns:Content

child at the given index

Exceptions
IndexOutOfBoundsException:
if index is negative or beyond the current number of children
IllegalStateException:
if parent is a Document and the root element is not set
getContentback to summary
public List<Content> getContent()

Returns the full content of this parent as a java.util.List which contains objects of type Content. 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 java.util.List#size may require walking the entire list and indexed lookups may require starting at the beginning each time.

Returns:List<Content>

a list of the content of the parent

Exceptions
IllegalStateException:
if parent is a Document and the root element is not set
getContentback to summary
public <E extends Content> List<E> getContent(Filter<E> filter)

Returns as a java.util.List 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 java.util.List#size may require walking the entire list and indexed lookups may require starting at the beginning each time.

Parameters
<E>
The Generic type of the returned content (the Filter's type)
filter:Filter<E>

filter to apply. Note that the Filters class has a number of predefined, useful filters.

Returns:List<E>

a list of the content of the parent matching the filter

Exceptions
IllegalStateException:
if parent is a Document and the root element is not set
getContentSizeback to summary
public int getContentSize()

Returns the number of children in this parent's content list. Children may be any Content type.

Returns:int

number of children

getDescendantsback to summary
public IteratorIterable<Content> getDescendants()

Returns an java.util.Iterator that walks over all descendants in document order.

Note that this method returns an IteratorIterable instance, which means that you can use it either as an Iterator, or an Iterable, allowing both:

  for (Iterator it = parent.getDescendants();
          it.hasNext();) {
      Content c = it.next();
      ....
  }
and
  for (Content c : parent.getDescendants()) {
      ....
  }
The Iterator version is most useful if you need to do list modification on the iterator (using remove()), and for compatibility with JDOM 1.x
Returns:IteratorIterable<Content>

an iterator to walk descendants

getDescendantsback to summary
public <E extends Content> IteratorIterable<E> getDescendants(Filter<E> filter)

Returns an java.util.Iterator that walks over all descendants in document order applying the Filter to return only content 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.

Note that this method returns an IteratorIterable instance, which means that you can use it either as an Iterator, or an Iterable, allowing both:

  for (Iterator it = parent.getDescendants(Filters.element());
          it.hasNext();) {
      Element e = it.next();
      ....
  }
and
  for (Element e : parent.getDescendants(Filters.element())) {
      ....
  }
The Iterator version is most useful if you need to do list modification on the iterator (using remove()), and for compatibility with JDOM 1.x
Parameters
<E>
The generic type of the returned descendant data
filter:Filter<E>

filter to select which descendants to see Note that the Filters class has a number of predefined, useful filters.

Returns:IteratorIterable<E>

an iterator to walk descendants that match a filter

getDocumentback to summary
public Document getDocument()

Return this parent's owning document or null if the branch containing this parent is currently not attached to a document.

Returns:Document

this child's owning document or null if none

getParentback to summary
public 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:Parent

this parent's parent or null if none

indexOfback to summary
public int indexOf(Content child)

Returns the index of the supplied child in the content list, or -1 if not a child of this parent.

Parameters
child:Content

child to search for

Returns:int

index of child, or -1 if not found

removeContentback to summary
public List<Content> removeContent()

Removes all content from this parent and returns the detached children.

Returns:List<Content>

list of the old content detached from this parent

removeContentback to summary
public <E extends Content> List<E> removeContent(Filter<E> filter)

Removes from this parent all child content matching the given filter and returns a list of the detached children.

Parameters
<E>
The Generic type of the content to remove.
filter:Filter<E>

filter to apply Note that the Filters class has a number of predefined, useful filters.

Returns:List<E>

list of the detached children matching the filter

removeContentback to summary
public boolean removeContent(Content child)

Removes a single child node from the content list.

Parameters
child:Content

child to remove

Returns:boolean

whether the removal occurred

removeContentback to summary
public Content removeContent(int index)

Removes and returns the child at the given index, or returns null if there's no such child.

Parameters
index:int

index of child to remove

Returns:Content

detached child at given index or null if no

Exceptions
IndexOutOfBoundsException:
if index is negative or beyond the current number of children