public class DefaultElement extends AbstractElement
DefaultElement
is the default DOM4J default implementation
of an XML element.
Modifier and Type | Field and Description |
---|---|
private Object |
attributes
Lazily constructes list of attributes
|
private Object |
content
Stores null for no content, a Node for a single content node
or a List for multiple content nodes.
|
private static DocumentFactory |
DOCUMENT_FACTORY
The
DocumentFactory instance used by default |
private Branch |
parentBranch
Stores the parent branch of this node which is either a Document
if this element is the root element in a document, or another Element
if it is a child of the root document, or null if it has not been added
to a document yet.
|
private QName |
qname
The
QName for this element |
EMPTY_ITERATOR, EMPTY_LIST, USE_STRINGVALUE_SEPARATOR, VERBOSE_TOSTRING
DEFAULT_CONTENT_LIST_SIZE, outputFormat
NODE_TYPE_NAMES
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 and Description |
---|
DefaultElement(QName qname) |
DefaultElement(QName qname,
int attributeCount) |
DefaultElement(String name) |
DefaultElement(String name,
Namespace namespace) |
Modifier and Type | Method and Description |
---|---|
void |
add(Attribute attribute)
Adds the given
Attribute to this element. |
List |
additionalNamespaces()
Returns any additional namespaces declarations for this element
other than namespace returned via the
Element.getNamespace() method. |
List |
additionalNamespaces(String defaultNamespaceURI) |
protected void |
addNewNode(Node node)
Like addNode() but does not require a parent check
|
Attribute |
attribute(int index)
Returns the attribute at the specified indexGets the
|
Attribute |
attribute(QName qName) |
Attribute |
attribute(String name)
Returns the attribute with the given name
|
Attribute |
attribute(String name,
Namespace namespace) |
int |
attributeCount() |
Iterator |
attributeIterator() |
protected List |
attributeList() |
protected List |
attributeList(int size) |
List |
attributes()
|
void |
clearContent()
Clears the content for this branch, removing any
Node
instances this branch may contain. |
Object |
clone()
clone will return a deep clone or if this node is
read-only then clone will return the same instance. |
protected List |
contentList() |
List |
declaredNamespaces()
Returns all the namespaces declared by this element.
|
Element |
element(QName qName)
Returns the first element for the given fully qualified name.
|
Element |
element(String name)
Returns the first element for the given local name and any namespace.
|
Element |
element(String name,
Namespace namespace) |
Iterator |
elementIterator()
Returns an iterator over all this elements child elements.
|
Iterator |
elementIterator(QName qName)
Returns an iterator over the elements contained in this element
which match the given fully qualified name.
|
Iterator |
elementIterator(String name)
Returns an iterator over the elements contained in this element
which match the given local name and any namespace.
|
Iterator |
elementIterator(String name,
Namespace namespace) |
List |
elements()
Returns the elements contained in this element.
|
List |
elements(QName qName)
Returns the elements contained in this element with the given
fully qualified name.
|
List |
elements(String name)
Returns the elements contained in this element with the given
local name and any namespace.
|
List |
elements(String name,
Namespace namespace) |
Document |
getDocument()
getDocument returns the Document
that this Node is part of if this node supports
the parent relationship. |
protected DocumentFactory |
getDocumentFactory() |
Namespace |
getNamespaceForPrefix(String prefix)
Returns the
Namespace which is mapped to the given
prefix or null if it could not be found. |
Namespace |
getNamespaceForURI(String uri)
Returns the
Namespace which is mapped to the given
URI or null if it could not be found. |
Element |
getParent()
getParent returns the parent Element
if this node supports the parent relationship or null if it is
the root element or does not support the parent relationship. |
QName |
getQName()
Returns the
QName of this element which represents
the local name, the qualified name and the Namespace . |
String |
getStringValue()
Returns the XPath string-value of this node.
|
String |
getText()
Returns the text of this node.
|
int |
indexOf(Node node)
Returns the index of the given node if it is a child node of this
branch or -1 if the given node is not a child node.
|
Node |
node(int index)
Returns the
Node at the specified index position. |
int |
nodeCount()
Returns the number of
Node instances that this branch
contains. |
Iterator |
nodeIterator()
Returns an iterator through the content nodes of this branch
|
ProcessingInstruction |
processingInstruction(String target) |
List |
processingInstructions()
Returns a list of all the processing instructions in this branch.
|
List |
processingInstructions(String target)
Returns a list of the processing instructions for the given target.
|
boolean |
remove(Attribute attribute)
Removes the given
Attribute from this element. |
protected boolean |
removeNode(Node node) |
boolean |
removeProcessingInstruction(String target)
Removes the processing instruction for the given target if it exists
|
protected void |
setAttributeList(List attributes) |
void |
setAttributes(List attributes)
Sets the attributes that this element contains
|
void |
setContent(List content)
Sets the contents of this branch as a
List of
Node instances. |
void |
setDocument(Document document)
setDocument sets the document of this node if the
parent relationship is supported or does nothing if the parent
relationship is not supported. |
void |
setParent(Element parent)
setParent sets the parent relationship of
this node if the parent relationship is supported or does nothing
if the parent relationship is not supported. |
void |
setQName(QName qname)
Sets the
QName of this element which represents
the local name, the qualified name and the Namespace . |
boolean |
supportsParent()
supportsParent returns true if this node supports the
parent relationship. |
accept, add, add, add, add, add, add, add, add, addAttribute, addAttribute, addCDATA, addComment, addElement, addEntity, addNamespace, addNode, addProcessingInstruction, addProcessingInstruction, addText, appendAttributes, asXML, attributeValue, attributeValue, attributeValue, attributeValue, childAdded, childRemoved, createAttributeList, createAttributeList, createCopy, createCopy, createCopy, createElement, createElement, createSingleIterator, elementText, elementText, elementTextTrim, elementTextTrim, ensureAttributesCapacity, getData, getName, getNamespace, getNamespacePrefix, getNamespaceURI, getNodeType, getPath, getQName, getQualifiedName, getUniquePath, getXPathNameStep, getXPathResult, hasMixedContent, isRootElement, isTextOnly, normalize, remove, remove, remove, remove, remove, remove, remove, remove, setAttributes, setAttributeValue, setAttributeValue, setData, setName, setNamespace, setText, toString, write
addElement, addElement, addElement, appendContent, content, contentRemoved, createContentList, createContentList, createEmptyList, createResultList, createSingleResultList, elementByID, elementID, getContentAsStringValue, getContentAsText, getTextTrim, hasContent, invalidNodeTypeAddException, isReadOnly, setProcessingInstructions
asXPathResult, createPattern, createXPath, createXPathFilter, createXPathResult, detach, getNodeTypeName, getPath, getUniquePath, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getTextTrim
addElement, addElement, appendContent, content, elementByID, setProcessingInstructions
asXPathResult, createXPath, detach, getNodeTypeName, getPath, getUniquePath, hasContent, isReadOnly, matches, numberValueOf, selectNodes, selectNodes, selectNodes, selectObject, selectSingleNode, valueOf
private static final transient DocumentFactory DOCUMENT_FACTORY
DocumentFactory
instance used by defaultprivate Branch parentBranch
private Object content
private Object attributes
public DefaultElement(String name)
public DefaultElement(QName qname)
public DefaultElement(QName qname, int attributeCount)
public DefaultElement(String name, Namespace namespace)
public Element getParent()
Node
getParent
returns the parent Element
if this node supports the parent relationship or null if it is
the root element or does not support the parent relationship.
This method is an optional feature and may not be supported
for all Node
implementations.
getParent
in interface Node
getParent
in class AbstractNode
public void setParent(Element parent)
Node
setParent
sets the parent relationship of
this node if the parent relationship is supported or does nothing
if the parent relationship is not supported.
This method should only be called from inside an
Element
implementation method and is not intended for
general use.
setParent
in interface Node
setParent
in class AbstractNode
parent
- is the new parent of this node.public Document getDocument()
Node
getDocument
returns the Document
that this Node
is part of if this node supports
the parent relationship.
This method is an optional feature and may not be supported
for all Node
implementations.
getDocument
in interface Node
getDocument
in class AbstractNode
Document
public void setDocument(Document document)
Node
setDocument
sets the document of this node if the
parent relationship is supported or does nothing if the parent
relationship is not supported.
This method should only be called from inside a
Document
implementation method and is not intended for
general use.
setDocument
in interface Node
setDocument
in class AbstractNode
document
- is the new document of this node.public boolean supportsParent()
Node
supportsParent
returns true if this node supports the
parent relationship.
Some XML tree implementations are singly linked and only support downward navigation through children relationships. The default case is that both parent and children relationships are supported though for memory and performance reasons the parent relationship may not be supported.
supportsParent
in interface Node
supportsParent
in class AbstractNode
public QName getQName()
Element
Returns the QName
of this element which represents
the local name, the qualified name and the Namespace
.
QName
associated with this elementpublic void setQName(QName qname)
Element
Sets the QName
of this element which represents
the local name, the qualified name and the Namespace
.
qname
- is the QName
to be associated with this elementpublic String getText()
Node
Returns the text of this node.
public String getStringValue()
Node
getStringValue
in interface Element
getStringValue
in interface Node
getStringValue
in class AbstractElement
public Object clone()
Node
clone
will return a deep clone or if this node is
read-only then clone will return the same instance.
clone
in interface Node
clone
in class AbstractNode
public Namespace getNamespaceForPrefix(String prefix)
Element
Returns the Namespace
which is mapped to the given
prefix or null if it could not be found.
getNamespaceForPrefix
in interface Element
getNamespaceForPrefix
in class AbstractElement
Namespace
associated with the given prefixpublic Namespace getNamespaceForURI(String uri)
Element
Returns the Namespace
which is mapped to the given
URI or null if it could not be found.
getNamespaceForURI
in interface Element
getNamespaceForURI
in class AbstractElement
Namespace
associated with the given URIpublic List declaredNamespaces()
Element
Returns all the namespaces declared by this element. If no namespaces are declared for this element then an empty list will be returned. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.
declaredNamespaces
in interface Element
declaredNamespaces
in class AbstractElement
public List additionalNamespaces()
Element
Returns any additional namespaces declarations for this element
other than namespace returned via the Element.getNamespace()
method.
If no additional namespace declarations are present for this
element then an empty list will be returned.
The list is backed by the element such that changes to the list will
be reflected in the element though the reverse is not the case.
additionalNamespaces
in interface Element
additionalNamespaces
in class AbstractElement
public List additionalNamespaces(String defaultNamespaceURI)
additionalNamespaces
in class AbstractElement
public List processingInstructions()
Branch
Returns a list of all the processing instructions in this branch. The list is backed by this branch so that changes to the list will be reflected in the branch but the reverse is not the case.
processingInstructions
in interface Branch
processingInstructions
in class AbstractElement
public List processingInstructions(String target)
Branch
Returns a list of the processing instructions for the given target. The list is backed by this branch so that changes to the list will be reflected in the branch but the reverse is not the case.
processingInstructions
in interface Branch
processingInstructions
in class AbstractElement
public ProcessingInstruction processingInstruction(String target)
processingInstruction
in interface Branch
processingInstruction
in class AbstractElement
public boolean removeProcessingInstruction(String target)
Branch
removeProcessingInstruction
in interface Branch
removeProcessingInstruction
in class AbstractElement
public Element element(String name)
Element
element
in interface Element
element
in class AbstractElement
public Element element(QName qName)
Element
element
in interface Element
element
in class AbstractElement
public Element element(String name, Namespace namespace)
element
in class AbstractElement
public List elements()
Element
Returns the elements contained in this element. If this element does not contain any elements then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.
elements
in interface Element
elements
in class AbstractElement
public List elements(String name)
Element
Returns the elements contained in this element with the given local name and any namespace. If no elements are found then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.
elements
in interface Element
elements
in class AbstractElement
public List elements(QName qName)
Element
Returns the elements contained in this element with the given fully qualified name. If no elements are found then this method returns an empty list. The list is backed by the element such that changes to the list will be reflected in the element though the reverse is not the case.
elements
in interface Element
elements
in class AbstractElement
qName
- is the fully qualified name to search forpublic List elements(String name, Namespace namespace)
elements
in class AbstractElement
public Iterator elementIterator()
Element
elementIterator
in interface Element
elementIterator
in class AbstractElement
public Iterator elementIterator(String name)
Element
elementIterator
in interface Element
elementIterator
in class AbstractElement
public Iterator elementIterator(QName qName)
Element
elementIterator
in interface Element
elementIterator
in class AbstractElement
public Iterator elementIterator(String name, Namespace namespace)
elementIterator
in class AbstractElement
public void setContent(List content)
Branch
List
of
Node
instances.content
- is the list of nodes to use as the content for this
branch.public void clearContent()
Branch
Node
instances this branch may contain.public Node node(int index)
Branch
Node
at the specified index position.node
in interface Branch
node
in class AbstractElement
index
- the index of the node to return.Node
at the specified position.public int indexOf(Node node)
Branch
indexOf
in interface Branch
indexOf
in class AbstractElement
node
- the content child node to find.public int nodeCount()
Branch
Node
instances that this branch
contains.nodeCount
in interface Branch
nodeCount
in class AbstractElement
public Iterator nodeIterator()
Branch
nodeIterator
in interface Branch
nodeIterator
in class AbstractElement
public List attributes()
Element
Returns the Attribute
instances this element contains as
a backed List
so that the attributes may be modified directly
using the List
interface.
The List
is backed by the Element
so that
changes to the list are reflected in the element and vice versa.
attributes
in interface Element
attributes
in class AbstractElement
List
public void setAttributes(List attributes)
Element
public Iterator attributeIterator()
attributeIterator
in interface Element
attributeIterator
in class AbstractElement
public Attribute attribute(int index)
Element
attribute
in interface Element
attribute
in class AbstractElement
public int attributeCount()
attributeCount
in interface Element
attributeCount
in class AbstractElement
public Attribute attribute(String name)
Element
attribute
in interface Element
attribute
in class AbstractElement
public Attribute attribute(QName qName)
attribute
in interface Element
attribute
in class AbstractElement
public Attribute attribute(String name, Namespace namespace)
attribute
in class AbstractElement
public void add(Attribute attribute)
Element
Attribute
to this element.
If the given node already has a parent defined then an
InvalidAddNodeException
will be thrown.add
in interface Element
add
in class AbstractElement
attribute
- is the attribute to be addedpublic boolean remove(Attribute attribute)
Element
Attribute
from this element.remove
in interface Element
remove
in class AbstractElement
attribute
- is the attribute to be removedprotected void addNewNode(Node node)
AbstractElement
addNewNode
in class AbstractElement
protected boolean removeNode(Node node)
removeNode
in class AbstractElement
protected List contentList()
contentList
in class AbstractBranch
protected List attributeList()
attributeList
in class AbstractElement
protected List attributeList(int size)
attributeList
in class AbstractElement
protected void setAttributeList(List attributes)
protected DocumentFactory getDocumentFactory()
getDocumentFactory
in class AbstractElement
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses