Class AbstractDocument
- java.lang.Object
 - 
- org.dom4j.tree.AbstractNode
 - 
- org.dom4j.tree.AbstractBranch
 - 
- org.dom4j.tree.AbstractDocument
 
 
 
 
- 
- All Implemented Interfaces:
 Serializable,Cloneable,Branch,Document,Node
- Direct Known Subclasses:
 DefaultDocument
public abstract class AbstractDocument extends AbstractBranch implements Document
AbstractDocumentis an abstract base class for tree implementors to use for implementation inheritence.- See Also:
 - Serialized Form
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected StringencodingThe encoding of this document as stated in the XML declaration- 
Fields inherited from class org.dom4j.tree.AbstractBranch
DEFAULT_CONTENT_LIST_SIZE 
- 
Fields inherited from class org.dom4j.tree.AbstractNode
NODE_TYPE_NAMES 
- 
Fields inherited from interface org.dom4j.Node
ANY_NODE, ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_REFERENCE_NODE, MAX_NODE_TYPE, NAMESPACE_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE, UNKNOWN_NODE 
 - 
 
- 
Constructor Summary
Constructors Constructor Description AbstractDocument() 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaccept(Visitor visitor)acceptmethod is theVisitor Patternmethod.voidadd(Element element)Adds the givenElementto this branch.DocumentaddComment(String comment)Adds a newCommentnode with the given text to this branch.ElementaddElement(String name)Adds a newElementnode with the given name to this branch and returns a reference to the new node.ElementaddElement(String qualifiedName, String namespaceURI)Adds a newElementnode with the given qualified name and namespace URI to this branch and returns a reference to the new node.ElementaddElement(QName qName)Adds a newElementnode with the givenQNameto this branch and returns a reference to the new node.DocumentaddProcessingInstruction(String target, String data)Adds a processing instruction for the given targetDocumentaddProcessingInstruction(String target, Map<String,String> data)Adds a processing instruction for the given targetStringasXML()asXMLreturns the textual XML representation of this node.NodeasXPathResult(Element parent)asXPathResultreturns a version of this node which is capable of being an XPath result.protected voidcheckAddElementAllowed(Element element)protected voidchildAdded(Node node)Called when a new child node has been added to me to allow any parent relationships to be created or events to be fired.protected voidchildRemoved(Node node)Called when a child node has been removed to allow any parent relationships to be deleted or events to be fired.DocumentgetDocument()getDocumentreturns theDocumentthat thisNodeis part of if this node supports the parent relationship.shortgetNodeType()Returns the code according to the type of node.StringgetPath(Element context)Returns the relative XPath expression which will return a node set containing the given node such as a/b/@c.StringgetStringValue()Returns the XPath string-value of this node.StringgetUniquePath(Element context)Returns the relative unique XPath expression from the given context which will return a nodeset of one node which is the current node.StringgetXMLEncoding()Return the encoding of this document, as part of the XML declaration This isnullwhen unspecified or when it is not known (such as when the Document was created in memory) or when the implementation does not support this operation.voidnormalize()Puts allTextnodes in the full depth of the sub-tree underneath thisNode, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separatesTextnodes, i.e., there are neither adjacentTextnodes nor emptyTextnodes.booleanremove(Element element)Removes the givenElementif the node is an immediate child of this branch.protected abstract voidrootElementAdded(Element rootElement)Called to set the root element variablevoidsetRootElement(Element rootElement)Sets the root element for this documentvoidsetXMLEncoding(String enc)Sets the encoding of this document as it will appear in the XML declaration part of the document.StringtoString()voidwrite(Writer out)writewrites this node as the default XML notation for this node.- 
Methods inherited from class org.dom4j.tree.AbstractBranch
add, add, add, addElement, addNode, addNode, appendContent, content, contentList, contentRemoved, createContentList, createContentList, createEmptyList, createResultList, createSingleResultList, elementByID, elementID, getContentAsStringValue, getContentAsText, getText, getTextTrim, hasContent, indexOf, invalidNodeTypeAddException, isReadOnly, node, nodeCount, nodeIterator, remove, remove, remove, removeNode, setProcessingInstructions 
- 
Methods inherited from class org.dom4j.tree.AbstractNode
clone, createPattern, createXPath, createXPathFilter, createXPathResult, detach, getDocumentFactory, getName, getNodeTypeName, getParent, getPath, getUniquePath, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, setDocument, setName, setParent, setText, supportsParent, valueOf 
- 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
- 
Methods inherited from interface org.dom4j.Branch
add, add, add, appendContent, clearContent, content, elementByID, indexOf, node, nodeCount, nodeIterator, processingInstruction, processingInstructions, processingInstructions, remove, remove, remove, removeProcessingInstruction, setContent, setProcessingInstructions 
- 
Methods inherited from interface org.dom4j.Document
addDocType, getDocType, getEntityResolver, getRootElement, setDocType, setEntityResolver 
- 
Methods inherited from interface org.dom4j.Node
clone, createXPath, detach, getName, getNodeTypeName, getParent, getPath, getText, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, setDocument, setName, setParent, setText, supportsParent, valueOf 
 - 
 
 - 
 
