|
|||||||||
| Home >> All >> org >> [ jdom overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.jdom
Class Document

java.lang.Objectorg.jdom.Document
- All Implemented Interfaces:
- java.lang.Cloneable, Parent, java.io.Serializable
- public class Document
- extends java.lang.Object
- implements Parent
- extends java.lang.Object
An XML document. Methods allow access to the root element as well as the DocType and other document-level information.
- Version:
- $Revision: 1.84 $, $Date: 2004/08/31 21:47:51 $
| Field Summary | |
protected java.lang.String |
baseURI
See http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/core.html#baseURIs-Considerations |
(package private) ContentList |
content
This document's content including comments, PIs, a possible DocType, and a root element. |
private static java.lang.String |
CVS_ID
|
private java.util.HashMap |
propertyMap
|
| Constructor Summary | |
Document()
Creates a new empty document. |
|
Document(Element rootElement)
This will create a new Document,
with the supplied Element
as the root element, and no DocType
declaration. |
|
Document(Element rootElement,
DocType docType)
This will create a new Document,
with the supplied Element
as the root element and the supplied
DocType declaration. |
|
Document(Element rootElement,
DocType docType,
java.lang.String baseURI)
This will create a new Document,
with the supplied Element
as the root element, the supplied
DocType declaration, and the specified
base URI. |
|
Document(java.util.List content)
This will create a new Document,
with the supplied list of content, and a
DocType declaration only if the content
contains a DocType instance. |
|
| Method Summary | |
Document |
addContent(java.util.Collection c)
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,
java.util.Collection c)
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. |
java.lang.Object |
clone()
This will return a deep clone of this Document. |
java.util.List |
cloneContent()
Returns a list containing detached clones of this parent's content list. |
Element |
detachRootElement()
Detach the root Element from this document. |
boolean |
equals(java.lang.Object ob)
This tests for equality of this Document to the supplied
Object. |
java.lang.String |
getBaseURI()
Returns the URI from which this document was loaded, or null if this is not known. |
java.util.List |
getContent()
This will return all content for the Document. |
java.util.List |
getContent(org.jdom.filter.Filter filter)
Return a filtered view of this Document's content. |
Content |
getContent(int index)
Returns the child at the given index. |
int |
getContentSize()
Returns the number of children in this parent's content list. |
java.util.Iterator |
getDescendants()
Returns an iterator that walks over all descendants in document order. |
java.util.Iterator |
getDescendants(org.jdom.filter.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. |
DocType |
getDocType()
This will return the DocType
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. |
java.lang.Object |
getProperty(java.lang.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. |
java.util.List |
removeContent()
Removes all child content from this parent. |
boolean |
removeContent(Content child)
Removes a single child node from the content list. |
java.util.List |
removeContent(org.jdom.filter.Filter filter)
Remove all child content from this parent matching the supplied filter. |
Content |
removeContent(int index)
Removes and returns the child at the given index, or returns null if there's no such child. |
void |
setBaseURI(java.lang.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(java.util.Collection newContent)
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,
java.util.Collection 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 DocType
declaration for this Document. |
void |
setProperty(java.lang.String id,
java.lang.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 Element 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 |
CVS_ID
private static final java.lang.String CVS_ID
- See Also:
- Constant Field Values
content
ContentList content
- This document's content including comments, PIs, a possible
DocType, and a root element.
Subclassers have to track content using their own
mechanism.
baseURI
protected java.lang.String baseURI
- See http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/core.html#baseURIs-Considerations
propertyMap
private java.util.HashMap propertyMap
| Constructor Detail |
Document
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.
Document
public Document(Element rootElement, DocType docType, java.lang.String baseURI)
- This will create a new
Document, with the suppliedElementas the root element, the suppliedDocTypedeclaration, and the specified base URI.
Document
public Document(Element rootElement, DocType docType)
- This will create a new
Document, with the suppliedElementas the root element and the suppliedDocTypedeclaration.
Document
public Document(Element rootElement)
- This will create a new
Document, with the suppliedElementas the root element, and noDocTypedeclaration.
Document
public Document(java.util.List content)
- This will create a new
Document, with the supplied list of content, and aDocTypedeclaration only if the content contains a DocType instance. A null list is treated the same as the no-arg constructor.
| Method Detail |
getContentSize
public int getContentSize()
- Description copied from interface:
Parent - Returns the number of children in this parent's content list.
Children may be any Content type.
- Specified by:
getContentSizein interfaceParent
indexOf
public int indexOf(Content child)
- Description copied from interface:
Parent - Returns the index of the supplied child in the content list,
or -1 if not a child of this parent.
hasRootElement
public boolean hasRootElement()
- This will return
trueif this document has a root element,falseotherwise.
getRootElement
public Element getRootElement()
- This will return the root
Elementfor thisDocument
setRootElement
public Document setRootElement(Element rootElement)
- This sets the root
Elementfor theDocument. If the document already has a root element, it is replaced.
detachRootElement
public Element detachRootElement()
- Detach the root
Elementfrom this document.
getDocType
public DocType getDocType()
- This will return the
DocTypedeclaration for thisDocument, ornullif none exists.
setDocType
public Document setDocType(DocType docType)
- This will set the
DocTypedeclaration for thisDocument. 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.
addContent
public Document addContent(Content child)
- Appends the child to the end of the content list.
addContent
public Document addContent(java.util.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.
addContent
public Document addContent(int index, Content child)
- Inserts the child into the content list at the given index.
addContent
public Document addContent(int index, java.util.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.
cloneContent
public java.util.List cloneContent()
- Description copied from interface:
Parent - Returns a list containing detached clones of this parent's content list.
- Specified by:
cloneContentin interfaceParent
getContent
public Content getContent(int index)
- Description copied from interface:
Parent - Returns the child at the given index.
- Specified by:
getContentin interfaceParent
getContent
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.
- Specified by:
getContentin interfaceParent
getContent
public java.util.List getContent(org.jdom.filter.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.
- Specified by:
getContentin interfaceParent
removeContent
public java.util.List removeContent()
- Removes all child content from this parent.
- Specified by:
removeContentin interfaceParent
removeContent
public java.util.List removeContent(org.jdom.filter.Filter filter)
- Remove all child content from this parent matching the supplied filter.
- Specified by:
removeContentin interfaceParent
setContent
public Document setContent(java.util.Collection newContent)
- This sets the content of the
Document. 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 to
getContent(int)55 ) 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(int)55 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.
setBaseURI
public final void setBaseURI(java.lang.String uri)
Sets the effective URI from which this document was loaded, and against which relative URLs in this document will be resolved.
getBaseURI
public final java.lang.String getBaseURI()
Returns the URI from which this document was loaded, or null if this is not known.
setContent
public Document setContent(int index, Content child)
setContent
public Document setContent(int index, java.util.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.
removeContent
public boolean removeContent(Content child)
- Description copied from interface:
Parent - Removes a single child node from the content list.
- Specified by:
removeContentin interfaceParent
removeContent
public Content removeContent(int index)
- Description copied from interface:
Parent - Removes and returns the child at the given
index, or returns null if there's no such child.
- Specified by:
removeContentin interfaceParent
setContent
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 the
getContent(int)55 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(int)55 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.
toString
public java.lang.String toString()
- This returns a
Stringrepresentation of theDocument, suitable for debugging. If the XML representation of theDocumentis desired,org.jdom.output.XMLOutputter#outputString(Document)should be used.
equals
public final boolean equals(java.lang.Object ob)
- This tests for equality of this
Documentto the suppliedObject.
hashCode
public final int hashCode()
- This returns the hash code for this
Document.
clone
public java.lang.Object clone()
getDescendants
public java.util.Iterator getDescendants()
- Returns an iterator that walks over all descendants in document order.
- Specified by:
getDescendantsin interfaceParent
getDescendants
public java.util.Iterator getDescendants(org.jdom.filter.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:
getDescendantsin interfaceParent
getParent
public Parent getParent()
- Description copied from interface:
Parent - 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.
getDocument
public Document getDocument()
- Description copied from interface:
Parent - Return this parent's owning document or null if the branch containing
this parent is currently not attached to a document.
- Specified by:
getDocumentin interfaceParent
setProperty
public void setProperty(java.lang.String id, java.lang.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.
getProperty
public java.lang.Object getProperty(java.lang.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.
|
|||||||||
| Home >> All >> org >> [ jdom overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.jdom.Document