public class DOM2DTM extends DTMDefaultBaseIterators
DOM2DTM class serves up a DOM's contents via the DTM API.
Note that it doesn't necessarily represent a full Document tree. You can wrap a DOM2DTM around a specific node and its subtree and the right things should happen. (I don't _think_ we currently support DocumentFrgment nodes as roots, though that might be worth considering.)
Note too that we do not currently attempt to track document mutation. If you alter the DOM after wrapping DOM2DTM around it, all bets are off.
DTMDefaultBaseIterators.AncestorIterator, DTMDefaultBaseIterators.AttributeIterator, DTMDefaultBaseIterators.ChildrenIterator, DTMDefaultBaseIterators.DescendantIterator, DTMDefaultBaseIterators.FollowingIterator, DTMDefaultBaseIterators.FollowingSiblingIterator, DTMDefaultBaseIterators.InternalAxisIteratorBase, DTMDefaultBaseIterators.NamespaceIterator, DTMDefaultBaseIterators.ParentIterator, DTMDefaultBaseIterators.PrecedingIterator, DTMDefaultBaseIterators.PrecedingSiblingIterator, DTMDefaultBaseIterators.RootIterator, DTMDefaultBaseIterators.SingletonIterator| Modifier and Type | Field and Description |
|---|---|
protected Vector<Node> |
m_nodes
The node objects.
|
DEFAULT_BLOCKSIZE, DEFAULT_NUMBLOCKS, DEFAULT_NUMBLOCKS_SMALL, m_documentBaseURI, m_dtmIdent, m_elemIndexes, m_expandedNameTable, m_exptype, m_firstch, m_indexing, m_mgr, m_mgrDefault, m_namespaceDeclSetElements, m_namespaceDeclSets, m_nextsib, m_parent, m_prevsib, m_size, m_traversers, NOTPROCESSED, ROOTNODEATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NAMESPACE_NODE, NOTATION_NODE, NTYPES, NULL, PROCESSING_INSTRUCTION_NODE, TEXT_NODE| Constructor and Description |
|---|
DOM2DTM(DTMManager mgr,
DOMSource domSource,
int dtmIdentity,
boolean doIndexing)
Construct a DOM2DTM object from a DOM node.
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
addNode(Node node,
int parentIndex,
int previousSibling,
int forceNodeType)
Construct the node map from the node.
|
int |
getAttributeNode(int nodeHandle,
String namespaceURI,
String name)
Retrieves an attribute node by local name and namespace URI
|
int |
getElementById(String elementId)
Returns the
Element whose ID is given by elementId. |
int |
getHandleOfNode(Node node)
Get the handle from a Node.
|
String |
getLocalName(int nodeHandle)
Given a node handle, return its DOM-style localname.
|
String |
getNamespaceURI(int nodeHandle)
Given a node handle, return its DOM-style namespace URI (As defined in Namespaces, this is the
declared URI which this node's prefix -- or default in lieu thereof -- was mapped to.)
|
protected int |
getNextNodeIdentity(int identity)
Get the next node identity value in the list, and call the iterator if it hasn't been added
yet.
|
Node |
getNode(int nodeHandle)
Return an DOM node for the given node.
|
protected static void |
getNodeData(Node node,
StringBuilder buf)
Retrieve the text content of a DOM subtree, appending it into a user-supplied FastStringBuffer
object.
|
String |
getNodeName(int nodeHandle)
Given a node handle, return its DOM-style node name.
|
String |
getNodeNameX(int nodeHandle)
Given a node handle, return the XPath node name.
|
String |
getNodeValue(int nodeHandle)
Given a node handle, return its node value.
|
String |
getPrefix(int nodeHandle)
Given a namespace handle, return the prefix that the namespace decl is mapping.
|
XString |
getStringValue(int nodeHandle)
Get the string-value of a node as a String object (see ... for the definition of a node's
string-value).
|
protected Node |
lookupNode(int nodeIdentity)
Get a Node from an identity index.
|
protected boolean |
nextNode()
This method should try and build one or more nodes in the table.
|
getAxisIteratorgetAxisTraverser_exptype, _firstch, _level, _nextsib, _parent, _prevsib, _type, declareNamespaceInContext, dumpDTM, dumpNode, ensureSizeOfIndex, findGTE, findInSortedSuballocatedIntVector, findNamespaceContext, getDocument, getDocumentRoot, getExpandedTypeID, getExpandedTypeID, getFirstAttribute, getFirstAttributeIdentity, getFirstChild, getFirstNamespaceNode, getLastChild, getManager, getNextAttribute, getNextAttributeIdentity, getNextNamespaceNode, getNextSibling, getNodeType, getOwnerDocument, getParent, getPreviousSibling, indexNode, isNodeAfter, makeNodeHandle, makeNodeIdentityprotected final Vector<Node> m_nodes
public DOM2DTM(DTMManager mgr, DOMSource domSource, int dtmIdentity, boolean doIndexing)
mgr - The DTMManager who owns this DTM.domSource - the DOM source that this DTM will wrap.dtmIdentity - The DTM identity ID for this DTM.doIndexing - true if the caller considers it worth it to use indexing schemes.protected int addNode(Node node, int parentIndex, int previousSibling, int forceNodeType)
node - The node that is to be added to the DTM.parentIndex - The current parent index.previousSibling - The previous sibling index.forceNodeType - If not DTM.NULL, overrides the DOM node type. Used to force nodes to Text
rather than CDATASection when their coalesced value includes ordinary Text nodes (current
DTM behavior).protected boolean nextNode()
nextNode in class DTMDefaultBasepublic Node getNode(int nodeHandle)
getNode in interface DTMgetNode in class DTMDefaultBasenodeHandle - The node ID.protected Node lookupNode(int nodeIdentity)
NEEDSDOC @param nodeIdentity
NEEDSDOC ($objectName$) @return
protected int getNextNodeIdentity(int identity)
getNextNodeIdentity in class DTMDefaultBaseidentity - The node identity (index).public int getHandleOfNode(Node node)
%OPT% This will be pretty slow. %REVIEW% This relies on being able to test node-identity via object-identity. DTM2DOM proxying is a great example of a case where that doesn't work. DOM Level 3 will provide the isSameNode() method to fix that, but until then this is going to be flaky.
node - A node, which may be null.DTM.NULL.public int getAttributeNode(int nodeHandle,
String namespaceURI,
String name)
%TBD% Note that we currently have no way to support the DOM's old getAttribute() call, which accesses only the qname.
getAttributeNode in interface DTMgetAttributeNode in class DTMDefaultBasenodeHandle - Handle of the node upon which to look up this attribute.namespaceURI - The namespace URI of the attribute to retrieve, or null.name - The local name of the attribute to retrieve.nodeName) or
DTM.NULL if there is no such attribute.public XString getStringValue(int nodeHandle)
getStringValue in interface DTMgetStringValue in class DTMDefaultBasenodeHandle - The node ID.protected static void getNodeData(Node node, StringBuilder buf)
There are open questions regarding whitespace stripping. Currently we make no special effort in that regard, since the standard DOM doesn't yet provide DTD-based information to distinguish whitespace-in-element-context from genuine #PCDATA. Note that we should probably also consider xml:space if/when we address this. DOM Level 3 may solve the problem for us.
%REVIEW% Actually, since this method operates on the DOM side of the fence rather than the DTM side, it SHOULDN'T do any special handling. The DOM does what the DOM does; if you want DTM-level abstractions, use DTM-level methods.
node - Node whose subtree is to be walked, gathering the contents of all Text or
CDATASection nodes.buf - StringBuilder into which the contents of the text nodes are to be concatenated.public String getNodeName(int nodeHandle)
getNodeName in interface DTMgetNodeName in class DTMDefaultBasenodeHandle - the id of the node.public String getNodeNameX(int nodeHandle)
getNodeNameX in interface DTMgetNodeNameX in class DTMDefaultBasenodeHandle - the id of the node.public String getLocalName(int nodeHandle)
getLocalName in interface DTMgetLocalName in class DTMDefaultBasenodeHandle - the id of the node.public String getPrefix(int nodeHandle)
%REVIEW% Are you sure you want "" for no prefix?
getPrefix in interface DTMgetPrefix in class DTMDefaultBasenodeHandle - the id of the node.public String getNamespaceURI(int nodeHandle)
getNamespaceURI in interface DTMgetNamespaceURI in class DTMDefaultBasenodeHandle - the id of the node.public String getNodeValue(int nodeHandle)
getNodeValue in interface DTMgetNodeValue in class DTMDefaultBasenodeHandle - The node id.public int getElementById(String elementId)
Element whose ID is given by elementId. If
no such element exists, returns DTM.NULL. Behavior is not defined if more than one
element has this ID. Attributes (including those with the name "ID") are not of
type ID unless so defined by DTD/Schema information available to the DTM implementation.
Implementations that do not know whether attributes are of type ID or not are expected to
return DTM.NULL.
%REVIEW% Presumably IDs are still scoped to a single document, and this operation searches only within a single document, right? Wouldn't want collisions between DTMs in the same process.
getElementById in interface DTMgetElementById in class DTMDefaultBaseelementId - The unique id value for an element.Copyright © 2022–2024 HtmlUnit. All rights reserved.