- 
- 
Field Detail
- 
encoding
protected String encoding
The encoding of this document as stated in the XML declaration 
 - 
 
- 
Method Detail
- 
getNodeType
public short getNodeType()
Description copied from interface:NodeReturns the code according to the type of node. This makes processing nodes polymorphically much easier as the switch statement can be used instead of multiple if (instanceof) statements.- Specified by:
 getNodeTypein interfaceNode- Overrides:
 getNodeTypein classAbstractNode- Returns:
 - a W3C DOM complient code for the node type such as ELEMENT_NODE or ATTRIBUTE_NODE
 
 
- 
getPath
public String getPath(Element context)
Description copied from interface:NodeReturns the relative XPath expression which will return a node set containing the given node such as a/b/@c. No indexing will be used to restrict the path if multiple elements with the same name occur on the path.- Specified by:
 getPathin interfaceNode- Parameters:
 context- is the parent context from which the relative path should start. If the context is null or the context is not an ancestor of this node then the path will be absolute and start from the document and so begin with the '/' character.- Returns:
 - the XPath expression relative to the given context which will return a nodeset containing at least this node.
 
 
- 
getUniquePath
public String getUniquePath(Element context)
Description copied from interface:NodeReturns the relative unique XPath expression from the given context which will return a nodeset of one node which is the current node. This method will use the XPath index operator to restrict the path if multiple elements with the same name occur on the path.
- Specified by:
 getUniquePathin interfaceNode- Parameters:
 context- is the parent context from which the path should start. If the context is null or the context is not an ancestor of this node then the path will start from the document and so begin with the '/' character.- Returns:
 - the XPath expression relative to the given context which will return a nodeset containing just this node.
 
 
- 
getDocument
public Document getDocument()
Description copied from interface:NodegetDocumentreturns theDocumentthat thisNodeis part of if this node supports the parent relationship.This method is an optional feature and may not be supported for all
Nodeimplementations.- Specified by:
 getDocumentin interfaceNode- Overrides:
 getDocumentin classAbstractNode- Returns:
 - the document of this node or null if this feature is not
         supported or the node is not associated with a
         
Document 
 
- 
getXMLEncoding
public String getXMLEncoding()
Description copied from interface:DocumentReturn the encoding of this document, as part of the XML declaration This isnullwhen unspecified or when it is not known (such as when the Document was created in memory) or when the implementation does not support this operation. The way this encoding is retrieved also depends on the way the XML source is parsed. For instance, if the SAXReader is used and if the underlying XMLReader implementation support theorg.xml.sax.ext.Locator2interface, the result returned by this method is specified by thegetEncoding()method of that interface.- Specified by:
 getXMLEncodingin interfaceDocument- Returns:
 - The encoding of this document, as stated in the XML declaration,
         or 
nullif unknown. 
 
- 
getStringValue
public String getStringValue()
Description copied from interface:NodeReturns the XPath string-value of this node. The behaviour of this method is defined in the XPath specification .- Specified by:
 getStringValuein interfaceNode- Overrides:
 getStringValuein classAbstractNode- Returns:
 - the text from all the child Text and Element nodes appended together.
 
 
- 
asXML
public String asXML()
Description copied from interface:NodeasXMLreturns the textual XML representation of this node. 
- 
write
public void write(Writer out) throws IOException
Description copied from interface:Nodewritewrites this node as the default XML notation for this node. If you wish to control the XML output (such as for pretty printing, changing the indentation policy etc.) then please useXMLWriteror its derivations.- Specified by:
 writein interfaceNode- Overrides:
 writein classAbstractNode- Parameters:
 out- is theWriterto output the XML to- Throws:
 IOException- DOCUMENT ME!
 
- 
accept
public void accept(Visitor visitor)
acceptmethod is theVisitor Patternmethod. 
- 
normalize
public void normalize()
Description copied from interface:BranchPuts allTextnodes in the full depth of the sub-tree underneath thisNode, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separatesTextnodes, i.e., there are neither adjacentTextnodes nor emptyTextnodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.In cases where the document containsCDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate betweenTextnodes andCDATASectionnodes. 
- 
addComment
public Document addComment(String comment)
Description copied from interface:DocumentAdds a newCommentnode with the given text to this branch.- Specified by:
 addCommentin interfaceDocument- Parameters:
 comment- is the text for theCommentnode.- Returns:
 - this 
