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