JDOM 1.0 | |
Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.jdom.Document
DocType
and other document-level information.
Field Summary | |
protected String |
|
Constructor Summary | |
| |
Method Summary | |
Document |
|
Document |
|
Document |
|
Document |
|
Object |
|
List |
|
Element |
|
boolean |
|
String |
|
List |
|
Content |
|
List |
|
int |
|
Iterator |
|
Iterator |
|
DocType |
|
Document | |
Parent |
|
Object |
|
Element |
|
boolean |
|
int |
|
int | |
List |
|
Content |
|
boolean |
|
List |
|
void |
|
Document |
|
Document |
|
Document |
|
Document |
|
Document |
|
void |
|
Document |
|
String |
|
protected String baseURI
See http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/core.html#baseURIs-Considerations
public Document()
Creates a new empty document. A document must have a root element, so this document will not be well-formed and accessor methods will throw an IllegalStateException if this document is accessed before a root element is added. This method is most useful for build tools.
public Document(List content)
This will create a newDocument
, with the supplied list of content, and adeclaration only if the content contains a DocType instance. A null list is treated the same as the no-arg constructor.
DocType
- Parameters:
content
-List
of starter content
public Document(Element rootElement)
This will create a newDocument
, with the suppliedas the root element, and no
Element
declaration.
DocType
- Parameters:
rootElement
-Element
for document root
public Document(Element rootElement, DocType docType)
This will create a newDocument
, with the suppliedas the root element and the supplied
Element
declaration.
DocType
- Parameters:
rootElement
-Element
for document root.docType
-DocType
declaration.
public Document(Element rootElement, DocType docType, String baseURI)
This will create a newDocument
, with the suppliedas the root element, the supplied
Element
declaration, and the specified base URI.
DocType
- Parameters:
rootElement
-Element
for document root.docType
-DocType
declaration.baseURI
- the URI from which this doucment was loaded.
public Document addContent(Collection 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 to append
- Returns:
- the document on which the method was called
public Document addContent(int index, Collection 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
- location for adding the collectionc
- collection to insert
- Returns:
- the parent on which the method was called
public Document addContent(int index, Content child)
Inserts the child into the content list at the given index.
- Parameters:
index
- location for adding the collectionchild
- child to insert
- Returns:
- the parent on which the method was called
public Document addContent(Content child)
Appends the child to the end of the content list.
- Parameters:
child
- child to append to end of content list
- Returns:
- the document on which the method was called
public Object clone()
This will return a deep clone of thisDocument
.
- Returns:
Object
clone of thisDocument
public List cloneContent()
Returns a list containing detached clones of this parent's content list.
- Specified by:
- cloneContent in interface Parent
- Returns:
- list of cloned child content
public Element detachRootElement()
Detach the rootfrom this document.
Element
- Returns:
- removed root
Element
public final boolean equals(Object ob)
This tests for equality of thisDocument
to the suppliedObject
.
- Parameters:
ob
-Object
to compare to
- Returns:
boolean
whether theDocument
is equal to the suppliedObject
public final String getBaseURI()
Returns the URI from which this document was loaded, or null if this is not known.
- Returns:
- the base URI of this document
public List getContent()
This will return all content for theDocument
. The returned list is "live" in document order and changes to it affect the document's actual content. Sequential traversal through the List is best done with a Iterator since the underlying implement of List.size() may require walking the entire list.
- Specified by:
- getContent in interface Parent
- Returns:
List
- all Document content
public Content getContent(int index)
Returns the child at the given index.
- Specified by:
- getContent in interface Parent
- Parameters:
index
- location of desired child
- Returns:
- child at the given index
public List getContent(Filter filter)
Return a filtered view of thisDocument
's content. Sequential traversal through the List is best done with a Iterator since the underlying implement of List.size() may require walking the entire list.
- Specified by:
- getContent in interface Parent
- Parameters:
filter
-Filter
to apply
- Returns:
List
- filtered Document content
public int getContentSize()
Returns the number of children in this parent's content list. Children may be anyContent
type.
- Specified by:
- getContentSize in interface Parent
- Returns:
- number of children
public Iterator getDescendants()
Returns an iterator that walks over all descendants in document order.
- Specified by:
- getDescendants in interface Parent
- Returns:
- an iterator to walk descendants
public Iterator getDescendants(Filter filter)
Returns an iterator 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.
- Specified by:
- getDescendants in interface Parent
- Parameters:
filter
- filter to select which descendants to see
- Returns:
- an iterator to walk descendants within a filter
public Document getDocument()
- Specified by:
- getDocument in interface Parent
- See Also:
Parent.getDocument()
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:
- this parent's parent or null if none
public Object getProperty(String id)
Returns the object associated with this document under the given "id" string, or null if there is no binding or if the binding explicitly stored a null value.
- Parameters:
id
- the id of the stored object to return
- Returns:
- the object associated with the given id
public Element getRootElement()
This will return the rootElement
for thisDocument
- Returns:
Element
- the document's root element
public boolean hasRootElement()
This will returntrue
if this document has a root element,false
otherwise.
- Returns:
true
if this document has a root element,false
otherwise.
public final int hashCode()
This returns the hash code for thisDocument
.
- Returns:
int
hash code
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
- child to search for
- Returns:
- index of child, or -1 if not found
public List removeContent()
Removes all child content from this parent.
- Specified by:
- removeContent in interface Parent
- Returns:
- list of the old children detached from this parent
public Content removeContent(int index)
Removes and returns the child at the given index, or returns null if there's no such child.
- Specified by:
- removeContent in interface Parent
- Parameters:
index
- index of child to remove
- Returns:
- detached child at given index or null if no
public boolean removeContent(Content child)
Removes a single child node from the content list.
- Specified by:
- removeContent in interface Parent
- Parameters:
child
- child to remove
- Returns:
- whether the removal occurred
public List removeContent(Filter filter)
Remove all child content from this parent matching the supplied filter.
- Specified by:
- removeContent in interface Parent
- Parameters:
filter
- filter to select which content to remove
- Returns:
- list of the old children detached from this parent
public final void setBaseURI(String uri)
Sets the effective URI from which this document was loaded, and against which relative URLs in this document will be resolved.
- Parameters:
uri
- the base URI of this document
public Document setContent(Collection newContent)
This sets the content of theDocument
. The supplied List should contain only objects of typeElement
,Comment
, andProcessingInstruction
. When all objects in the supplied List are legal and before the new content is added, all objects in the old content will have their parentage set to null (no parent) and the old content list will be cleared. This has the effect that any active list (previously obtained with a call togetContent
) will also change to reflect the new content. In addition, all objects in the supplied List will have their parentage set to this document, but the List itself will not be "live" and further removals and additions will have no effect on this document content. If the user wants to continue working with a "live" list, then a call to setContent should be followed by a call togetContent
to obtain a "live" version of the content. Passing a null or empty List clears the existing content. In event of an exception the original content will be unchanged and the objects in the supplied content will be unaltered.
- Parameters:
newContent
-List
of content to set
- Returns:
- this document modified
public Document setContent(int index, Collection collection)
Replace the child at the given index whith the supplied collection. In event of an exception the original content will be unchanged and the content in the supplied collection will be unaltered.
- Parameters:
index
- - index of child to replace.collection
- - collection of content to add.
- Returns:
- object on which the method was invoked
public Document setContent(Content child)
Set this document's content to be the supplied child. If the supplied child is legal content for a Document and before it is added, all content in the current content list will be cleared and all current children will have their parentage set to null. This has the effect that any active list (previously obtained with a call to one of thegetContent
methods will also change to reflect the new content. In addition, all content in the supplied collection will have their parentage set to this Document. If the user wants to continue working with a "live" list of this Document's child, then a call to setContent should be followed by a call to one of thegetContent
methods to obtain a "live" version of the children. Passing a null child clears the existing content. In event of an exception the original content will be unchanged and the supplied child will be unaltered.
- Parameters:
child
- new content to replace existing content
- Returns:
- the parent on which the method was called
public Document setDocType(DocType docType)
This will set thedeclaration for this
DocType
Document
. Note that a DocType can only be attached to one Document. Attempting to set the DocType to a DocType object that already belongs to a Document will result in an IllegalAddException being thrown.
- Parameters:
docType
-DocType
declaration.
- Returns:
- object on which the method was invoked
public void setProperty(String id, Object value)
Assigns an arbitrary object to be associated with this document under the given "id" string. Null values are permitted. Strings beginning with "http://www.jdom.org/ are reserved for JDOM use.
- Parameters:
id
- the id of the stored objectvalue
- the object to store
public Document setRootElement(Element rootElement)
This sets the rootfor the
Element
Document
. If the document already has a root element, it is replaced.
- Parameters:
rootElement
-Element
to be new root.
- Returns:
Document
- modified Document.
public String toString()
This returns aString
representation of theDocument
, suitable for debugging. If the XML representation of theDocument
is desired,XMLOutputter.outputString(Document)
should be used.
- Returns:
String
- information about theDocument