|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jdom.Document
Document
defines behavior for an XML Document, modeled
in Java. Methods allow access to the root element as well
as processing instructions and other document-level information.
Field Summary | |
protected org.jdom.ContentList |
content
This Document 's
s,
s and
the root . |
protected DocType |
docType
The declaration. |
Constructor Summary | |
Document()
Creates a new empty document. |
|
Document(Element rootElement)
This will create a new Document ,
with the supplied
as the root element, and no
declaration. |
|
Document(Element rootElement,
DocType docType)
This will create a new Document ,
with the supplied
as the root element and the supplied
declaration. |
|
Document(java.util.List content)
This will create a new Document ,
with the supplied list of content, and no
declaration. |
|
Document(java.util.List newContent,
DocType docType)
This will create a new Document ,
with the supplied list of content, and the supplied
declaration. |
Method Summary | |
Document |
addContent(Comment comment)
This will add a comment to the Document . |
Document |
addContent(ProcessingInstruction pi)
Adds the specified PI to the document. |
java.lang.Object |
clone()
This will return a deep clone of this Document . |
Element |
detachRootElement()
Detach the root from this document. |
boolean |
equals(java.lang.Object ob)
This tests for equality of this Document to the supplied
Object . |
java.util.List |
getContent()
This will return all content for the Document . |
java.util.List |
getContent(Filter filter)
Return a filtered view of this Document 's content. |
DocType |
getDocType()
This will return the
declaration for this Document , or
null if none exists. |
Element |
getRootElement()
This will return the root Element
for this Document
|
int |
hashCode()
This returns the hash code for this Document . |
boolean |
hasRootElement()
This will return true if this document has a
root element, false otherwise. |
boolean |
removeContent(Comment comment)
This removes the specified Comment . |
boolean |
removeContent(ProcessingInstruction pi)
This removes the specified ProcessingInstruction . |
Document |
setContent(java.util.List newContent)
This sets the content of the Document . |
Document |
setDocType(DocType docType)
This will set the
declaration for this Document . |
Document |
setRootElement(Element rootElement)
This sets the root for the
Document . |
java.lang.String |
toString()
This returns a String representation of the
Document , suitable for debugging. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
protected org.jdom.ContentList content
Document
's
Comment
s,
ProcessingInstruction
s and
the root Element
.protected DocType docType
DocType
declaration.Constructor Detail |
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(Element rootElement, DocType docType)
This will create a new Document
,
with the supplied
as the root element and the supplied
Element
declaration.
DocType
rootElement
- Element
for document root.docType
- DocType
declaration.public Document(Element rootElement)
This will create a new Document
,
with the supplied
as the root element, and no Element
declaration.
DocType
rootElement
- Element
for document rootpublic Document(java.util.List newContent, DocType docType)
This will create a new Document
,
with the supplied list of content, and the supplied
declaration.
DocType
content
- List
of starter contentdocType
- DocType
declaration.IllegalAddException
- if (1) the List contains more than
one Element or objects of illegal types, or (2) if the
given docType object is already attached to a document.public Document(java.util.List content)
This will create a new Document
,
with the supplied list of content, and no
declaration.
DocType
content
- List
of starter contentIllegalAddException
- if the List contains more than
one Element or objects of illegal types.Method Detail |
public boolean hasRootElement()
This will return true
if this document has a
root element, false
otherwise.
true
if this document has a root element,
false
otherwise.public Element getRootElement()
This will return the root Element
for this Document
Element
- the document's root elementIllegalStateException
- if the root element hasn't been setpublic Document setRootElement(Element rootElement)
This sets the root
for the
Element
Document
. If the document already has a root
element, it is replaced.
rootElement
- Element
to be new root.Document
- modified Document.IllegalAddException
- if the given rootElement already has
a parent.public Element detachRootElement()
Detach the root
from this document.
Element
Element
public DocType getDocType()
This will return the
declaration for this DocType
Document
, or
null
if none exists.
DocType
- the DOCTYPE declaration.public Document setDocType(DocType docType)
This will set the
declaration 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.
docType
- DocType
declaration.IllegalAddException
- if the given docType is
already attached to a Document.public Document addContent(ProcessingInstruction pi)
Adds the specified PI to the document.
pi
- the ProcessingInstruction to add.Document
this document modified.IllegalAddException
- if the given processing instruction
already has a parent element.public Document addContent(Comment comment)
This will add a comment to the Document
.
comment
- Comment
to add.Document
- this object modified.IllegalAddException
- if the given comment already has a
parent element.public java.util.List getContent()
This will return all content for the Document
.
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.
List
- all Document contentIllegalStateException
- if the root element hasn't been setpublic java.util.List getContent(Filter filter)
Return a filtered view of this Document
'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.
filter
- Filter
to applyList
- filtered Document contentIllegalStateException
- if the root element hasn't been setpublic Document setContent(java.util.List newContent)
This sets the content of the Document
. The supplied
List should contain only objects of type Element
,
Comment
, and ProcessingInstruction
.
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 to getContent()
) 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 to getContent()
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.
newContent
- List
of content to setIllegalAddException
- if the List contains objects of
illegal types.public boolean removeContent(ProcessingInstruction pi)
This removes the specified ProcessingInstruction
.
If the specified ProcessingInstruction
is not a child of
this Document
, this method does nothing.
child
- ProcessingInstruction
to deletepublic boolean removeContent(Comment comment)
This removes the specified Comment
.
If the specified Comment
is not a child of
this Document
, this method does nothing.
comment
- Comment
to deletepublic java.lang.String toString()
This returns a String
representation of the
Document
, suitable for debugging. If the XML
representation of the Document
is desired,
XMLOutputter.outputString(Document)
should be used.
toString
in class java.lang.Object
String
- information about the
Document
public final boolean equals(java.lang.Object ob)
This tests for equality of this Document
to the supplied
Object
.
equals
in class java.lang.Object
ob
- Object
to compare to.boolean
- whether the Document
is
equal to the supplied Object
.public final int hashCode()
This returns the hash code for this Document
.
hashCode
in class java.lang.Object
int
- hash code.public java.lang.Object clone()
This will return a deep clone of this Document
.
clone
in class java.lang.Object
Object
- clone of this Document
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |