|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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()
public Document(Element rootElement, DocType docType)
Document
,
with the supplied Element
as the root element and the supplied
DocType
declaration.
rootElement
- Element
for document root.docType
- DocType
declaration.
IllegalAddException
- if the given docType object
is already attached to a document or the given
rootElement already has a parentpublic Document(Element rootElement)
Document
,
with the supplied Element
as the root element, and no DocType
declaration.
rootElement
- Element
for document root
IllegalAddException
- if the given rootElement already has
a parent.public Document(java.util.List newContent, DocType docType)
Document
,
with the supplied list of content, and the supplied
DocType
declaration.
newContent
- 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)
Document
,
with the supplied list of content, and no
DocType
declaration.
content
- List
of starter content
IllegalAddException
- if the List contains more than
one Element or objects of illegal types.Method Detail |
public boolean hasRootElement()
true
if this document has a
root element, false
otherwise.
true
if this document has a root element,
false
otherwise.public Element getRootElement()
Element
for this Document
Element
- the document's root element
java.lang.IllegalStateException
- if the root element hasn't been setpublic Document setRootElement(Element rootElement)
Element
for the
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()
Element
from this document.
Element
public DocType getDocType()
DocType
declaration for this Document
, or
null
if none exists.
DocType
- the DOCTYPE declaration.public Document setDocType(DocType docType)
DocType
declaration for this 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)
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)
Document
.
comment
- Comment
to add.
Document
- this object modified.
IllegalAddException
- if the given comment already has a
parent element.public java.util.List getContent()
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 content
java.lang.IllegalStateException
- if the root element hasn't been setpublic java.util.List getContent(Filter filter)
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 apply
List
- filtered Document content
java.lang.IllegalStateException
- if the root element hasn't been setpublic Document setContent(java.util.List newContent)
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 set
IllegalAddException
- if the List contains objects of
illegal types.public boolean removeContent(ProcessingInstruction pi)
ProcessingInstruction
.
If the specified ProcessingInstruction
is not a child of
this Document
, this method does nothing.
pi
- ProcessingInstruction
to delete
public boolean removeContent(Comment comment)
Comment
.
If the specified Comment
is not a child of
this Document
, this method does nothing.
comment
- Comment
to delete
public java.lang.String toString()
String
representation of the
Document
, suitable for debugging. If the XML
representation of the Document
is desired,
XMLOutputter.outputString(Document)
should be used.
String
- information about the
Document
public final boolean equals(java.lang.Object ob)
Document
to the supplied
Object
.
ob
- Object
to compare to.
boolean
- whether the Document
is
equal to the supplied Object
.public final int hashCode()
Document
.
int
- hash code.public java.lang.Object clone()
Document
.
Object
- clone of this Document
.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |