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 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.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.xml.dtm.ref.DTMDefaultBaseIterators
DTMDefaultBaseIterators.AncestorIterator, DTMDefaultBaseIterators.AttributeIterator, DTMDefaultBaseIterators.ChildrenIterator, DTMDefaultBaseIterators.DescendantIterator, DTMDefaultBaseIterators.FollowingIterator, DTMDefaultBaseIterators.FollowingSiblingIterator, DTMDefaultBaseIterators.InternalAxisIteratorBase, DTMDefaultBaseIterators.NamespaceAttributeIterator, DTMDefaultBaseIterators.NamespaceChildrenIterator, DTMDefaultBaseIterators.NamespaceIterator, DTMDefaultBaseIterators.NthDescendantIterator, DTMDefaultBaseIterators.ParentIterator, DTMDefaultBaseIterators.PrecedingIterator, DTMDefaultBaseIterators.PrecedingSiblingIterator, DTMDefaultBaseIterators.RootIterator, DTMDefaultBaseIterators.SingletonIterator, DTMDefaultBaseIterators.TypedAncestorIterator, DTMDefaultBaseIterators.TypedAttributeIterator, DTMDefaultBaseIterators.TypedChildrenIterator, DTMDefaultBaseIterators.TypedDescendantIterator, DTMDefaultBaseIterators.TypedFollowingIterator, DTMDefaultBaseIterators.TypedFollowingSiblingIterator, DTMDefaultBaseIterators.TypedNamespaceIterator, DTMDefaultBaseIterators.TypedPrecedingIterator, DTMDefaultBaseIterators.TypedPrecedingSiblingIterator, DTMDefaultBaseIterators.TypedRootIterator, DTMDefaultBaseIterators.TypedSingletonIterator
-
Field Summary
Fields inherited from class org.apache.xml.dtm.ref.DTMDefaultBase
DEFAULT_BLOCKSIZE, DEFAULT_NUMBLOCKS, DEFAULT_NUMBLOCKS_SMALL, m_mgr, ROOTNODE
Fields inherited from interface org.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, ROOT_NODE, TEXT_NODE
-
Constructor Summary
ConstructorsConstructorDescriptionDOM2DTM
(DTMManager mgr, DOMSource domSource, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing) Construct a DOM2DTM object from a DOM node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispatchCharactersEvents
(int nodeHandle, ContentHandler ch, boolean normalize) Directly call the characters method on the passed ContentHandler for the string-value of the given node (see http://www.w3.org/TR/xpath#data-model for the definition of a node's string-value).void
dispatchToEvents
(int nodeHandle, ContentHandler ch) Directly create SAX parser events from a subtree.int
getAttributeNode
(int nodeHandle, String namespaceURI, String name) Retrieves an attribute node by by qualified name and namespace URI.getContentHandler returns "our SAX builder" -- the thing that someone else should send SAX events to in order to extend this DTM model.Return this DTM's DeclHandler.Return the public identifier of the external subset, normalized as described in 4.2.2 External Entities [XML].A document type declaration information item has the following properties: 1.Return this DTM's DTDHandler.int
getElementById
(String elementId) Returns theElement
whoseID
is given byelementId
.Return this DTM's EntityResolver.Return this DTM's ErrorHandler.int
getHandleOfNode
(Node node) Get the handle from a Node.Return this DTM's lexical handler.getLocalName
(int nodeHandle) Given a node handle, return its XPath-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.)getNode
(int nodeHandle) Return an DOM node for the given node.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.int
Get the number of nodes that have been added.getPrefix
(int nodeHandle) Given a namespace handle, return the prefix that the namespace decl is mapping.getSourceLocatorFor
(int node) No source information is available for DOM2DTM, so returnnull
here.getStringValue
(int nodeHandle) Get the string-value of a node as a String object (see http://www.w3.org/TR/xpath#data-model for the definition of a node's string-value).getUnparsedEntityURI
(String name) The getUnparsedEntityURI function returns the URI of the unparsed entity with the specified name in the same document as the context node (see [3.3 Unparsed Entities]).boolean
isAttributeSpecified
(int attributeHandle) 5.boolean
isWhitespace
(int nodeHandle) Determine if the string-value of a node is whitespaceboolean
void
Bind an IncrementalSAXSource to this DTM.void
setProperty
(String property, Object value) For the moment all the run time properties are ignored by this class.Methods inherited from class org.apache.xml.dtm.ref.DTMDefaultBaseIterators
getAxisIterator, getTypedAxisIterator
Methods inherited from class org.apache.xml.dtm.ref.DTMDefaultBaseTraversers
getAxisTraverser
Methods inherited from class org.apache.xml.dtm.ref.DTMDefaultBase
appendChild, appendTextChild, documentRegistration, documentRelease, dumpDTM, dumpNode, getDocument, getDocumentAllDeclarationsProcessed, getDocumentBaseURI, getDocumentEncoding, getDocumentRoot, getDocumentStandalone, getDocumentSystemIdentifier, getDocumentVersion, getDTMIDs, getExpandedTypeID, getExpandedTypeID, getFirstAttribute, getFirstChild, getFirstNamespaceNode, getLastChild, getLevel, getLocalNameFromExpandedNameID, getManager, getNamespaceFromExpandedNameID, getNamespaceType, getNextAttribute, getNextNamespaceNode, getNextSibling, getNodeHandle, getNodeIdent, getNodeType, getOwnerDocument, getParent, getPreviousSibling, getStringValueChunk, getStringValueChunkCount, getTypedFirstChild, getTypedNextSibling, hasChildNodes, isCharacterElementContentWhitespace, isDocumentAllDeclarationsProcessed, isNodeAfter, isSupported, makeNodeHandle, makeNodeIdentity, migrateTo, setDocumentBaseURI, setFeature, supportsPreStripping
-
Constructor Details
-
DOM2DTM
public DOM2DTM(DTMManager mgr, DOMSource domSource, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing) 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.whiteSpaceFilter
- The white space filter for this DTM, which may be null.xstringfactory
- XMLString factory for creating character content.doIndexing
- true if the caller considers it worth it to use indexing schemes.
-
-
Method Details
-
getNumberOfNodes
public int getNumberOfNodes()Get the number of nodes that have been added. -
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.
-
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 by qualified name and namespace URI.- Specified by:
getAttributeNode
in interfaceDTM
- Specified by:
getAttributeNode
in classDTMDefaultBase
- Parameters:
nodeHandle
- int 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.- 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 http://www.w3.org/TR/xpath#data-model 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.
-
isWhitespace
public boolean isWhitespace(int nodeHandle) Determine if the string-value of a node is whitespace- Parameters:
nodeHandle
- The node Handle.- Returns:
- Return true if the given node is whitespace.
-
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... %REVIEW-COMMENT% It should never be empty, should it?
-
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, which may be an empty string.
-
getLocalName
Given a node handle, return its XPath-style localname. (As defined in Namespaces, this is the portion of the name after any colon character).- 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.%REVIEW% Are you sure you want "" for no prefix?
%REVIEW-COMMENT% I think so... not totally sure. -sb
- 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.)%REVIEW% Null or ""? -sb
- 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.
-
getDocumentTypeDeclarationSystemIdentifier
A document type declaration information item has the following properties: 1. [system identifier] The system identifier of the external subset, if it exists. Otherwise this property has no value.- Specified by:
getDocumentTypeDeclarationSystemIdentifier
in interfaceDTM
- Specified by:
getDocumentTypeDeclarationSystemIdentifier
in classDTMDefaultBase
- Returns:
- the system identifier String object, or null if there is none.
-
getDocumentTypeDeclarationPublicIdentifier
Return the public identifier of the external subset, normalized as described in 4.2.2 External Entities [XML]. If there is no external subset or if it has no public identifier, this property has no value.- Specified by:
getDocumentTypeDeclarationPublicIdentifier
in interfaceDTM
- Specified by:
getDocumentTypeDeclarationPublicIdentifier
in classDTMDefaultBase
- Returns:
- the public identifier String object, or null if there is none.
-
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.
-
getUnparsedEntityURI
The getUnparsedEntityURI function returns the URI of the unparsed entity with the specified name in the same document as the context node (see [3.3 Unparsed Entities]). It returns the empty string if there is no such entity.XML processors may choose to use the System Identifier (if one is provided) to resolve the entity, rather than the URI in the Public Identifier. The details are dependent on the processor, and we would have to support some form of plug-in resolver to handle this properly. Currently, we simply return the System Identifier if present, and hope that it a usable URI or that our caller can map it to one. TODO: Resolve Public Identifiers... or consider changing function name.
If we find a relative URI reference, XML expects it to be resolved in terms of the base URI of the document. The DOM doesn't do that for us, and it isn't entirely clear whether that should be done here; currently that's pushed up to a higher level of our application. (Note that DOM Level 1 didn't store the document's base URI.) TODO: Consider resolving Relative URIs.
(The DOM's statement that "An XML processor may choose to completely expand entities before the structure model is passed to the DOM" refers only to parsed entities, not unparsed, and hence doesn't affect this function.)
- Specified by:
getUnparsedEntityURI
in interfaceDTM
- Specified by:
getUnparsedEntityURI
in classDTMDefaultBase
- Parameters:
name
- A string containing the Entity Name of the unparsed entity.- Returns:
- String containing the URI of the Unparsed Entity, or an empty string if no such entity exists.
-
isAttributeSpecified
public boolean isAttributeSpecified(int attributeHandle) 5. [specified] A flag indicating whether this attribute was actually specified in the start-tag of its element, or was defaulted from the DTD.- Specified by:
isAttributeSpecified
in interfaceDTM
- Specified by:
isAttributeSpecified
in classDTMDefaultBase
- Parameters:
attributeHandle
- the attribute handle- Returns:
true
if the attribute was specified;false
if it was defaulted.
-
setIncrementalSAXSource
Bind an IncrementalSAXSource to this DTM. NOT RELEVANT for DOM2DTM, since we're wrapped around an existing DOM.- Parameters:
source
- The IncrementalSAXSource that we want to recieve events from on demand.
-
getContentHandler
getContentHandler returns "our SAX builder" -- the thing that someone else should send SAX events to in order to extend this DTM model.- Returns:
- null if this model doesn't respond to SAX events, "this" if the DTM object has a built-in SAX ContentHandler, the IncrmentalSAXSource if we're bound to one and should receive the SAX stream via it for incremental build purposes...
-
getLexicalHandler
Return this DTM's lexical handler. %REVIEW% Should this return null if constrution already done/begun?- Returns:
- null if this model doesn't respond to lexical SAX events, "this" if the DTM object has a built-in SAX ContentHandler, the IncrementalSAXSource if we're bound to one and should receive the SAX stream via it for incremental build purposes...
-
getEntityResolver
Return this DTM's EntityResolver.- Returns:
- null if this model doesn't respond to SAX entity ref events.
-
getDTDHandler
Return this DTM's DTDHandler.- Returns:
- null if this model doesn't respond to SAX dtd events.
-
getErrorHandler
Return this DTM's ErrorHandler.- Returns:
- null if this model doesn't respond to SAX error events.
-
getDeclHandler
Return this DTM's DeclHandler.- Returns:
- null if this model doesn't respond to SAX Decl events.
-
needsTwoThreads
public boolean needsTwoThreads()- Returns:
- true iff we're building this model incrementally (eg we're partnered with a IncrementalSAXSource) and thus require that the transformation and the parse run simultaneously. Guidance to the DTMManager.
-
dispatchCharactersEvents
public void dispatchCharactersEvents(int nodeHandle, ContentHandler ch, boolean normalize) throws SAXException Directly call the characters method on the passed ContentHandler for the string-value of the given node (see http://www.w3.org/TR/xpath#data-model for the definition of a node's string-value). Multiple calls to the ContentHandler's characters methods may well occur for a single call to this method.- Specified by:
dispatchCharactersEvents
in interfaceDTM
- Specified by:
dispatchCharactersEvents
in classDTMDefaultBase
- Parameters:
nodeHandle
- The node ID.ch
- A non-null reference to a ContentHandler.normalize
- true if the content should be normalized according to the rules for the XPath normalize-space function.- Throws:
SAXException
-
dispatchToEvents
Directly create SAX parser events from a subtree.- Specified by:
dispatchToEvents
in interfaceDTM
- Specified by:
dispatchToEvents
in classDTMDefaultBase
- Parameters:
nodeHandle
- The node ID.ch
- A non-null reference to a ContentHandler.- Throws:
SAXException
-
setProperty
For the moment all the run time properties are ignored by this class.- Parameters:
property
- aString
valuevalue
- anObject
value
-
getSourceLocatorFor
No source information is available for DOM2DTM, so returnnull
here.- Parameters:
node
- anint
value- Returns:
- null
-