1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: DTM.java,v 1.13 2004/02/16 23:03:44 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.dtm;
  20. import javax.xml.transform.SourceLocator;
  21. import com.sun.org.apache.xml.internal.utils.XMLString;
  22. /**
  23. * <code>DTM</code> is an XML document model expressed as a table
  24. * rather than an object tree. It attempts to provide an interface to
  25. * a parse tree that has very little object creation. (DTM
  26. * implementations may also support incremental construction of the
  27. * model, but that's hidden from the DTM API.)
  28. *
  29. * <p>Nodes in the DTM are identified by integer "handles". A handle must
  30. * be unique within a process, and carries both node identification and
  31. * document identification. It must be possible to compare two handles
  32. * (and thus their nodes) for identity with "==".</p>
  33. *
  34. * <p>Namespace URLs, local-names, and expanded-names can all be
  35. * represented by and tested as integer ID values. An expanded name
  36. * represents (and may or may not directly contain) a combination of
  37. * the URL ID, and the local-name ID. Note that the namespace URL id
  38. * can be 0, which should have the meaning that the namespace is null.
  39. * For consistancy, zero should not be used for a local-name index. </p>
  40. *
  41. * <p>Text content of a node is represented by an index and length,
  42. * permitting efficient storage such as a shared FastStringBuffer.</p>
  43. *
  44. * <p>The model of the tree, as well as the general navigation model,
  45. * is that of XPath 1.0, for the moment. The model will eventually be
  46. * adapted to match the XPath 2.0 data model, XML Schema, and
  47. * InfoSet.</p>
  48. *
  49. * <p>DTM does _not_ directly support the W3C's Document Object
  50. * Model. However, it attempts to come close enough that an
  51. * implementation of DTM can be created that wraps a DOM and vice
  52. * versa.</p>
  53. *
  54. * <p><strong>Please Note:</strong> The DTM API is still
  55. * <strong>Subject To Change.</strong> This wouldn't affect most
  56. * users, but might require updating some extensions.</p>
  57. *
  58. * <p> The largest change being contemplated is a reconsideration of
  59. * the Node Handle representation. We are still not entirely sure
  60. * that an integer packed with two numeric subfields is really the
  61. * best solution. It has been suggested that we move up to a Long, to
  62. * permit more nodes per document without having to reduce the number
  63. * of slots in the DTMManager. There's even been a proposal that we
  64. * replace these integers with "cursor" objects containing the
  65. * internal node id and a pointer to the actual DTM object; this might
  66. * reduce the need to continuously consult the DTMManager to retrieve
  67. * the latter, and might provide a useful "hook" back into normal Java
  68. * heap management. But changing this datatype would have huge impact
  69. * on Xalan's internals -- especially given Java's lack of C-style
  70. * typedefs -- so we won't cut over unless we're convinced the new
  71. * solution really would be an improvement!</p>
  72. * */
  73. public interface DTM
  74. {
  75. /**
  76. * Null node handles are represented by this value.
  77. */
  78. public static final int NULL = -1;
  79. // These nodeType mnemonics and values are deliberately the same as those
  80. // used by the DOM, for convenient mapping
  81. //
  82. // %REVIEW% Should we actually define these as initialized to,
  83. // eg. org.w3c.dom.Document.ELEMENT_NODE?
  84. /**
  85. * The node is a <code>Root</code>.
  86. */
  87. public static final short ROOT_NODE = 0;
  88. /**
  89. * The node is an <code>Element</code>.
  90. */
  91. public static final short ELEMENT_NODE = 1;
  92. /**
  93. * The node is an <code>Attr</code>.
  94. */
  95. public static final short ATTRIBUTE_NODE = 2;
  96. /**
  97. * The node is a <code>Text</code> node.
  98. */
  99. public static final short TEXT_NODE = 3;
  100. /**
  101. * The node is a <code>CDATASection</code>.
  102. */
  103. public static final short CDATA_SECTION_NODE = 4;
  104. /**
  105. * The node is an <code>EntityReference</code>.
  106. */
  107. public static final short ENTITY_REFERENCE_NODE = 5;
  108. /**
  109. * The node is an <code>Entity</code>.
  110. */
  111. public static final short ENTITY_NODE = 6;
  112. /**
  113. * The node is a <code>ProcessingInstruction</code>.
  114. */
  115. public static final short PROCESSING_INSTRUCTION_NODE = 7;
  116. /**
  117. * The node is a <code>Comment</code>.
  118. */
  119. public static final short COMMENT_NODE = 8;
  120. /**
  121. * The node is a <code>Document</code>.
  122. */
  123. public static final short DOCUMENT_NODE = 9;
  124. /**
  125. * The node is a <code>DocumentType</code>.
  126. */
  127. public static final short DOCUMENT_TYPE_NODE = 10;
  128. /**
  129. * The node is a <code>DocumentFragment</code>.
  130. */
  131. public static final short DOCUMENT_FRAGMENT_NODE = 11;
  132. /**
  133. * The node is a <code>Notation</code>.
  134. */
  135. public static final short NOTATION_NODE = 12;
  136. /**
  137. * The node is a <code>namespace node</code>. Note that this is not
  138. * currently a node type defined by the DOM API.
  139. */
  140. public static final short NAMESPACE_NODE = 13;
  141. /**
  142. * The number of valid nodetypes.
  143. */
  144. public static final short NTYPES = 14;
  145. // ========= DTM Implementation Control Functions. ==============
  146. // %TBD% RETIRED -- do via setFeature if needed. Remove from impls.
  147. // public void setParseBlockSize(int blockSizeSuggestion);
  148. /**
  149. * Set an implementation dependent feature.
  150. * <p>
  151. * %REVIEW% Do we really expect to set features on DTMs?
  152. *
  153. * @param featureId A feature URL.
  154. * @param state true if this feature should be on, false otherwise.
  155. */
  156. public void setFeature(String featureId, boolean state);
  157. /**
  158. * Set a run time property for this DTM instance.
  159. *
  160. * @param property a <code>String</code> value
  161. * @param value an <code>Object</code> value
  162. */
  163. public void setProperty(String property, Object value);
  164. // ========= Document Navigation Functions =========
  165. /**
  166. * This returns a stateless "traverser", that can navigate over an
  167. * XPath axis, though not in document order.
  168. *
  169. * @param axis One of Axes.ANCESTORORSELF, etc.
  170. *
  171. * @return A DTMAxisIterator, or null if the givin axis isn't supported.
  172. */
  173. public DTMAxisTraverser getAxisTraverser(final int axis);
  174. /**
  175. * This is a shortcut to the iterators that implement
  176. * XPath axes.
  177. * Returns a bare-bones iterator that must be initialized
  178. * with a start node (using iterator.setStartNode()).
  179. *
  180. * @param axis One of Axes.ANCESTORORSELF, etc.
  181. *
  182. * @return A DTMAxisIterator, or null if the givin axis isn't supported.
  183. */
  184. public DTMAxisIterator getAxisIterator(final int axis);
  185. /**
  186. * Get an iterator that can navigate over an XPath Axis, predicated by
  187. * the extended type ID.
  188. *
  189. * @param axis
  190. * @param type An extended type ID.
  191. *
  192. * @return A DTMAxisIterator, or null if the givin axis isn't supported.
  193. */
  194. public DTMAxisIterator getTypedAxisIterator(final int axis, final int type);
  195. /**
  196. * Given a node handle, test if it has child nodes.
  197. * <p> %REVIEW% This is obviously useful at the DOM layer, where it
  198. * would permit testing this without having to create a proxy
  199. * node. It's less useful in the DTM API, where
  200. * (dtm.getFirstChild(nodeHandle)!=DTM.NULL) is just as fast and
  201. * almost as self-evident. But it's a convenience, and eases porting
  202. * of DOM code to DTM. </p>
  203. *
  204. * @param nodeHandle int Handle of the node.
  205. * @return int true if the given node has child nodes.
  206. */
  207. public boolean hasChildNodes(int nodeHandle);
  208. /**
  209. * Given a node handle, get the handle of the node's first child.
  210. *
  211. * @param nodeHandle int Handle of the node.
  212. * @return int DTM node-number of first child,
  213. * or DTM.NULL to indicate none exists.
  214. */
  215. public int getFirstChild(int nodeHandle);
  216. /**
  217. * Given a node handle, get the handle of the node's last child.
  218. *
  219. * @param nodeHandle int Handle of the node.
  220. * @return int Node-number of last child,
  221. * or DTM.NULL to indicate none exists.
  222. */
  223. public int getLastChild(int nodeHandle);
  224. /**
  225. * Retrieves an attribute node by local name and namespace URI
  226. *
  227. * %TBD% Note that we currently have no way to support
  228. * the DOM's old getAttribute() call, which accesses only the qname.
  229. *
  230. * @param elementHandle Handle of the node upon which to look up this attribute.
  231. * @param namespaceURI The namespace URI of the attribute to
  232. * retrieve, or null.
  233. * @param name The local name of the attribute to
  234. * retrieve.
  235. * @return The attribute node handle with the specified name (
  236. * <code>nodeName</code>) or <code>DTM.NULL</code> if there is no such
  237. * attribute.
  238. */
  239. public int getAttributeNode(int elementHandle, String namespaceURI,
  240. String name);
  241. /**
  242. * Given a node handle, get the index of the node's first attribute.
  243. *
  244. * @param nodeHandle int Handle of the node.
  245. * @return Handle of first attribute, or DTM.NULL to indicate none exists.
  246. */
  247. public int getFirstAttribute(int nodeHandle);
  248. /**
  249. * Given a node handle, get the index of the node's first namespace node.
  250. *
  251. * @param nodeHandle handle to node, which should probably be an element
  252. * node, but need not be.
  253. *
  254. * @param inScope true if all namespaces in scope should be
  255. * returned, false if only the node's own
  256. * namespace declarations should be returned.
  257. * @return handle of first namespace,
  258. * or DTM.NULL to indicate none exists.
  259. */
  260. public int getFirstNamespaceNode(int nodeHandle, boolean inScope);
  261. /**
  262. * Given a node handle, advance to its next sibling.
  263. * @param nodeHandle int Handle of the node.
  264. * @return int Node-number of next sibling,
  265. * or DTM.NULL to indicate none exists.
  266. */
  267. public int getNextSibling(int nodeHandle);
  268. /**
  269. * Given a node handle, find its preceeding sibling.
  270. * WARNING: DTM implementations may be asymmetric; in some,
  271. * this operation has been resolved by search, and is relatively expensive.
  272. *
  273. * @param nodeHandle the id of the node.
  274. * @return int Node-number of the previous sib,
  275. * or DTM.NULL to indicate none exists.
  276. */
  277. public int getPreviousSibling(int nodeHandle);
  278. /**
  279. * Given a node handle, advance to the next attribute. If an
  280. * element, we advance to its first attribute; if an attr, we advance to
  281. * the next attr of the same element.
  282. *
  283. * @param nodeHandle int Handle of the node.
  284. * @return int DTM node-number of the resolved attr,
  285. * or DTM.NULL to indicate none exists.
  286. */
  287. public int getNextAttribute(int nodeHandle);
  288. /**
  289. * Given a namespace handle, advance to the next namespace in the same scope
  290. * (local or local-plus-inherited, as selected by getFirstNamespaceNode)
  291. *
  292. * @param baseHandle handle to original node from where the first child
  293. * was relative to (needed to return nodes in document order).
  294. * @param namespaceHandle handle to node which must be of type
  295. * NAMESPACE_NODE.
  296. * NEEDSDOC @param inScope
  297. * @return handle of next namespace,
  298. * or DTM.NULL to indicate none exists.
  299. */
  300. public int getNextNamespaceNode(int baseHandle, int namespaceHandle,
  301. boolean inScope);
  302. /**
  303. * Given a node handle, find its parent node.
  304. *
  305. * @param nodeHandle the id of the node.
  306. * @return int Node handle of parent,
  307. * or DTM.NULL to indicate none exists.
  308. */
  309. public int getParent(int nodeHandle);
  310. /**
  311. * Given a DTM which contains only a single document,
  312. * find the Node Handle of the Document node. Note
  313. * that if the DTM is configured so it can contain multiple
  314. * documents, this call will return the Document currently
  315. * under construction -- but may return null if it's between
  316. * documents. Generally, you should use getOwnerDocument(nodeHandle)
  317. * or getDocumentRoot(nodeHandle) instead.
  318. *
  319. * @return int Node handle of document, or DTM.NULL if a shared DTM
  320. * can not tell us which Document is currently active.
  321. */
  322. public int getDocument();
  323. /**
  324. * Given a node handle, find the owning document node. This version mimics
  325. * the behavior of the DOM call by the same name.
  326. *
  327. * @param nodeHandle the id of the node.
  328. * @return int Node handle of owning document, or DTM.NULL if the node was
  329. * a Document.
  330. * @see getDocumentRoot(int nodeHandle)
  331. */
  332. public int getOwnerDocument(int nodeHandle);
  333. /**
  334. * Given a node handle, find the owning document node.
  335. *
  336. * @param nodeHandle the id of the node.
  337. * @return int Node handle of owning document, or the node itself if it was
  338. * a Document. (Note difference from DOM, where getOwnerDocument returns
  339. * null for the Document node.)
  340. * @see getOwnerDocument(int nodeHandle)
  341. */
  342. public int getDocumentRoot(int nodeHandle);
  343. /**
  344. * Get the string-value of a node as a String object
  345. * (see http://www.w3.org/TR/xpath#data-model
  346. * for the definition of a node's string-value).
  347. *
  348. * @param nodeHandle The node ID.
  349. *
  350. * @return A string object that represents the string-value of the given node.
  351. */
  352. public XMLString getStringValue(int nodeHandle);
  353. /**
  354. * Get number of character array chunks in
  355. * the string-value of a node.
  356. * (see http://www.w3.org/TR/xpath#data-model
  357. * for the definition of a node's string-value).
  358. * Note that a single text node may have multiple text chunks.
  359. *
  360. * @param nodeHandle The node ID.
  361. *
  362. * @return number of character array chunks in
  363. * the string-value of a node.
  364. */
  365. public int getStringValueChunkCount(int nodeHandle);
  366. /**
  367. * Get a character array chunk in the string-value of a node.
  368. * (see http://www.w3.org/TR/xpath#data-model
  369. * for the definition of a node's string-value).
  370. * Note that a single text node may have multiple text chunks.
  371. *
  372. * @param nodeHandle The node ID.
  373. * @param chunkIndex Which chunk to get.
  374. * @param startAndLen A two-integer array which, upon return, WILL
  375. * BE FILLED with values representing the chunk's start position
  376. * within the returned character buffer and the length of the chunk.
  377. * @return The character array buffer within which the chunk occurs,
  378. * setting startAndLen's contents as a side-effect.
  379. */
  380. public char[] getStringValueChunk(int nodeHandle, int chunkIndex,
  381. int[] startAndLen);
  382. /**
  383. * Given a node handle, return an ID that represents the node's expanded name.
  384. *
  385. * @param nodeHandle The handle to the node in question.
  386. *
  387. * @return the expanded-name id of the node.
  388. */
  389. public int getExpandedTypeID(int nodeHandle);
  390. /**
  391. * Given an expanded name, return an ID. If the expanded-name does not
  392. * exist in the internal tables, the entry will be created, and the ID will
  393. * be returned. Any additional nodes that are created that have this
  394. * expanded name will use this ID.
  395. *
  396. * @param nodeHandle The handle to the node in question.
  397. *
  398. * NEEDSDOC @param namespace
  399. * NEEDSDOC @param localName
  400. * NEEDSDOC @param type
  401. *
  402. * @return the expanded-name id of the node.
  403. */
  404. public int getExpandedTypeID(String namespace, String localName, int type);
  405. /**
  406. * Given an expanded-name ID, return the local name part.
  407. *
  408. * @param ExpandedNameID an ID that represents an expanded-name.
  409. * @return String Local name of this node.
  410. */
  411. public String getLocalNameFromExpandedNameID(int ExpandedNameID);
  412. /**
  413. * Given an expanded-name ID, return the namespace URI part.
  414. *
  415. * @param ExpandedNameID an ID that represents an expanded-name.
  416. * @return String URI value of this node's namespace, or null if no
  417. * namespace was resolved.
  418. */
  419. public String getNamespaceFromExpandedNameID(int ExpandedNameID);
  420. /**
  421. * Given a node handle, return its DOM-style node name. This will
  422. * include names such as #text or #document.
  423. *
  424. * @param nodeHandle the id of the node.
  425. * @return String Name of this node, which may be an empty string.
  426. * %REVIEW% Document when empty string is possible...
  427. */
  428. public String getNodeName(int nodeHandle);
  429. /**
  430. * Given a node handle, return the XPath node name. This should be
  431. * the name as described by the XPath data model, NOT the DOM-style
  432. * name.
  433. *
  434. * @param nodeHandle the id of the node.
  435. * @return String Name of this node.
  436. */
  437. public String getNodeNameX(int nodeHandle);
  438. /**
  439. * Given a node handle, return its DOM-style localname.
  440. * (As defined in Namespaces, this is the portion of the name after the
  441. * prefix, if present, or the whole node name if no prefix exists)
  442. *
  443. * @param nodeHandle the id of the node.
  444. * @return String Local name of this node.
  445. */
  446. public String getLocalName(int nodeHandle);
  447. /**
  448. * Given a namespace handle, return the prefix that the namespace decl is
  449. * mapping.
  450. * Given a node handle, return the prefix used to map to the namespace.
  451. * (As defined in Namespaces, this is the portion of the name before any
  452. * colon character).
  453. * @param postition int Handle of the node.
  454. *
  455. * <p> %REVIEW% Are you sure you want "" for no prefix? </p>
  456. *
  457. * @param nodeHandle the id of the node.
  458. * @return String prefix of this node's name, or "" if no explicit
  459. * namespace prefix was given.
  460. */
  461. public String getPrefix(int nodeHandle);
  462. /**
  463. * Given a node handle, return its DOM-style namespace URI
  464. * (As defined in Namespaces, this is the declared URI which this node's
  465. * prefix -- or default in lieu thereof -- was mapped to.)
  466. * @param postition int Handle of the node.
  467. *
  468. * @param nodeHandle the id of the node.
  469. * @return String URI value of this node's namespace, or null if no
  470. * namespace was resolved.
  471. */
  472. public String getNamespaceURI(int nodeHandle);
  473. /**
  474. * Given a node handle, return its node value. This is mostly
  475. * as defined by the DOM, but may ignore some conveniences.
  476. * <p>
  477. * @param nodeHandle The node id.
  478. * @return String Value of this node, or null if not
  479. * meaningful for this node type.
  480. */
  481. public String getNodeValue(int nodeHandle);
  482. /**
  483. * Given a node handle, return its DOM-style node type.
  484. *
  485. * <p>%REVIEW% Generally, returning short is false economy. Return int?</p>
  486. *
  487. * @param nodeHandle The node id.
  488. * @return int Node type, as per the DOM's Node._NODE constants.
  489. */
  490. public short getNodeType(int nodeHandle);
  491. /**
  492. * Get the depth level of this node in the tree (equals 1 for
  493. * a parentless node).
  494. *
  495. * @param nodeHandle The node id.
  496. * @return the number of ancestors, plus one
  497. * @xsl.usage internal
  498. */
  499. public short getLevel(int nodeHandle);
  500. // ============== Document query functions ==============
  501. /**
  502. * Tests whether DTM DOM implementation implements a specific feature and
  503. * that feature is supported by this node.
  504. * @param feature The name of the feature to test.
  505. * @param version This is the version number of the feature to test.
  506. * If the version is not
  507. * specified, supporting any version of the feature will cause the
  508. * method to return <code>true</code>.
  509. * @return Returns <code>true</code> if the specified feature is
  510. * supported on this node, <code>false</code> otherwise.
  511. */
  512. public boolean isSupported(String feature, String version);
  513. /**
  514. * Return the base URI of the document entity. If it is not known
  515. * (because the document was parsed from a socket connection or from
  516. * standard input, for example), the value of this property is unknown.
  517. *
  518. * @return the document base URI String object or null if unknown.
  519. */
  520. public String getDocumentBaseURI();
  521. /**
  522. * Set the base URI of the document entity.
  523. *
  524. * @param baseURI the document base URI String object or null if unknown.
  525. */
  526. public void setDocumentBaseURI(String baseURI);
  527. /**
  528. * Return the system identifier of the document entity. If
  529. * it is not known, the value of this property is null.
  530. *
  531. * @param nodeHandle The node id, which can be any valid node handle.
  532. * @return the system identifier String object or null if unknown.
  533. */
  534. public String getDocumentSystemIdentifier(int nodeHandle);
  535. /**
  536. * Return the name of the character encoding scheme
  537. * in which the document entity is expressed.
  538. *
  539. * @param nodeHandle The node id, which can be any valid node handle.
  540. * @return the document encoding String object.
  541. */
  542. public String getDocumentEncoding(int nodeHandle);
  543. /**
  544. * Return an indication of the standalone status of the document,
  545. * either "yes" or "no". This property is derived from the optional
  546. * standalone document declaration in the XML declaration at the
  547. * beginning of the document entity, and has no value if there is no
  548. * standalone document declaration.
  549. *
  550. * @param nodeHandle The node id, which can be any valid node handle.
  551. * @return the document standalone String object, either "yes", "no", or null.
  552. */
  553. public String getDocumentStandalone(int nodeHandle);
  554. /**
  555. * Return a string representing the XML version of the document. This
  556. * property is derived from the XML declaration optionally present at the
  557. * beginning of the document entity, and has no value if there is no XML
  558. * declaration.
  559. *
  560. * @param the document handle
  561. *
  562. * NEEDSDOC @param documentHandle
  563. *
  564. * @return the document version String object
  565. */
  566. public String getDocumentVersion(int documentHandle);
  567. /**
  568. * Return an indication of
  569. * whether the processor has read the complete DTD. Its value is a
  570. * boolean. If it is false, then certain properties (indicated in their
  571. * descriptions below) may be unknown. If it is true, those properties
  572. * are never unknown.
  573. *
  574. * @return <code>true</code> if all declarations were processed;
  575. * <code>false</code> otherwise.
  576. */
  577. public boolean getDocumentAllDeclarationsProcessed();
  578. /**
  579. * A document type declaration information item has the following properties:
  580. *
  581. * 1. [system identifier] The system identifier of the external subset, if
  582. * it exists. Otherwise this property has no value.
  583. *
  584. * @return the system identifier String object, or null if there is none.
  585. */
  586. public String getDocumentTypeDeclarationSystemIdentifier();
  587. /**
  588. * Return the public identifier of the external subset,
  589. * normalized as described in 4.2.2 External Entities [XML]. If there is
  590. * no external subset or if it has no public identifier, this property
  591. * has no value.
  592. *
  593. * @param the document type declaration handle
  594. *
  595. * @return the public identifier String object, or null if there is none.
  596. */
  597. public String getDocumentTypeDeclarationPublicIdentifier();
  598. /**
  599. * Returns the <code>Element</code> whose <code>ID</code> is given by
  600. * <code>elementId</code>. If no such element exists, returns
  601. * <code>DTM.NULL</code>. Behavior is not defined if more than one element
  602. * has this <code>ID</code>. Attributes (including those
  603. * with the name "ID") are not of type ID unless so defined by DTD/Schema
  604. * information available to the DTM implementation.
  605. * Implementations that do not know whether attributes are of type ID or
  606. * not are expected to return <code>DTM.NULL</code>.
  607. *
  608. * <p>%REVIEW% Presumably IDs are still scoped to a single document,
  609. * and this operation searches only within a single document, right?
  610. * Wouldn't want collisions between DTMs in the same process.</p>
  611. *
  612. * @param elementId The unique <code>id</code> value for an element.
  613. * @return The handle of the matching element.
  614. */
  615. public int getElementById(String elementId);
  616. /**
  617. * The getUnparsedEntityURI function returns the URI of the unparsed
  618. * entity with the specified name in the same document as the context
  619. * node (see [3.3 Unparsed Entities]). It returns the empty string if
  620. * there is no such entity.
  621. * <p>
  622. * XML processors may choose to use the System Identifier (if one
  623. * is provided) to resolve the entity, rather than the URI in the
  624. * Public Identifier. The details are dependent on the processor, and
  625. * we would have to support some form of plug-in resolver to handle
  626. * this properly. Currently, we simply return the System Identifier if
  627. * present, and hope that it a usable URI or that our caller can
  628. * map it to one.
  629. * %REVIEW% Resolve Public Identifiers... or consider changing function name.
  630. * <p>
  631. * If we find a relative URI
  632. * reference, XML expects it to be resolved in terms of the base URI
  633. * of the document. The DOM doesn't do that for us, and it isn't
  634. * entirely clear whether that should be done here; currently that's
  635. * pushed up to a higher level of our application. (Note that DOM Level
  636. * 1 didn't store the document's base URI.)
  637. * %REVIEW% Consider resolving Relative URIs.
  638. * <p>
  639. * (The DOM's statement that "An XML processor may choose to
  640. * completely expand entities before the structure model is passed
  641. * to the DOM" refers only to parsed entities, not unparsed, and hence
  642. * doesn't affect this function.)
  643. *
  644. * @param name A string containing the Entity Name of the unparsed
  645. * entity.
  646. *
  647. * @return String containing the URI of the Unparsed Entity, or an
  648. * empty string if no such entity exists.
  649. */
  650. public String getUnparsedEntityURI(String name);
  651. // ============== Boolean methods ================
  652. /**
  653. * Return true if the xsl:strip-space or xsl:preserve-space was processed
  654. * during construction of the document contained in this DTM.
  655. *
  656. * NEEDSDOC ($objectName$) @return
  657. */
  658. public boolean supportsPreStripping();
  659. /**
  660. * Figure out whether nodeHandle2 should be considered as being later
  661. * in the document than nodeHandle1, in Document Order as defined
  662. * by the XPath model. This may not agree with the ordering defined
  663. * by other XML applications.
  664. * <p>
  665. * There are some cases where ordering isn't defined, and neither are
  666. * the results of this function -- though we'll generally return true.
  667. * <p>
  668. * %REVIEW% Make sure this does the right thing with attribute nodes!!!
  669. * <p>
  670. * %REVIEW% Consider renaming for clarity. Perhaps isDocumentOrder(a,b)?
  671. *
  672. * @param firstNodeHandle DOM Node to perform position comparison on.
  673. * @param secondNodeHandle DOM Node to perform position comparison on.
  674. *
  675. * @return false if secondNode comes before firstNode, otherwise return true.
  676. * You can think of this as
  677. * <code>(firstNode.documentOrderPosition <= secondNode.documentOrderPosition)</code>.
  678. */
  679. public boolean isNodeAfter(int firstNodeHandle, int secondNodeHandle);
  680. /**
  681. * 2. [element content whitespace] A boolean indicating whether a
  682. * text node represents white space appearing within element content
  683. * (see [XML], 2.10 "White Space Handling"). Note that validating
  684. * XML processors are required by XML 1.0 to provide this
  685. * information... but that DOM Level 2 did not support it, since it
  686. * depends on knowledge of the DTD which DOM2 could not guarantee
  687. * would be available.
  688. * <p>
  689. * If there is no declaration for the containing element, an XML
  690. * processor must assume that the whitespace could be meaningful and
  691. * return false. If no declaration has been read, but the [all
  692. * declarations processed] property of the document information item
  693. * is false (so there may be an unread declaration), then the value
  694. * of this property is indeterminate for white space characters and
  695. * should probably be reported as false. It is always false for text
  696. * nodes that contain anything other than (or in addition to) white
  697. * space.
  698. * <p>
  699. * Note too that it always returns false for non-Text nodes.
  700. * <p>
  701. * %REVIEW% Joe wants to rename this isWhitespaceInElementContent() for clarity
  702. *
  703. * @param nodeHandle the node ID.
  704. * @return <code>true</code> if the node definitely represents whitespace in
  705. * element content; <code>false</code> otherwise.
  706. */
  707. public boolean isCharacterElementContentWhitespace(int nodeHandle);
  708. /**
  709. * 10. [all declarations processed] This property is not strictly speaking
  710. * part of the infoset of the document. Rather it is an indication of
  711. * whether the processor has read the complete DTD. Its value is a
  712. * boolean. If it is false, then certain properties (indicated in their
  713. * descriptions below) may be unknown. If it is true, those properties
  714. * are never unknown.
  715. *
  716. *
  717. * @param the document handle
  718. *
  719. * @param documentHandle A node handle that must identify a document.
  720. * @return <code>true</code> if all declarations were processed;
  721. * <code>false</code> otherwise.
  722. */
  723. public boolean isDocumentAllDeclarationsProcessed(int documentHandle);
  724. /**
  725. * 5. [specified] A flag indicating whether this attribute was actually
  726. * specified in the start-tag of its element, or was defaulted from the
  727. * DTD (or schema).
  728. *
  729. * @param the attribute handle
  730. *
  731. * NEEDSDOC @param attributeHandle
  732. * @return <code>true</code> if the attribute was specified;
  733. * <code>false</code> if it was defaulted or the handle doesn't
  734. * refer to an attribute node.
  735. */
  736. public boolean isAttributeSpecified(int attributeHandle);
  737. // ========== Direct SAX Dispatch, for optimization purposes ========
  738. /**
  739. * Directly call the
  740. * characters method on the passed ContentHandler for the
  741. * string-value of the given node (see http://www.w3.org/TR/xpath#data-model
  742. * for the definition of a node's string-value). Multiple calls to the
  743. * ContentHandler's characters methods may well occur for a single call to
  744. * this method.
  745. *
  746. * @param nodeHandle The node ID.
  747. * @param ch A non-null reference to a ContentHandler.
  748. * @param normalize true if the content should be normalized according to
  749. * the rules for the XPath
  750. * <a href="http://www.w3.org/TR/xpath#function-normalize-space">normalize-space</a>
  751. * function.
  752. *
  753. * @throws org.xml.sax.SAXException
  754. */
  755. public void dispatchCharactersEvents(
  756. int nodeHandle, org.xml.sax.ContentHandler ch, boolean normalize)
  757. throws org.xml.sax.SAXException;
  758. /**
  759. * Directly create SAX parser events representing the XML content of
  760. * a DTM subtree. This is a "serialize" operation.
  761. *
  762. * @param nodeHandle The node ID.
  763. * @param ch A non-null reference to a ContentHandler.
  764. *
  765. * @throws org.xml.sax.SAXException
  766. */
  767. public void dispatchToEvents(int nodeHandle, org.xml.sax.ContentHandler ch)
  768. throws org.xml.sax.SAXException;
  769. /**
  770. * Return an DOM node for the given node.
  771. *
  772. * @param nodeHandle The node ID.
  773. *
  774. * @return A node representation of the DTM node.
  775. */
  776. public org.w3c.dom.Node getNode(int nodeHandle);
  777. // ==== Construction methods (may not be supported by some implementations!) =====
  778. // %REVIEW% What response occurs if not supported?
  779. /**
  780. * @return true iff we're building this model incrementally (eg
  781. * we're partnered with a CoroutineParser) and thus require that the
  782. * transformation and the parse run simultaneously. Guidance to the
  783. * DTMManager.
  784. */
  785. public boolean needsTwoThreads();
  786. // %REVIEW% Do these appends make any sense, should we support a
  787. // wider set of methods (like the "append" methods in the
  788. // current DTMDocumentImpl draft), or should we just support SAX
  789. // listener interfaces? Should it be a separate interface to
  790. // make that distinction explicit?
  791. /**
  792. * Return this DTM's content handler, if it has one.
  793. *
  794. * @return null if this model doesn't respond to SAX events.
  795. */
  796. public org.xml.sax.ContentHandler getContentHandler();
  797. /**
  798. * Return this DTM's lexical handler, if it has one.
  799. *
  800. * %REVIEW% Should this return null if constrution already done/begun?
  801. *
  802. * @return null if this model doesn't respond to lexical SAX events.
  803. */
  804. public org.xml.sax.ext.LexicalHandler getLexicalHandler();
  805. /**
  806. * Return this DTM's EntityResolver, if it has one.
  807. *
  808. * @return null if this model doesn't respond to SAX entity ref events.
  809. */
  810. public org.xml.sax.EntityResolver getEntityResolver();
  811. /**
  812. * Return this DTM's DTDHandler, if it has one.
  813. *
  814. * @return null if this model doesn't respond to SAX dtd events.
  815. */
  816. public org.xml.sax.DTDHandler getDTDHandler();
  817. /**
  818. * Return this DTM's ErrorHandler, if it has one.
  819. *
  820. * @return null if this model doesn't respond to SAX error events.
  821. */
  822. public org.xml.sax.ErrorHandler getErrorHandler();
  823. /**
  824. * Return this DTM's DeclHandler, if it has one.
  825. *
  826. * @return null if this model doesn't respond to SAX Decl events.
  827. */
  828. public org.xml.sax.ext.DeclHandler getDeclHandler();
  829. /**
  830. * Append a child to "the end of the document". Please note that
  831. * the node is always cloned in a base DTM, since our basic behavior
  832. * is immutable so nodes can't be removed from their previous
  833. * location.
  834. *
  835. * <p> %REVIEW% DTM maintains an insertion cursor which
  836. * performs a depth-first tree walk as nodes come in, and this operation
  837. * is really equivalent to:
  838. * insertionCursor.appendChild(document.importNode(newChild)))
  839. * where the insert point is the last element that was appended (or
  840. * the last one popped back to by an end-element operation).</p>
  841. *
  842. * @param newChild Must be a valid new node handle.
  843. * @param clone true if the child should be cloned into the document.
  844. * @param cloneDepth if the clone argument is true, specifies that the
  845. * clone should include all it's children.
  846. */
  847. public void appendChild(int newChild, boolean clone, boolean cloneDepth);
  848. /**
  849. * Append a text node child that will be constructed from a string,
  850. * to the end of the document. Behavior is otherwise like appendChild().
  851. *
  852. * @param str Non-null reference to a string.
  853. */
  854. public void appendTextChild(String str);
  855. /**
  856. * Get the location of a node in the source document.
  857. *
  858. * @param node an <code>int</code> value
  859. * @return a <code>SourceLocator</code> value or null if no location
  860. * is available
  861. */
  862. public SourceLocator getSourceLocatorFor(int node);
  863. /**
  864. * As the DTM is registered with the DTMManager, this method
  865. * will be called. This will give the DTM implementation a
  866. * chance to initialize any subsystems that are required to
  867. * build the DTM
  868. */
  869. public void documentRegistration();
  870. /**
  871. * As documents are released from the DTMManager, the DTM implementation
  872. * will be notified of the event. This will allow the DTM implementation
  873. * to shutdown any subsystem activity that may of been assoiated with
  874. * the active DTM Implementation.
  875. */
  876. public void documentRelease();
  877. /**
  878. * Migrate a DTM built with an old DTMManager to a new DTMManager.
  879. * After the migration, the new DTMManager will treat the DTM as
  880. * one that is built by itself.
  881. * This is used to support DTM sharing between multiple transformations.
  882. * @param manager the DTMManager
  883. */
  884. public void migrateTo(DTMManager manager);
  885. }