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

文件:DTM.java
包名:com.sun.org.apache.xml.internal.dtm
类名:DTM
继承:
接口: