|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.xerces.dom.NodeImpl | +--org.apache.xerces.dom.ChildNode | +--org.apache.xerces.dom.ParentNode | +--org.apache.xerces.dom.CoreDocumentImpl
The Document interface represents the entire HTML or XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a Document, the Document interface also contains the factory methods needed to create these objects. The Node objects created have a ownerDocument attribute which associates them with the Document within whose context they were created.
The CoreDocumentImpl class only implements the DOM Core. Additional modules are supported by the more complete DocumentImpl subclass.
Note: When any node in the document is serialized, the entire document is serialized along with it.
Field Summary | |
---|---|
protected boolean |
allowGrammarAccess
Allow grammar access. |
protected int |
changes
Number of alterations made to this document since its creation. |
protected ElementImpl |
docElement
Document element. |
protected DocumentTypeImpl |
docType
Document type. |
protected java.lang.String |
encoding
Experimental DOM Level 3 feature: Document encoding |
protected boolean |
errorChecking
Bypass error checking. |
protected java.util.Hashtable |
identifiers
Identifiers. |
protected static int[] |
kidOK
Table for quick check of child insertion. |
protected boolean |
standalone
Experimental DOM Level 3 feature: Document standalone |
protected java.lang.String |
version
Experimental DOM Level 3 feature: Document version |
Fields inherited from class org.apache.xerces.dom.ParentNode |
---|
fCachedChild, fCachedChildIndex, fCachedLength, firstChild, ownerDocument |
Fields inherited from class org.apache.xerces.dom.ChildNode |
---|
nextSibling, previousSibling |
Fields inherited from class org.apache.xerces.dom.NodeImpl |
---|
ELEMENT_DEFINITION_NODE, FIRSTCHILD, flags, HASSTRING, IGNORABLEWS, OWNED, ownerNode, READONLY, SPECIFIED, SYNCCHILDREN, SYNCDATA, UNNORMALIZED |
Fields inherited from interface org.w3c.dom.Node |
---|
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE |
Constructor Summary | |
---|---|
CoreDocumentImpl()
NON-DOM: Actually creating a Document is outside the DOM's spec, since it has to operate in terms of a particular implementation. |
|
CoreDocumentImpl(boolean grammarAccess)
Constructor. |
|
CoreDocumentImpl(DocumentType doctype)
For DOM2 support. |
|
CoreDocumentImpl(DocumentType doctype,
boolean grammarAccess)
For DOM2 support. |
Method Summary | |
---|---|
protected void |
addEventListener(NodeImpl node,
java.lang.String type,
EventListener listener,
boolean useCapture)
|
Node |
adoptNode(Node source)
DOM Level 3 WD - Experimental Change the node's ownerDocument, and its subtree, to this Document |
protected void |
changed()
Denotes that this node has changed. |
protected int |
changes()
Returns the number of changes to this node. |
java.lang.Object |
clone()
Clone. |
Node |
cloneNode(boolean deep)
Deep-clone a document, including fixing ownerDoc for the cloned children. |
protected void |
cloneNode(CoreDocumentImpl newdoc,
boolean deep)
internal method to share code with subclass |
Attr |
createAttribute(java.lang.String name)
Factory method; creates an Attribute having this Document as its OwnerDoc. |
Attr |
createAttributeNS(java.lang.String namespaceURI,
java.lang.String qualifiedName)
Introduced in DOM Level 2. |
CDATASection |
createCDATASection(java.lang.String data)
Factory method; creates a CDATASection having this Document as its OwnerDoc. |
Comment |
createComment(java.lang.String data)
Factory method; creates a Comment having this Document as its OwnerDoc. |
DocumentFragment |
createDocumentFragment()
Factory method; creates a DocumentFragment having this Document as its OwnerDoc. |
DocumentType |
createDocumentType(java.lang.String qualifiedName,
java.lang.String publicID,
java.lang.String systemID)
NON-DOM Factory method; creates a DocumentType having this Document as its OwnerDoc. |
Element |
createElement(java.lang.String tagName)
Factory method; creates an Element having this Document as its OwnerDoc. |
ElementDefinitionImpl |
createElementDefinition(java.lang.String name)
NON-DOM Factory method: creates an element definition. |
Element |
createElementNS(java.lang.String namespaceURI,
java.lang.String qualifiedName)
Introduced in DOM Level 2. |
Entity |
createEntity(java.lang.String name)
NON-DOM Factory method; creates an Entity having this Document as its OwnerDoc. |
EntityReference |
createEntityReference(java.lang.String name)
Factory method; creates an EntityReference having this Document as its OwnerDoc. |
Notation |
createNotation(java.lang.String name)
NON-DOM Factory method; creates a Notation having this Document as its OwnerDoc. |
ProcessingInstruction |
createProcessingInstruction(java.lang.String target,
java.lang.String data)
Factory method; creates a ProcessingInstruction having this Document as its OwnerDoc. |
Text |
createTextNode(java.lang.String data)
Factory method; creates a Text node having this Document as its OwnerDoc. |
protected boolean |
dispatchEvent(NodeImpl node,
Event event)
|
DocumentType |
getDoctype()
For XML, this provides access to the Document Type Definition. |
Element |
getDocumentElement()
Convenience method, allowing direct access to the child node which is considered the root of the actual document content. |
Element |
getElementById(java.lang.String elementId)
Introduced in DOM Level 2 Returns the Element whose ID is given by elementId. |
NodeList |
getElementsByTagName(java.lang.String tagname)
Return a live collection of all descendent Elements (not just immediate children) having the specified tag name. |
NodeList |
getElementsByTagNameNS(java.lang.String namespaceURI,
java.lang.String localName)
Introduced in DOM Level 2. |
java.lang.String |
getEncoding()
DOM Level 3 WD - Experimental. |
boolean |
getErrorChecking()
Returns true if the DOM implementation performs error checking. |
Element |
getIdentifier(java.lang.String idName)
Returns a previously registered element with the specified identifier name, or null if no element is registered. |
java.util.Enumeration |
getIdentifiers()
Returns an enumeration registered of identifier names. |
DOMImplementation |
getImplementation()
Retrieve information describing the abilities of this particular DOM implementation. |
java.lang.String |
getNodeName()
Returns the node name. |
short |
getNodeType()
Returns the node type. |
Document |
getOwnerDocument()
The Document object associated with this node. |
boolean |
getStandalone()
DOM Level 3 WD - Experimental. |
boolean |
getStrictErrorChecking()
EXPERIMENTAL! Based on the Document Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.. |
protected java.lang.Object |
getUserData(NodeImpl n)
Retreive user data related to a given node |
java.lang.String |
getVersion()
DOM Level 3 WD - Experimental. |
Node |
importNode(Node source,
boolean deep)
Copies a node from another document to this document. |
Node |
insertBefore(Node newChild,
Node refChild)
Since a Document may contain at most one top-level Element child, and at most one DocumentType declaraction, we need to subclass our add-children methods to implement this constraint. |
protected boolean |
isKidOK(Node parent,
Node child)
Uses the kidOK lookup table to check whether the proposed tree structure is legal. |
static boolean |
isXMLName(java.lang.String s)
Check the string against XML's definition of acceptable names for elements and attributes and so on using the XMLCharacterProperties utility class |
void |
putIdentifier(java.lang.String idName,
Element element)
Registers an identifier name with a specified element node. |
Node |
removeChild(Node oldChild)
Since insertBefore caches the docElement (and, currently, docType), removeChild has to know how to undo the cache REVISIT: According to the spec it is not allowed to alter neither the document element nor the document type in any way |
protected void |
removeEventListener(NodeImpl node,
java.lang.String type,
EventListener listener,
boolean useCapture)
|
void |
removeIdentifier(java.lang.String idName)
Removes a previously registered element with the specified identifier name. |
Node |
replaceChild(Node newChild,
Node oldChild)
Since we cache the docElement (and, currently, docType), replaceChild has to update the cache REVISIT: According to the spec it is not allowed to alter neither the document element nor the document type in any way |
void |
setEncoding(java.lang.String value)
DOM Level 3 WD - Experimental. |
void |
setErrorChecking(boolean check)
Sets whether the DOM implementation performs error checking upon operations. |
void |
setStandalone(boolean value)
DOM Level 3 WD - Experimental. |
void |
setStrictErrorChecking(boolean check)
EXPERIMENTAL! Based on the Document Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.. |
protected void |
setUserData(NodeImpl n,
java.lang.Object data)
Store user data related to a given node This is a place where we could use weak references! Indeed, the node here won't be GC'ed as long as some user data is attached to it, since the userData table will have a reference to the node. |
void |
setVersion(java.lang.String value)
DOM Level 3 WD - Experimental. |
Methods inherited from class org.apache.xerces.dom.ParentNode |
---|
getChildNodes, getChildNodesUnoptimized, getFirstChild, getLastChild, getLength, hasChildNodes, item, normalize, setReadOnly, synchronizeChildren |
Methods inherited from class org.apache.xerces.dom.ChildNode |
---|
getNextSibling, getParentNode, getPreviousSibling |
Methods inherited from class org.apache.xerces.dom.NodeImpl |
---|
addEventListener, appendChild, dispatchEvent, getAttributes, getLocalName, getNamespaceURI, getNodeValue, getPrefix, getReadOnly, getUserData, hasAttributes, isSupported, removeEventListener, setNodeValue, setPrefix, setUserData, synchronizeData, toString |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.w3c.dom.Node |
---|
appendChild, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, isSupported, normalize, setNodeValue, setPrefix |
Field Detail |
protected DocumentTypeImpl docType
protected ElementImpl docElement
protected java.lang.String encoding
protected java.lang.String version
protected boolean standalone
protected java.util.Hashtable identifiers
protected static int[] kidOK
protected int changes
Any method that alters the tree structure MUST cause or be accompanied by a call to changed(), to inform it that any outstanding NodeLists may have to be updated.
(Required because NodeList is simultaneously "live" and integer- indexed -- a bad decision in the DOM's design.)
Note that changes which do not affect the tree's structure -- changing the node's name, for example -- do _not_ have to call changed().
Alternative implementation would be to use a cryptographic Digest value rather than a count. This would have the advantage that "harmless" changes (those producing equal() trees) would not force NodeList to resynchronize. Disadvantage is that it's slightly more prone to "false negatives", though that's the difference between "wildly unlikely" and "absurdly unlikely". IF we start maintaining digests, we should consider taking advantage of them. Note: This used to be done a node basis, so that we knew what subtree changed. But since only DeepNodeList really use this today, the gain appears to be really small compared to the cost of having an int on every (parent) node plus having to walk up the tree all the way to the root to mark the branch as changed everytime a node is changed. So we now have a single counter global to the document. It means that some objects may flush their cache more often than necessary, but this makes nodes smaller and only the document needs to be marked as changed.
protected boolean allowGrammarAccess
protected boolean errorChecking
Constructor Detail |
public CoreDocumentImpl()
public CoreDocumentImpl(boolean grammarAccess)
public CoreDocumentImpl(DocumentType doctype)
public CoreDocumentImpl(DocumentType doctype, boolean grammarAccess)
Method Detail |
public final Document getOwnerDocument()
Node
Document
object associated with this node. This is
also the Document
object used to create new nodes. When
this node is a Document
or a DocumentType
which is not used with any Document
yet, this is
null
.getOwnerDocument
in interface Node
getOwnerDocument
in class ParentNode
public short getNodeType()
getNodeType
in interface Node
getNodeType
in class NodeImpl
public java.lang.String getNodeName()
getNodeName
in interface Node
getNodeName
in class NodeImpl
public Node cloneNode(boolean deep)
cloneNode
in interface Node
cloneNode
in class ParentNode
deep
- boolean, iff true replicate childrenprotected void cloneNode(CoreDocumentImpl newdoc, boolean deep)
public Node insertBefore(Node newChild, Node refChild) throws DOMException
While I'm doing so, I've taken advantage of the opportunity to cache documentElement and docType so we don't have to search for them. REVISIT: According to the spec it is not allowed to alter neither the document element nor the document type in any way
insertBefore
in interface Node
insertBefore
in class ParentNode
org.w3c.dom.Node
newChildThe
- node to insert.refChildThe
- reference node, i.e., the node before which the new
node must be inserted.DOMException
- HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
allow children of the type of the newChild
node, or if
the node to insert is one of this node's ancestors.
newChild
was created
from a different document than the one that created this node.
refChild
is not a child of
this node.public Node removeChild(Node oldChild) throws DOMException
removeChild
in interface Node
removeChild
in class ParentNode
org.w3c.dom.Node
oldChildThe
- node being removed.DOMException
- NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
oldChild
is not a child of
this node.public Node replaceChild(Node newChild, Node oldChild) throws DOMException
replaceChild
in interface Node
replaceChild
in class ParentNode
org.w3c.dom.Node
newChildThe
- new node to put in the child list.oldChildThe
- node being replaced in the list.DOMException
- HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
allow children of the type of the newChild
node, or if
the node to put in is one of this node's ancestors.
newChild
was created
from a different document than the one that created this node.
oldChild
is not a child of
this node.public Attr createAttribute(java.lang.String name) throws DOMException
createAttribute
in interface Document
name
- The name of the attribute. Note that the attribute's value
is _not_ established at the factory; remember to set it!DOMException(INVALID_NAME_ERR)
- if the attribute name is not
acceptable.public CDATASection createCDATASection(java.lang.String data) throws DOMException
createCDATASection
in interface Document
data
- The initial contents of the CDATADOMException(NOT_SUPPORTED_ERR)
- for HTML documents. (HTML
not yet implemented.)public Comment createComment(java.lang.String data)
createComment
in interface Document
data
- The initial contents of the Comment.public DocumentFragment createDocumentFragment()
createDocumentFragment
in interface Document
org.w3c.dom.Document
DocumentFragment
.public Element createElement(java.lang.String tagName) throws DOMException
createElement
in interface Document
tagName
- The name of the element type to instantiate. For
XML, this is case-sensitive. For HTML, the tagName parameter may
be provided in any case, but it must be mapped to the canonical
uppercase form by the DOM implementation.DOMException(INVALID_NAME_ERR)
- if the tag name is not
acceptable.public EntityReference createEntityReference(java.lang.String name) throws DOMException
createEntityReference
in interface Document
name
- The name of the Entity we wish to refer toDOMException(NOT_SUPPORTED_ERR)
- for HTML documents, where
nonstandard entities are not permitted. (HTML not yet
implemented.)public ProcessingInstruction createProcessingInstruction(java.lang.String target, java.lang.String data) throws DOMException
createProcessingInstruction
in interface Document
target
- The target "processor channel"data
- Parameter string to be passed to the target.DOMException(INVALID_NAME_ERR)
- if the target name is not
acceptable.DOMException(NOT_SUPPORTED_ERR)
- for HTML documents. (HTML
not yet implemented.)public Text createTextNode(java.lang.String data)
createTextNode
in interface Document
data
- The initial contents of the Text.public DocumentType getDoctype()
getDoctype
in interface Document
public java.lang.String getEncoding()
getEncoding
in interface Document
public java.lang.String getVersion()
getVersion
in interface Document
public boolean getStandalone()
getStandalone
in interface Document
public Element getDocumentElement()
getDocumentElement
in interface Document
public NodeList getElementsByTagName(java.lang.String tagname)
getElementsByTagName
in interface Document
tagname
- The type of Element we want to gather. "*" will be
taken as a wildcard, meaning "all elements in the document."DeepNodeListImpl
public DOMImplementation getImplementation()
getImplementation
in interface Document
public void setErrorChecking(boolean check)
Turning off error checking does not turn off the following checks:
public void setStrictErrorChecking(boolean check)
Document
EXPERIMENTAL! Based on the Document Object Model (DOM) Level 3 Core Working Draft of 5 June 2001..
An attribute specifying whether errors checking is enforced or not.
When set to false
, the implementation is free to not
test every possible error case normally defined on DOM operations,
and not raise any DOMException
. In case of error, the
behavior is undefined. This attribute is true
by
defaults.
setStrictErrorChecking
in interface Document
public void setEncoding(java.lang.String value)
setEncoding
in interface Document
public void setVersion(java.lang.String value)
setVersion
in interface Document
public void setStandalone(boolean value)
setStandalone
in interface Document
public boolean getErrorChecking()
public boolean getStrictErrorChecking()
Document
EXPERIMENTAL! Based on the Document Object Model (DOM) Level 3 Core Working Draft of 5 June 2001..
An attribute specifying whether errors checking is enforced or not.
When set to false
, the implementation is free to not
test every possible error case normally defined on DOM operations,
and not raise any DOMException
. In case of error, the
behavior is undefined. This attribute is true
by
defaults.
getStrictErrorChecking
in interface Document
public DocumentType createDocumentType(java.lang.String qualifiedName, java.lang.String publicID, java.lang.String systemID) throws DOMException
name
- The name of the Entity we wish to provide a value for.DOMException(NOT_SUPPORTED_ERR)
- for HTML documents, where
DTDs are not permitted. (HTML not yet implemented.)public Entity createEntity(java.lang.String name) throws DOMException
name
- The name of the Entity we wish to provide a value for.DOMException(NOT_SUPPORTED_ERR)
- for HTML documents, where
nonstandard entities are not permitted. (HTML not yet
implemented.)public Notation createNotation(java.lang.String name) throws DOMException
name
- The name of the Notation we wish to describeDOMException(NOT_SUPPORTED_ERR)
- for HTML documents, where
notations are not permitted. (HTML not yet
implemented.)public ElementDefinitionImpl createElementDefinition(java.lang.String name) throws DOMException
public Node importNode(Node source, boolean deep) throws DOMException
According to the DOM specifications, document nodes cannot be imported and a NOT_SUPPORTED_ERR exception is thrown if attempted.
importNode
in interface Document
org.w3c.dom.Document
importedNodeThe
- node to import.deepIf
- true
, recursively import the subtree under
the specified node; if false
, import only the node
itself, as explained above. This has no effect on Attr
, EntityReference
, and Notation
nodes.Document
.DOMException
- NOT_SUPPORTED_ERR: Raised if the type of node being imported is not
supported.public Node adoptNode(Node source)
adoptNode
in interface Document
source
- The node to adopt.DocumentImpl.importNode
public Element getElementById(java.lang.String elementId)
Note: The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null.
getElementById
in interface Document
getIdentifier(java.lang.String)
public void putIdentifier(java.lang.String idName, Element element)
getIdentifier(java.lang.String)
,
removeIdentifier(java.lang.String)
public Element getIdentifier(java.lang.String idName)
putIdentifier(java.lang.String, org.w3c.dom.Element)
,
removeIdentifier(java.lang.String)
public void removeIdentifier(java.lang.String idName)
putIdentifier(java.lang.String, org.w3c.dom.Element)
,
getIdentifier(java.lang.String)
public java.util.Enumeration getIdentifiers()
public Element createElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName) throws DOMException
Creates an element of the given qualified name and namespace URI. If the given namespaceURI is null or an empty string and the qualifiedName has a prefix that is "xml", the created element is bound to the predefined namespace "http://www.w3.org/XML/1998/namespace" [Namespaces].
createElementNS
in interface Document
namespaceURI
- The namespace URI of the element to
create.qualifiedName
- The qualified name of the element type to
instantiate.DOMException
- INVALID_CHARACTER_ERR: Raised if the specified
name contains an invalid character.DOMException
- NAMESPACE_ERR: Raised if the qualifiedName has a
prefix that is "xml" and the namespaceURI is
neither null nor an empty string nor
"http://www.w3.org/XML/1998/namespace", or
if the qualifiedName has a prefix different
from "xml" and the namespaceURI is null or an
empty string.public Attr createAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName) throws DOMException
Creates an attribute of the given qualified name and namespace URI. If the given namespaceURI is null or an empty string and the qualifiedName has a prefix that is "xml", the created element is bound to the predefined namespace "http://www.w3.org/XML/1998/namespace" [Namespaces].
createAttributeNS
in interface Document
namespaceURI
- The namespace URI of the attribute to
create. When it is null or an empty string,
this method behaves like createAttribute.qualifiedName
- The qualified name of the attribute to
instantiate.DOMException
- INVALID_CHARACTER_ERR: Raised if the specified
name contains an invalid character.public NodeList getElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
Returns a NodeList of all the Elements with a given local name and namespace URI in the order in which they would be encountered in a preorder traversal of the Document tree.
getElementsByTagNameNS
in interface Document
namespaceURI
- The namespace URI of the elements to match
on. The special value "*" matches all
namespaces. When it is null or an empty
string, this method behaves like
getElementsByTagName.localName
- The local name of the elements to match on.
The special value "*" matches all local names.public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
public static boolean isXMLName(java.lang.String s)
protected boolean isKidOK(Node parent, Node child)
protected void changed()
changed
in class NodeImpl
protected int changes()
changes
in class NodeImpl
protected void setUserData(NodeImpl n, java.lang.Object data)
protected java.lang.Object getUserData(NodeImpl n)
protected void addEventListener(NodeImpl node, java.lang.String type, EventListener listener, boolean useCapture)
protected void removeEventListener(NodeImpl node, java.lang.String type, EventListener listener, boolean useCapture)
protected boolean dispatchEvent(NodeImpl node, Event event)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |