org.jdom
Class Document

java.lang.Object
  |
  +--org.jdom.Document

public class Document
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Document defines behavior for an XML Document, modeled in Java. Methods allow the user to the root element as well as processing instructions and other document-level information.

Version:
1.0
Author:
Brett McLaughlin, Jason Hunter
See Also:
Serialized Form

Field Summary
protected  java.util.List content
          This Document's Comments, ProcessingInstructions and the root Element
protected  DocType docType
          The DocType declaration
protected  Element rootElement
          The root Element of the Document.
 
Constructor Summary
protected Document()
           Default, no-args constructor for implementations to use if needed.
  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.
 
Method Summary
 Document addComment(Comment c)
          Deprecated. use addContent(Comment) instead
 Document addContent(Comment comment)
           This will add a comment to the Document.
 Document addContent(Element element)
           This will add an element to the Document.
 Document addContent(ProcessingInstruction pi)
           Adds the specified PI to the document.
 Document addProcessingInstruction(ProcessingInstruction pi)
          Deprecated. use addContent(ProcessingInstruction) instead
 Document addProcessingInstruction(java.lang.String target, java.util.Map data)
          Deprecated. use addContent(ProcessingInstruction) instead
 Document addProcessingInstruction(java.lang.String target, java.lang.String data)
          Deprecated. use addContent(ProcessingInstruction) instead
 java.lang.Object clone()
           This will return a deep clone of this Document.
 boolean equals(java.lang.Object ob)
           This tests for equality of this Document to the supplied Object.
 DocType getDocType()
           This will return the DocType declaration for this Document, or null if none exists.
 java.util.List getMixedContent()
           This will return all content for the Document.
 ProcessingInstruction getProcessingInstruction(java.lang.String target)
           This returns the first processing instruction for this Document located at the document level (outside the root element) for the supplied target, or null if no such processing instruction exists.
 java.util.List getProcessingInstructions()
           This will return the list of ProcessingInstructions for this Document located at the document level (outside the root element).
 java.util.List getProcessingInstructions(java.lang.String target)
           This returns the processing instructions for this Document located at the document level (outside the root element) which have the supplied target.
 Element getRootElement()
           This will return the root Element for this Document, or return null in the case the root element hasn't been yet set.
 java.lang.String getSerializedForm()
           This will return the Document in XML format, usable in an XML document.
 int hashCode()
           This returns the hash code for this Document.
 boolean removeProcessingInstruction(ProcessingInstruction pi)
          Deprecated. use doc.getMixedContent().remove(PI) instead
 boolean removeProcessingInstruction(java.lang.String target)
           This will remove the first PI with the specified target.
 boolean removeProcessingInstructions(java.lang.String target)
           This will remove all PIs with the specified target.
 Document setDocType(DocType docType)
           This will set the DocType declaration for this Document.
 Document setMixedContent(java.util.List content)
           This will set all content for the Document.
 Document setProcessingInstructions(java.util.List pis)
           This sets the PIs for this Document to those in the List
 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

content

protected java.util.List content
This Document's Comments, ProcessingInstructions and the root Element

rootElement

protected Element rootElement
The root Element of the Document.

docType

protected DocType docType
The DocType declaration
Constructor Detail

Document

protected Document()

Default, no-args constructor for implementations to use if needed.


Document

public Document(Element rootElement,
                DocType docType)

This will create a new Document, with the supplied Element as the root element and the supplied DocType declaration.

Parameters:
rootElement - Element for document root.
docType - DocType declaration.

Document

public Document(Element rootElement)

This will create a new Document, with the supplied Element as the root element, and no DocType declaration.

Parameters:
rootElement - Element for document root
Method Detail

getRootElement

public Element getRootElement()

This will return the root Element for this Document, or return null in the case the root element hasn't been yet set.

Returns:
Element - the document's root element, or null if none has been yet set

setRootElement

public Document setRootElement(Element rootElement)

This sets the root Element for the Document.

Parameters:
rootElement - Element to be new root.
Returns:
Document - modified Document.

getDocType

public DocType getDocType()

This will return the DocType declaration for this Document, or null if none exists.

Returns:
DocType - the DOCTYPE declaration.

setDocType

public Document setDocType(DocType docType)

This will set the DocType declaration for this Document.

Parameters:
docType - DocType declaration.

