|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.cdmckay.coffeedom.Document
public class Document
An XML document. Methods allow access to the root element as well as the DocType
and other document-level
information.
Field Summary | |
---|---|
protected String |
baseURI
See http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/core.html#baseURIs-Considerations |
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(Element rootElement,
DocType docType,
String baseURI)
This will create a new Document , with the supplied as the root element,
the supplied declaration, and the specified base URI. |
|
Document(List<Content> contents)
This will create a new Document , with the supplied list of content, and a declaration only if the content contains a DocType instance. |
Method Summary | |
---|---|
Document |
addContent(Collection<? extends Content> newContents)
Appends all children in the given collection to the end of the content list. |
Document |
addContent(Content child)
Appends the child to the end of the content list. |
Document |
addContent(int index,
Collection<? extends Content> contents)
Inserts the content in a collection into the content list at the given index. |
Document |
addContent(int index,
Content child)
Inserts the child into the content list at the given index. |
Document |
clone()
This will return a deep clone of this Document . |
List<Content> |
cloneContents()
Returns a list containing detached clones of this parent's content list. |
Element |
detachRootElement()
Detach the root from this document. |
boolean |
equals(Object ob)
This tests for equality of this Document to the supplied Object . |
String |
getBaseURI()
Returns the URI from which this document was loaded, or null if this is not known. |
Content |
getContent(int index)
Returns the child at the given index. |
List<Content> |
getContents()
This will return all content for the Document . |
List<Content> |
getContents(Filter filter)
Return a filtered view of this Document 's content. |
int |
getContentsSize()
Returns the number of children in this parent's content list. |
Iterable<Content> |
getDescendants()
Returns an Iterable that walks over all descendants in document order. |
Iterable<Content> |
getDescendants(Filter filter)
Returns an Iterable that walks over all descendants in document order applying the Filter to return only elements
that match the filter rule. |
DocType |
getDocType()
This will return the declaration for this Document , or
null if none exists. |
Document |
getDocument()
Return this parent's owning document or null if the branch containing this parent is currently not attached to a document. |
Parent |
getParent()
Return this parent's parent, or null if this parent is currently not attached to another parent. |
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. |
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. |
int |
indexOf(Content child)
Returns the index of the supplied child in the content list, or -1 if not a child of this parent. |
boolean |
removeContent(Content child)
Removes a single child node from the content list. |
Content |
removeContent(int index)
Removes and returns the child at the given index, or returns null if there's no such child. |
List<Content> |
removeContents()
Removes all child content from this parent. |
List<Content> |
removeContents(Filter filter)
Remove all child content from this parent matching the supplied filter. |
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. |
Document |
setContent(Collection<? extends Content> newContents)
This sets the content of the Document . |
Document |
setContent(Content child)
Set this document's content to be the supplied child. |
Document |
setContent(int index,
Collection<? extends Content> collection)
Replace the child at the given index whith the supplied collection. |
Document |
setContent(int index,
Content child)
|
Document |
setDocType(DocType docType)
This will set the declaration for this Document . |
void |
setProperty(String id,
Object value)
Assigns an arbitrary object to be associated with this document under the given "id" string. |
Document |
setRootElement(Element rootElement)
This sets the root for the Document . |
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 String baseURI
Constructor Detail |
---|
public Document()
public Document(Element rootElement, DocType docType, String baseURI)
Document
, with the supplied Element
as the root element,
the supplied DocType
declaration, and the specified base URI.
rootElement
- Element
for document root.docType
- DocType
declaration.baseURI
- the URI from which this doucment was loaded.
IllegalAddException
- if the given docType object is already attached to a document or the given
rootElement already has a parentpublic 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(List<Content> contents)
Document
, with the supplied list of content, and a DocType
declaration only if the content contains a DocType instance. A null list is treated the same as
the no-arg constructor.
contents
- List
of starter content
IllegalAddException
- if the List contains more than one Element or objects of illegal types.Method Detail |
---|
public int getContentsSize()
Parent
Content
type.
getContentsSize
in interface Parent
public int indexOf(Content child)
Parent
indexOf
in interface Parent
child
- child to search for
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
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(Content child)
child
- child to append to end of content list
IllegalAddException
- if the given child already has a parent.public Document addContent(Collection<? extends Content> newContents)
newContents
- collection to append
IllegalAddException
- if any item in the collection already has a parent or is of an illegal type.public Document addContent(int index, Content child)
index
- location for adding the collectionchild
- child to insert
IndexOutOfBoundsException
- if index is negative or beyond the current number of children
IllegalAddException
- if the given child already has a parent.public Document addContent(int index, Collection<? extends Content> contents)
index
- location for adding the collectioncontents
- collection to insert
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.public List<Content> cloneContents()
Parent
cloneContents
in interface Parent
public Content getContent(int index)
Parent
getContent
in interface Parent
index
- location of desired child
public List<Content> getContents()
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.
getContents
in interface Parent
IllegalStateException
- if the root element hasn't been setpublic List<Content> getContents(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.
getContents
in interface Parent
filter
- Filter
to apply
List
- filtered Document content
IllegalStateException
- if the root element hasn't been setpublic List<Content> removeContents()
removeContents
in interface Parent
public List<Content> removeContents(Filter filter)
removeContents
in interface Parent
filter
- filter to select which content to remove
public Document setContent(Collection<? extends Content> newContents)
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 getContents()
) 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 getContents()
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.
newContents
- List
of content to set
IllegalAddException
- if the List contains objects of illegal types or with existing parentage.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.
uri
- the base URI of this documentpublic final String getBaseURI()
Returns the URI from which this document was loaded, or null if this is not known.
public Document setContent(int index, Content child)
public Document setContent(int index, Collection<? extends Content> collection)
In event of an exception the original content will be unchanged and the content in the supplied collection will be unaltered.
index
- - index of child to replace.collection
- - collection of content to add.
IllegalAddException
- if the collection contains objects of illegal types.
IndexOutOfBoundsException
- if index is negative or greater than the current number of children.public boolean removeContent(Content child)
Parent
removeContent
in interface Parent
child
- child to remove
public Content removeContent(int index)
Parent
removeContent
in interface Parent
index
- index of child to remove
public Document setContent(Content child)
getContents()
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 the getContents()
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.
child
- new content to replace existing content
IllegalAddException
- if the supplied child is already attached or not legal content for this parentpublic 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.
toString
in class Object
String
- information about the Document
public final boolean equals(Object ob)
Document
to the supplied Object
.
equals
in class Object
ob
- Object
to compare to
boolean
whether the Document
is equal to the supplied Object
public final int hashCode()
Document
.
hashCode
in class Object
int
hash codepublic Document clone()
Document
.
clone
in interface Parent
clone
in class Object
Object
clone of this Document
public Iterable<Content> getDescendants()
Iterable
that walks over all descendants in document order.
getDescendants
in interface Parent
public Iterable<Content> getDescendants(Filter filter)
Iterable
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.
getDescendants
in interface Parent
filter
- filter to select which descendants to see
public Parent getParent()
Parent
getParent
in interface Parent
public Document getDocument()
Parent
getDocument
in interface Parent
Parent.getDocument()
public void setProperty(String id, Object value)
id
- the id of the stored objectvalue
- the object to storepublic Object getProperty(String id)
id
- the id of the stored object to return
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |