Class DOM2DTM
- All Implemented Interfaces:
DTM
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 to that we do not currently attempt to track document mutation. If you alter the DOM after wrapping DOM2DTM around it, all bets are off.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.loboevolution.apache.xml.dtm.ref.DTMDefaultBaseIterators
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
-
Field Summary
Fields inherited from class org.loboevolution.apache.xml.dtm.ref.DTMDefaultBase
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, ROOTNODE
Fields inherited from interface org.loboevolution.apache.xml.dtm.DTM
ATTRIBUTE_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 Summary
ConstructorDescriptionDOM2DTM
(DTMManager mgr, DOMSource domSource, int dtmIdentity, boolean doIndexing) Construct a DOM2DTM object from a DOM node. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Construct the node map from the node.int
getAttributeNode
(int nodeHandle, String nsURI, String name) Retrieves an attribute node by local name and namespace URIint
getElementById
(String elementId) Returns theElement
whoseID
is given byelementId
.int
getHandleOfNode
(Node node) Get the handle from a Node.getLocalName
(int nodeHandle) Given a node handle, return its DOM-style localname.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.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.getNodeName
(int nodeHandle) Given a node handle, return its DOM-style node name.getNodeNameX
(int nodeHandle) Given a node handle, return the XPath node name.getNodeValue
(int nodeHandle) Given a node handle, return its node value.getPrefix
(int nodeHandle) Given a namespace handle, return the prefix that the namespace decl is mapping.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.Methods inherited from class org.loboevolution.apache.xml.dtm.ref.DTMDefaultBaseIterators
getAxisIterator
Methods inherited from class org.loboevolution.apache.xml.dtm.ref.DTMDefaultBaseTraversers
getAxisTraverser
Methods inherited from class org.loboevolution.apache.xml.dtm.ref.DTMDefaultBase
_exptype, _firstch, _level, _nextsib, _parent, _prevsib, _type, declareNamespaceInContext, dumpNode, ensureSizeOfIndex, error, findGTE, findInSortedSuballocatedIntVector, findNamespaceContext, getDocument, getDocumentRoot, getExpandedTypeID, getExpandedTypeID, getFirstAttribute, getFirstAttributeIdentity, getFirstChild, getFirstNamespaceNode, getLastChild, getManager, getNextAttribute, getNextAttributeIdentity, getNextNamespaceNode, getNextSibling, getNodeType, getOwnerDocument, getParent, getPreviousSibling, indexNode, isNodeAfter, makeNodeHandle, makeNodeIdentity
-
Field Details
-
m_nodes
The node objects. The instance part of the handle indexes directly into this vector. Each DTM node may actually be composed of several DOM nodes (for example, if logically-adjacent Text/CDATASection nodes in the DOM have been coalesced into a single DTM Text node); this table points only to the first in that sequence.
-
-
Constructor Details
-
DOM2DTM
Construct a DOM2DTM object from a DOM node.- Parameters:
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.
-
-
Method Details
-
addNode
Construct the node map from the node.- Parameters:
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).- Returns:
- The index identity of the node that was added.
-
nextNode
protected boolean nextNode()This method should try and build one or more nodes in the table.- Specified by:
nextNode
in classDTMDefaultBase
- Returns:
- The true if a next node is found or false if there are no more nodes.
-
getNode
Return an DOM node for the given node.- Specified by:
getNode
in interfaceDTM
- Overrides:
getNode
in classDTMDefaultBase
- Parameters:
nodeHandle
- The node ID.- Returns:
- A node representation of the DTM node.
-
lookupNode
Get a Node from an identity index.NEEDSDOC @param nodeIdentity
NEEDSDOC ($objectName$) @return
-
getNextNodeIdentity
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.- Specified by:
getNextNodeIdentity
in classDTMDefaultBase
- Parameters:
identity
- The node identity (index).- Returns:
- identity+1, or DTM.NULL.
-
getHandleOfNode
Get the handle from a Node. This is a more robust version of getHandleFromNode, intended to be usable by the public.%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.
- Parameters:
node
- A node, which may be null.- Returns:
- The node handle or
DTM.NULL
.
-
getAttributeNode
Retrieves an attribute node by local name and namespace URI%TBD% Note that we currently have no way to support the DOM's old getAttribute() call, which accesses only the qname.
- Specified by:
getAttributeNode
in interfaceDTM
- Specified by:
getAttributeNode
in classDTMDefaultBase
- Parameters:
nodeHandle
- Handle of the node upon which to look up this attribute.nsURI
- The namespace URI of the attribute to retrieve, or null.name
- The local name of the attribute to retrieve.- Returns:
- The attribute node handle with the specified name (
nodeName
) orDTM.NULL
if there is no such attribute.
-
getStringValue
Get the string-value of a node as a String object (see ... for the definition of a node's string-value).- Specified by:
getStringValue
in interfaceDTM
- Specified by:
getStringValue
in classDTMDefaultBase
- Parameters:
nodeHandle
- The node ID.- Returns:
- A string object that represents the string-value of the given node.
-
getNodeData
Retrieve the text content of a DOM subtree, appending it into a user-supplied FastStringBuffer object. Note that attributes are not considered part of the content of an element.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.
- Parameters:
node
- Node whose subtree is to be walked, gathering the contents of all Text or CDATASection nodes.buf
- FastStringBuffer into which the contents of the text nodes are to be concatenated.
-
getNodeName
Given a node handle, return its DOM-style node name. This will include names such as #text or #document.- Specified by:
getNodeName
in interfaceDTM
- Specified by:
getNodeName
in classDTMDefaultBase
- Parameters:
nodeHandle
- the id of the node.- Returns:
- String Name of this node, which may be an empty string. %REVIEW% Document when empty string is possible...
-
getNodeNameX
Given a node handle, return the XPath node name. This should be the name as described by the XPath data model, NOT the DOM-style name.- Specified by:
getNodeNameX
in interfaceDTM
- Overrides:
getNodeNameX
in classDTMDefaultBase
- Parameters:
nodeHandle
- the id of the node.- Returns:
- String Name of this node.
-
getLocalName
Given a node handle, return its DOM-style localname. (As defined in Namespaces, this is the portion of the name after the prefix, if present, or the whole node name if no prefix exists)- Specified by:
getLocalName
in interfaceDTM
- Specified by:
getLocalName
in classDTMDefaultBase
- Parameters:
nodeHandle
- the id of the node.- Returns:
- String Local name of this node.
-
getPrefix
Given a namespace handle, return the prefix that the namespace decl is mapping. Given a node handle, return the prefix used to map to the namespace. (As defined in Namespaces, this is the portion of the name before any colon character).%REVIEW% Are you sure you want "" for no prefix?
- Specified by:
getPrefix
in interfaceDTM
- Specified by:
getPrefix
in classDTMDefaultBase
- Parameters:
nodeHandle
- the id of the node.- Returns:
- String prefix of this node's name, or "" if no explicit namespace prefix was given.
-
getNamespaceURI
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.)- Specified by:
getNamespaceURI
in interfaceDTM
- Specified by:
getNamespaceURI
in classDTMDefaultBase
- Parameters:
nodeHandle
- the id of the node.- Returns:
- String URI value of this node's namespace, or null if no namespace was resolved.
-
getNodeValue
Given a node handle, return its node value. This is mostly as defined by the DOM, but may ignore some conveniences.- Specified by:
getNodeValue
in interfaceDTM
- Specified by:
getNodeValue
in classDTMDefaultBase
- Parameters:
nodeHandle
- The node id.- Returns:
- String Value of this node, or null if not meaningful for this node type.
-
getElementById
Returns theElement
whoseID
is given byelementId
. If no such element exists, returnsDTM.NULL
. Behavior is not defined if more than one element has thisID
. 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 returnDTM.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.
- Specified by:
getElementById
in interfaceDTM
- Specified by:
getElementById
in classDTMDefaultBase
- Parameters:
elementId
- The uniqueid
value for an element.- Returns:
- The handle of the matching element.
-