Documentinstance. 
 
- 
addProcessingInstruction
public Document addProcessingInstruction(String target, String data)
Description copied from interface:DocumentAdds a processing instruction for the given target- Specified by:
 addProcessingInstructionin interfaceDocument- Parameters:
 target- is the target of the processing instructiondata- is the textual data (key/value pairs) of the processing instruction- Returns:
 - this 
Documentinstance. 
 
- 
addProcessingInstruction
public Document addProcessingInstruction(String target, Map<String,String> data)
Description copied from interface:DocumentAdds a processing instruction for the given target- Specified by:
 addProcessingInstructionin interfaceDocument- Parameters:
 target- is the target of the processing instructiondata- is a Map of the key / value pairs of the processing instruction- Returns:
 - this 
Documentinstance. 
 
- 
addElement
public Element addElement(String name)
Description copied from interface:BranchAdds a newElementnode with the given name to this branch and returns a reference to the new node.- Specified by:
 addElementin interfaceBranch- Overrides:
 addElementin classAbstractBranch- Parameters:
 name- is the name for theElementnode.- Returns:
 - the newly added 
Elementnode. 
 
- 
addElement
public Element addElement(String qualifiedName, String namespaceURI)
Description copied from interface:BranchAdds a newElementnode with the given qualified name and namespace URI to this branch and returns a reference to the new node.- Specified by:
 addElementin interfaceBranch- Overrides:
 addElementin classAbstractBranch- Parameters:
 qualifiedName- is the fully qualified name of the ElementnamespaceURI- is the URI of the namespace to use- Returns:
 - the newly added 
Elementnode. 
 
- 
addElement
public Element addElement(QName qName)
Description copied from interface:BranchAdds a newElementnode with the givenQNameto this branch and returns a reference to the new node.- Specified by:
 addElementin interfaceBranch- Overrides:
 addElementin classAbstractBranch- Parameters:
 qName- is the qualified name for theElementnode.- Returns:
 - the newly added 
Elementnode. 
 
- 
setRootElement
public void setRootElement(Element rootElement)
Description copied from interface:DocumentSets the root element for this document- Specified by:
 setRootElementin interfaceDocument- Parameters:
 rootElement- the new root element for this document
 
- 
add
public void add(Element element)
Description copied from interface:BranchAdds the givenElementto this branch. If the given node already has a parent defined then anIllegalAddExceptionwill be thrown.- Specified by:
 addin interfaceBranch- Overrides:
 addin classAbstractBranch- Parameters:
 element- is the element to be added
 
- 
remove
public boolean remove(Element element)
Description copied from interface:BranchRemoves the givenElementif the node is an immediate child of this branch. If the given node is not an immediate child of this branch then theNode.detach()method should be used instead.- Specified by:
 removein interfaceBranch- Overrides:
 removein classAbstractBranch- Parameters:
 element- is the element to be removed- Returns:
 - true if the element was removed
 
 
- 
asXPathResult
public Node asXPathResult(Element parent)
Description copied from interface:NodeasXPathResultreturns a version of this node which is capable of being an XPath result. The result of an XPath expression should always support the parent relationship, whether the original XML tree was singly or doubly linked. If the node does not support the parent relationship then a new node will be created which is linked to its parent and returned.- Specified by:
 asXPathResultin interfaceNode- Overrides:
 asXPathResultin classAbstractNode- Parameters:
 parent- DOCUMENT ME!- Returns:
 - a 
Nodewhich supports the parent relationship 
 
- 
childAdded
protected void childAdded(Node node)
Description copied from class:AbstractBranchCalled when a new child node has been added to me to allow any parent relationships to be created or events to be fired.- Specified by:
 childAddedin classAbstractBranch- Parameters:
 node- DOCUMENT ME!
 
- 
childRemoved
protected void childRemoved(Node node)
Description copied from class:AbstractBranchCalled when a child node has been removed to allow any parent relationships to be deleted or events to be fired.- Specified by:
 childRemovedin classAbstractBranch- Parameters:
 node- DOCUMENT ME!
 
- 
checkAddElementAllowed
protected void checkAddElementAllowed(Element element)
 
- 
rootElementAdded
protected abstract void rootElementAdded(Element rootElement)
Called to set the root element variable- Parameters:
 rootElement- DOCUMENT ME!
 
- 
setXMLEncoding
public void setXMLEncoding(String enc)
Description copied from interface:DocumentSets the encoding of this document as it will appear in the XML declaration part of the document.- Specified by:
 setXMLEncodingin interfaceDocument- Parameters:
 enc- the encoding of the document
 
 - 
 
 -