getProcessingInstructions

public java.util.List getProcessingInstructions()

This will return the list of ProcessingInstructions for this Document located at the document level (outside the root element). The returned list is "live" and changes to it affect the document's actual content.

Returns:
List - PIs for document.

getProcessingInstructions

public java.util.List getProcessingInstructions(java.lang.String target)

This returns the processing instructions for this Document located at the document level (outside the root element) which have the supplied target. The returned list is "live" and changes to it affect the document's actual content.

Parameters:
target - String target of PI to return.
Returns:
List - all PIs with the specified target.

getProcessingInstruction

public ProcessingInstruction getProcessingInstruction(java.lang.String target)

This returns the first processing instruction for this Document located at the document level (outside the root element) for the supplied target, or null if no such processing instruction exists.

Parameters:
target - String target of PI to return.
Returns:
ProcessingInstruction - the first PI with the specified target, or null if no such PI exists.

removeProcessingInstruction

public boolean removeProcessingInstruction(java.lang.String target)

This will remove the first PI with the specified target.

Parameters:
target - String target of PI to remove.
Returns:
boolean - whether the requested PI was removed.

removeProcessingInstructions

public boolean removeProcessingInstructions(java.lang.String target)

This will remove all PIs with the specified target.

Parameters:
target - String target of PI to remove.
Returns:
boolean - whether the requested PIs were removed.

setProcessingInstructions

public Document setProcessingInstructions(java.util.List pis)

This sets the PIs for this Document to those in the List

Parameters:
pis - List of PIs to use.
Returns:
Document - this Document modified.

addContent

public Document addContent(ProcessingInstruction pi)

Adds the specified PI to the document.

Parameters:
pi - the PI to add.
Returns:
Document this document modified.

addContent

public Document addContent(Comment comment)

This will add a comment to the Document.

Parameters:
comment - Comment to add.
Returns:
Document - this object modified.

addContent

public Document addContent(Element element)

This will add an element to the Document.

Parameters:
element - Element to add.
Returns:
Document - this object modified.

getMixedContent

public java.util.List getMixedContent()

This will return all content for the Document. The returned list is "live" and changes to it affect the document's actual content.

Returns:
List - all Document content

setMixedContent

public Document setMixedContent(java.util.List content)

This will set all content for the Document. The List may contain only objects of type Element, Comment, and ProcessingInstruction; and only one Element that becomes the root.

Parameters:
content - the new mixed content
Returns:
the modified Document
Throws:
IllegalAddException - if the List contains more than one Element or objects of illegal types

toString

public final java.lang.String toString()

This returns a String representation of the Document, suitable for debugging. If the XML representation of the Comment is desired, getSerializedForm() should be used.

Returns:
String - information about the Document
Overrides:
toString in class java.lang.Object

getSerializedForm

public final java.lang.String getSerializedForm()

This will return the Document in XML format, usable in an XML document.

Returns:
String - the serialized form of the Document.

equals

public final boolean equals(java.lang.Object ob)

This tests for equality of this Document to the supplied Object.

Parameters:
ob - Object to compare to.
Returns:
boolean - whether the Document is equal to the supplied Object.
Overrides:
equals in class java.lang.Object

hashCode

public final int hashCode()

This returns the hash code for this Document.

Returns:
int - hash code.
Overrides:
hashCode in class java.lang.Object

clone

public final java.lang.Object clone()

This will return a deep clone of this Document.

Returns:
Object - clone of this Document.
Overrides:
clone in class java.lang.Object

addComment

public Document addComment(Comment c)
Deprecated. use addContent(Comment) instead

addProcessingInstruction

public Document addProcessingInstruction(ProcessingInstruction pi)
Deprecated. use addContent(ProcessingInstruction) instead

addProcessingInstruction

public Document addProcessingInstruction(java.lang.String target,
                                         java.lang.String data)
Deprecated. use addContent(ProcessingInstruction) instead

addProcessingInstruction

public Document addProcessingInstruction(java.lang.String target,
                                         java.util.Map data)
Deprecated. use addContent(ProcessingInstruction) instead

removeProcessingInstruction

public boolean removeProcessingInstruction(ProcessingInstruction pi)
Deprecated. use doc.getMixedContent().remove(PI) instead


Copyright © 2000 Brett McLaughlin, Jason Hunter. All Rights Reserved.