1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 1999-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 /* 21 * $Id: DTMNodeProxy.java,v 22 */ 23 package com.sun.org.apache.xml.internal.dtm.ref; 24 25 import java.util.Vector; 26 27 import com.sun.org.apache.xml.internal.dtm.DTM; 28 import com.sun.org.apache.xml.internal.dtm.DTMDOMException; 29 import com.sun.org.apache.xpath.internal.NodeSet; 30 31 import org.w3c.dom.Attr; 32 import org.w3c.dom.CDATASection; 33 import org.w3c.dom.Comment; 34 import org.w3c.dom.DOMException; 35 import org.w3c.dom.DOMImplementation; 36 import org.w3c.dom.Document; 37 import org.w3c.dom.DocumentFragment; 38 import org.w3c.dom.DocumentType; 39 import org.w3c.dom.Element; 40 import org.w3c.dom.EntityReference; 41 import org.w3c.dom.NamedNodeMap; 42 import org.w3c.dom.Node; 43 import org.w3c.dom.NodeList; 44 import org.w3c.dom.ProcessingInstruction; 45 import org.w3c.dom.Text; 46 47 import org.w3c.dom.UserDataHandler; 48 import org.w3c.dom.DOMConfiguration; 49 import org.w3c.dom.TypeInfo; 50 51 /** 52 * <code>DTMNodeProxy</code> presents a DOM Node API front-end to the DTM model. 53 * <p> 54 * It does _not_ attempt to address the "node identity" question; no effort 55 * is made to prevent the creation of multiple proxies referring to a single 56 * DTM node. Users can create a mechanism for managing this, or relinquish the 57 * use of "==" and use the .sameNodeAs() mechanism, which is under 58 * consideration for future versions of the DOM. 59 * <p> 60 * DTMNodeProxy may be subclassed further to present specific DOM node types. 61 * 62 * @see org.w3c.dom 63 */ 64 public class DTMNodeProxy 65 implements Node, Document, Text, Element, Attr, 66 ProcessingInstruction, Comment, DocumentFragment 67 { 68 69 /** The DTM for this node. */ 70 public DTM dtm; 71 72 /** The DTM node handle. */ 73 int node; 74 75 /** The return value as Empty String. */ 76 private static final String EMPTYSTRING = ""; 77 78 /** The DOMImplementation object */ 79 static final DOMImplementation implementation=new DTMNodeProxyImplementation(); 80 81 /** 82 * Create a DTMNodeProxy Node representing a specific Node in a DTM 83 * 84 * @param dtm The DTM Reference, must be non-null. 85 * @param node The DTM node handle. 86 */ 87 public DTMNodeProxy(DTM dtm, int node) 88 { 89 this.dtm = dtm; 90 this.node = node; 91 } 92 93 /** 94 * NON-DOM: Return the DTM model 95 * 96 * @return The DTM that this proxy is a representative for. 97 */ 98 public final DTM getDTM() 99 { 100 return dtm; 101 } 102 103 /** 104 * NON-DOM: Return the DTM node number 105 * 106 * @return The DTM node handle. 107 */ 108 public final int getDTMNodeNumber() 109 { 110 return node; 111 } 112 113 /** 114 * Test for equality based on node number. 115 * 116 * @param node A DTM node proxy reference. 117 * 118 * @return true if the given node has the same handle as this node. 119 */ 120 public final boolean equals(Node node) 121 { 122 123 try 124 { 125 DTMNodeProxy dtmp = (DTMNodeProxy) node; 126 127 // return (dtmp.node == this.node); 128 // Patch attributed to Gary L Peskin <garyp@firstech.com> 129 return (dtmp.node == this.node) && (dtmp.dtm == this.dtm); 130 } 131 catch (ClassCastException cce) 132 { 133 return false; 134 } 135 } 136 137 /** 138 * Test for equality based on node number. 139 * 140 * @param node A DTM node proxy reference. 141 * 142 * @return true if the given node has the same handle as this node. 143 */ 144 public final boolean equals(Object node) 145 { 146 147 try 148 { 149 150 // DTMNodeProxy dtmp = (DTMNodeProxy)node; 151 // return (dtmp.node == this.node); 152 // Patch attributed to Gary L Peskin <garyp@firstech.com> 153 return equals((Node) node); 154 } 155 catch (ClassCastException cce) 156 { 157 return false; 158 } 159 } 160 161 /** 162 * FUTURE DOM: Test node identity, in lieu of Node==Node 163 * 164 * @param other 165 * 166 * @return true if the given node has the same handle as this node. 167 */ 168 public final boolean sameNodeAs(Node other) 169 { 170 171 if (!(other instanceof DTMNodeProxy)) 172 return false; 173 174 DTMNodeProxy that = (DTMNodeProxy) other; 175 176 return this.dtm == that.dtm && this.node == that.node; 177 } 178 179 /** 180 * 181 * 182 * @see org.w3c.dom.Node 183 */ 184 public final String getNodeName() 185 { 186 return dtm.getNodeName(node); 187 } 188 189 /** 190 * A PI's "target" states what processor channel the PI's data 191 * should be directed to. It is defined differently in HTML and XML. 192 * <p> 193 * In XML, a PI's "target" is the first (whitespace-delimited) token 194 * following the "<?" token that begins the PI. 195 * <p> 196 * In HTML, target is always null. 197 * <p> 198 * Note that getNodeName is aliased to getTarget. 199 * 200 * 201 */ 202 public final String getTarget() 203 { 204 return dtm.getNodeName(node); 205 } // getTarget():String 206 207 /** 208 * 209 * 210 * @see org.w3c.dom.Node as of DOM Level 2 211 */ 212 public final String getLocalName() 213 { 214 return dtm.getLocalName(node); 215 } 216 217 /** 218 * @return The prefix for this node. 219 * @see org.w3c.dom.Node as of DOM Level 2 220 */ 221 public final String getPrefix() 222 { 223 return dtm.getPrefix(node); 224 } 225 226 /** 227 * 228 * @param prefix 229 * 230 * @throws DOMException 231 * @see org.w3c.dom.Node as of DOM Level 2 -- DTMNodeProxy is read-only 232 */ 233 public final void setPrefix(String prefix) throws DOMException 234 { 235 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 236 } 237 238 /** 239 * 240 * 241 * @see org.w3c.dom.Node as of DOM Level 2 242 */ 243 public final String getNamespaceURI() 244 { 245 return dtm.getNamespaceURI(node); 246 } 247 248 /** Ask whether we support a given DOM feature. 249 * In fact, we do not _fully_ support any DOM feature -- we're a 250 * read-only subset -- so arguably we should always return false. 251 * Or we could say that we support DOM Core Level 2 but all nodes 252 * are read-only. Unclear which answer is least misleading. 253 * 254 * NON-DOM method. This was present in early drafts of DOM Level 2, 255 * but was renamed isSupported. It's present here only because it's 256 * cheap, harmless, and might help some poor fool who is still trying 257 * to use an early Working Draft of the DOM. 258 * 259 * @param feature 260 * @param version 261 * 262 * @return false 263 */ 264 public final boolean supports(String feature, String version) 265 { 266 return implementation.hasFeature(feature,version); 267 //throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 268 } 269 270 /** Ask whether we support a given DOM feature. 271 * In fact, we do not _fully_ support any DOM feature -- we're a 272 * read-only subset -- so arguably we should always return false. 273 * 274 * @param feature 275 * @param version 276 * 277 * @return false 278 * @see org.w3c.dom.Node as of DOM Level 2 279 */ 280 public final boolean isSupported(String feature, String version) 281 { 282 return implementation.hasFeature(feature,version); 283 // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 284 } 285 286 /** 287 * 288 * 289 * 290 * @throws DOMException 291 * @see org.w3c.dom.Node 292 */ 293 public final String getNodeValue() throws DOMException 294 { 295 return dtm.getNodeValue(node); 296 } 297 298 /** 299 * @return The string value of the node 300 * 301 * @throws DOMException 302 */ 303 public final String getStringValue() throws DOMException 304 { 305 return dtm.getStringValue(node).toString(); 306 } 307 308 /** 309 * 310 * @param nodeValue 311 * 312 * @throws DOMException 313 * @see org.w3c.dom.Node -- DTMNodeProxy is read-only 314 */ 315 public final void setNodeValue(String nodeValue) throws DOMException 316 { 317 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 318 } 319 320 /** 321 * 322 * 323 * @see org.w3c.dom.Node 324 */ 325 public final short getNodeType() 326 { 327 return (short) dtm.getNodeType(node); 328 } 329 330 /** 331 * 332 * 333 * @see org.w3c.dom.Node 334 */ 335 public final Node getParentNode() 336 { 337 338 if (getNodeType() == Node.ATTRIBUTE_NODE) 339 return null; 340 341 int newnode = dtm.getParent(node); 342 343 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 344 } 345 346 /** 347 * 348 * 349 * @see org.w3c.dom.Node 350 */ 351 public final Node getOwnerNode() 352 { 353 354 int newnode = dtm.getParent(node); 355 356 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 357 } 358 359 /** 360 * 361 * 362 * @see org.w3c.dom.Node 363 */ 364 public final NodeList getChildNodes() 365 { 366 367 // Annoyingly, AxisIterators do not currently implement DTMIterator, so 368 // we can't just wap DTMNodeList around an Axis.CHILD iterator. 369 // Instead, we've created a special-case operating mode for that object. 370 return new DTMChildIterNodeList(dtm,node); 371 372 // throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 373 } 374 375 /** 376 * 377 * 378 * @see org.w3c.dom.Node 379 */ 380 public final Node getFirstChild() 381 { 382 383 int newnode = dtm.getFirstChild(node); 384 385 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 386 } 387 388 /** 389 * 390 * 391 * @see org.w3c.dom.Node 392 */ 393 public final Node getLastChild() 394 { 395 396 int newnode = dtm.getLastChild(node); 397 398 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 399 } 400 401 /** 402 * 403 * 404 * @see org.w3c.dom.Node 405 */ 406 public final Node getPreviousSibling() 407 { 408 409 int newnode = dtm.getPreviousSibling(node); 410 411 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 412 } 413 414 /** 415 * 416 * 417 * @see org.w3c.dom.Node 418 */ 419 public final Node getNextSibling() 420 { 421 422 // Attr's Next is defined at DTM level, but not at DOM level. 423 if (dtm.getNodeType(node) == Node.ATTRIBUTE_NODE) 424 return null; 425 426 int newnode = dtm.getNextSibling(node); 427 428 return (newnode == DTM.NULL) ? null : dtm.getNode(newnode); 429 } 430 431 // DTMNamedNodeMap m_attrs; 432 433 /** 434 * 435 * 436 * @see org.w3c.dom.Node 437 */ 438 public final NamedNodeMap getAttributes() 439 { 440 441 return new DTMNamedNodeMap(dtm, node); 442 } 443 444 /** 445 * Method hasAttribute 446 * 447 * 448 * @param name 449 * 450 */ 451 public boolean hasAttribute(String name) 452 { 453 return DTM.NULL != dtm.getAttributeNode(node,null,name); 454 } 455 456 /** 457 * Method hasAttributeNS 458 * 459 * 460 * @param namespaceURI 461 * @param localName 462 * 463 * 464 */ 465 public boolean hasAttributeNS(String namespaceURI, String localName) 466 { 467 return DTM.NULL != dtm.getAttributeNode(node,namespaceURI,localName); 468 } 469 470 /** 471 * 472 * 473 * @see org.w3c.dom.Node 474 */ 475 public final Document getOwnerDocument() 476 { 477 // Note that this uses the DOM-compatable version of the call 478 return (Document)(dtm.getNode(dtm.getOwnerDocument(node))); 479 } 480 481 /** 482 * 483 * @param newChild 484 * @param refChild 485 * 486 * 487 * 488 * @throws DOMException 489 * @see org.w3c.dom.Node -- DTMNodeProxy is read-only 490 */ 491 public final Node insertBefore(Node newChild, Node refChild) 492 throws DOMException 493 { 494 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 495 } 496 497 /** 498 * 499 * @param newChild 500 * @param oldChild 501 * 502 * 503 * 504 * @throws DOMException 505 * @see org.w3c.dom.Node -- DTMNodeProxy is read-only 506 */ 507 public final Node replaceChild(Node newChild, Node oldChild) 508 throws DOMException 509 { 510 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 511 } 512 513 /** 514 * 515 * @param oldChild 516 * 517 * 518 * 519 * @throws DOMException 520 * @see org.w3c.dom.Node -- DTMNodeProxy is read-only 521 */ 522 public final Node removeChild(Node oldChild) throws DOMException 523 { 524 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 525 } 526 527 /** 528 * 529 * @param newChild 530 * 531 * 532 * 533 * @throws DOMException 534 * @see org.w3c.dom.Node -- DTMNodeProxy is read-only 535 */ 536 public final Node appendChild(Node newChild) throws DOMException 537 { 538 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 539 } 540 541 /** 542 * 543 * 544 * @see org.w3c.dom.Node 545 */ 546 public final boolean hasChildNodes() 547 { 548 return (DTM.NULL != dtm.getFirstChild(node)); 549 } 550 551 /** 552 * 553 * @param deep 554 * 555 * 556 * @see org.w3c.dom.Node -- DTMNodeProxy is read-only 557 */ 558 public final Node cloneNode(boolean deep) 559 { 560 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 561 } 562 563 /** 564 * 565 * 566 * @see org.w3c.dom.Document 567 */ 568 public final DocumentType getDoctype() 569 { 570 return null; 571 } 572 573 /** 574 * 575 * 576 * @see org.w3c.dom.Document 577 */ 578 public final DOMImplementation getImplementation() 579 { 580 return implementation; 581 } 582 583 /** This is a bit of a problem in DTM, since a DTM may be a Document 584 * Fragment and hence not have a clear-cut Document Element. We can 585 * make it work in the well-formed cases but would that be confusing for others? 586 * 587 * 588 * @see org.w3c.dom.Document 589 */ 590 public final Element getDocumentElement() 591 { 592 int dochandle=dtm.getDocument(); 593 int elementhandle=DTM.NULL; 594 for(int kidhandle=dtm.getFirstChild(dochandle); 595 kidhandle!=DTM.NULL; 596 kidhandle=dtm.getNextSibling(kidhandle)) 597 { 598 switch(dtm.getNodeType(kidhandle)) 599 { 600 case Node.ELEMENT_NODE: 601 if(elementhandle!=DTM.NULL) 602 { 603 elementhandle=DTM.NULL; // More than one; ill-formed. 604 kidhandle=dtm.getLastChild(dochandle); // End loop 605 } 606 else 607 elementhandle=kidhandle; 608 break; 609 610 // These are harmless; document is still wellformed 611 case Node.COMMENT_NODE: 612 case Node.PROCESSING_INSTRUCTION_NODE: 613 case Node.DOCUMENT_TYPE_NODE: 614 break; 615 616 default: 617 elementhandle=DTM.NULL; // ill-formed 618 kidhandle=dtm.getLastChild(dochandle); // End loop 619 break; 620 } 621 } 622 if(elementhandle==DTM.NULL) 623 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 624 else 625 return (Element)(dtm.getNode(elementhandle)); 626 } 627 628 /** 629 * 630 * @param tagName 631 * 632 * 633 * 634 * @throws DOMException 635 * @see org.w3c.dom.Document 636 */ 637 public final Element createElement(String tagName) throws DOMException 638 { 639 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 640 } 641 642 /** 643 * 644 * 645 * @see org.w3c.dom.Document 646 */ 647 public final DocumentFragment createDocumentFragment() 648 { 649 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 650 } 651 652 /** 653 * 654 * @param data 655 * 656 * 657 * @see org.w3c.dom.Document 658 */ 659 public final Text createTextNode(String data) 660 { 661 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 662 } 663 664 /** 665 * 666 * @param data 667 * 668 * 669 * @see org.w3c.dom.Document 670 */ 671 public final Comment createComment(String data) 672 { 673 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 674 } 675 676 /** 677 * 678 * @param data 679 * 680 * 681 * 682 * @throws DOMException 683 * @see org.w3c.dom.Document 684 */ 685 public final CDATASection createCDATASection(String data) 686 throws DOMException 687 { 688 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 689 } 690 691 /** 692 * 693 * @param target 694 * @param data 695 * 696 * 697 * 698 * @throws DOMException 699 * @see org.w3c.dom.Document 700 */ 701 public final ProcessingInstruction createProcessingInstruction( 702 String target, String data) throws DOMException 703 { 704 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 705 } 706 707 /** 708 * 709 * @param name 710 * 711 * 712 * 713 * @throws DOMException 714 * @see org.w3c.dom.Document 715 */ 716 public final Attr createAttribute(String name) throws DOMException 717 { 718 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 719 } 720 721 /** 722 * 723 * @param name 724 * 725 * 726 * 727 * @throws DOMException 728 * @see org.w3c.dom.Document 729 */ 730 public final EntityReference createEntityReference(String name) 731 throws DOMException 732 { 733 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 734 } 735 /** 736 * 737 * @param tagname 738 * 739 * 740 * @see org.w3c.dom.Document 741 */ 742 public final NodeList getElementsByTagName(String tagname) 743 { 744 Vector listVector = new Vector(); 745 Node retNode = dtm.getNode(node); 746 if (retNode != null) 747 { 748 boolean isTagNameWildCard = "*".equals(tagname); 749 if (DTM.ELEMENT_NODE == retNode.getNodeType()) 750 { 751 NodeList nodeList = retNode.getChildNodes(); 752 for (int i = 0; i < nodeList.getLength(); i++) 753 { 754 traverseChildren(listVector, nodeList.item(i), tagname, 755 isTagNameWildCard); 756 } 757 } else if (DTM.DOCUMENT_NODE == retNode.getNodeType()) { 758 traverseChildren(listVector, dtm.getNode(node), tagname, 759 isTagNameWildCard); 760 } 761 } 762 int size = listVector.size(); 763 NodeSet nodeSet = new NodeSet(size); 764 for (int i = 0; i < size; i++) 765 { 766 nodeSet.addNode((Node) listVector.elementAt(i)); 767 } 768 return (NodeList) nodeSet; 769 } 770 771 /** 772 * 773 * @param listVector 774 * @param tempNode 775 * @param tagname 776 * @param isTagNameWildCard 777 * 778 * 779 * Private method to be used for recursive iterations to obtain elements by tag name. 780 */ 781 private final void traverseChildren 782 ( 783 Vector listVector, 784 Node tempNode, 785 String tagname, 786 boolean isTagNameWildCard) { 787 if (tempNode == null) 788 { 789 return; 790 } 791 else 792 { 793 if (tempNode.getNodeType() == DTM.ELEMENT_NODE 794 && (isTagNameWildCard || tempNode.getNodeName().equals(tagname))) 795 { 796 listVector.add(tempNode); 797 } 798 if(tempNode.hasChildNodes()) 799 { 800 NodeList nodeList = tempNode.getChildNodes(); 801 for (int i = 0; i < nodeList.getLength(); i++) 802 { 803 traverseChildren(listVector, nodeList.item(i), tagname, 804 isTagNameWildCard); 805 } 806 } 807 } 808 } 809 810 811 812 /** 813 * 814 * @param importedNode 815 * @param deep 816 * 817 * 818 * 819 * @throws DOMException 820 * @see org.w3c.dom.Document as of DOM Level 2 -- DTMNodeProxy is read-only 821 */ 822 public final Node importNode(Node importedNode, boolean deep) 823 throws DOMException 824 { 825 throw new DTMDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); 826 } 827 828 /** 829 * 830 * @param namespaceURI 831 * @param qualifiedName 832 * 833 * 834 * 835 * @throws DOMException 836 * @see org.w3c.dom.Document as of DOM Level 2 837 */ 838 public final Element createElementNS( 839 String namespaceURI, String qualifiedName) throws DOMException 840 { 841 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 842 } 843 844 /** 845 * 846 * @param namespaceURI 847 * @param qualifiedName 848 * 849 * 850 * 851 * @throws DOMException 852 * @see org.w3c.dom.Document as of DOM Level 2 853 */ 854 public final Attr createAttributeNS( 855 String namespaceURI, String qualifiedName) throws DOMException 856 { 857 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 858 } 859 860 /** 861 * 862 * @param namespaceURI 863 * @param localName 864 * 865 * 866 * @see org.w3c.dom.Document as of DOM Level 2 867 */ 868 public final NodeList getElementsByTagNameNS(String namespaceURI, 869 String localName) 870 { 871 Vector listVector = new Vector(); 872 Node retNode = dtm.getNode(node); 873 if (retNode != null) 874 { 875 boolean isNamespaceURIWildCard = "*".equals(namespaceURI); 876 boolean isLocalNameWildCard = "*".equals(localName); 877 if (DTM.ELEMENT_NODE == retNode.getNodeType()) 878 { 879 NodeList nodeList = retNode.getChildNodes(); 880 for(int i = 0; i < nodeList.getLength(); i++) 881 { 882 traverseChildren(listVector, nodeList.item(i), namespaceURI, localName, isNamespaceURIWildCard, isLocalNameWildCard); 883 } 884 } 885 else if(DTM.DOCUMENT_NODE == retNode.getNodeType()) 886 { 887 traverseChildren(listVector, dtm.getNode(node), namespaceURI, localName, isNamespaceURIWildCard, isLocalNameWildCard); 888 } 889 } 890 int size = listVector.size(); 891 NodeSet nodeSet = new NodeSet(size); 892 for (int i = 0; i < size; i++) 893 { 894 nodeSet.addNode((Node)listVector.elementAt(i)); 895 } 896 return (NodeList) nodeSet; 897 } 898 /** 899 * 900 * @param listVector 901 * @param tempNode 902 * @param namespaceURI 903 * @param localname 904 * @param isNamespaceURIWildCard 905 * @param isLocalNameWildCard 906 * 907 * Private method to be used for recursive iterations to obtain elements by tag name 908 * and namespaceURI. 909 */ 910 private final void traverseChildren 911 ( 912 Vector listVector, 913 Node tempNode, 914 String namespaceURI, 915 String localname, 916 boolean isNamespaceURIWildCard, 917 boolean isLocalNameWildCard) 918 { 919 if (tempNode == null) 920 { 921 return; 922 } 923 else 924 { 925 if (tempNode.getNodeType() == DTM.ELEMENT_NODE 926 && (isLocalNameWildCard 927 || tempNode.getLocalName().equals(localname))) 928 { 929 String nsURI = tempNode.getNamespaceURI(); 930 if ((namespaceURI == null && nsURI == null) 931 || isNamespaceURIWildCard 932 || (namespaceURI != null && namespaceURI.equals(nsURI))) 933 { 934 listVector.add(tempNode); 935 } 936 } 937 if(tempNode.hasChildNodes()) 938 { 939 NodeList nl = tempNode.getChildNodes(); 940 for(int i = 0; i < nl.getLength(); i++) 941 { 942 traverseChildren(listVector, nl.item(i), namespaceURI, localname, 943 isNamespaceURIWildCard, isLocalNameWildCard); 944 } 945 } 946 } 947 } 948 /** 949 * 950 * @param elementId 951 * 952 * 953 * @see org.w3c.dom.Document as of DOM Level 2 954 */ 955 public final Element getElementById(String elementId) 956 { 957 return (Element) dtm.getNode(dtm.getElementById(elementId)); 958 } 959 960 /** 961 * 962 * @param offset 963 * 964 * 965 * 966 * @throws DOMException 967 * @see org.w3c.dom.Text 968 */ 969 public final Text splitText(int offset) throws DOMException 970 { 971 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 972 } 973 974 /** 975 * 976 * 977 * 978 * @throws DOMException 979 * @see org.w3c.dom.CharacterData 980 */ 981 public final String getData() throws DOMException 982 { 983 return dtm.getNodeValue(node); 984 } 985 986 /** 987 * 988 * @param data 989 * 990 * @throws DOMException 991 * @see org.w3c.dom.CharacterData 992 */ 993 public final void setData(String data) throws DOMException 994 { 995 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 996 } 997 998 /** 999 * 1000 * 1001 * @see org.w3c.dom.CharacterData 1002 */ 1003 public final int getLength() 1004 { 1005 // %OPT% This should do something smarter? 1006 return dtm.getNodeValue(node).length(); 1007 } 1008 1009 /** 1010 * 1011 * @param offset 1012 * @param count 1013 * 1014 * 1015 * 1016 * @throws DOMException 1017 * @see org.w3c.dom.CharacterData 1018 */ 1019 public final String substringData(int offset, int count) throws DOMException 1020 { 1021 return getData().substring(offset,offset+count); 1022 } 1023 1024 /** 1025 * 1026 * @param arg 1027 * 1028 * @throws DOMException 1029 * @see org.w3c.dom.CharacterData 1030 */ 1031 public final void appendData(String arg) throws DOMException 1032 { 1033 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1034 } 1035 1036 /** 1037 * 1038 * @param offset 1039 * @param arg 1040 * 1041 * @throws DOMException 1042 * @see org.w3c.dom.CharacterData 1043 */ 1044 public final void insertData(int offset, String arg) throws DOMException 1045 { 1046 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1047 } 1048 1049 /** 1050 * 1051 * @param offset 1052 * @param count 1053 * 1054 * @throws DOMException 1055 * @see org.w3c.dom.CharacterData 1056 */ 1057 public final void deleteData(int offset, int count) throws DOMException 1058 { 1059 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1060 } 1061 1062 /** 1063 * 1064 * @param offset 1065 * @param count 1066 * @param arg 1067 * 1068 * @throws DOMException 1069 * @see org.w3c.dom.CharacterData 1070 */ 1071 public final void replaceData(int offset, int count, String arg) 1072 throws DOMException 1073 { 1074 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1075 } 1076 1077 /** 1078 * 1079 * 1080 * @see org.w3c.dom.Element 1081 */ 1082 public final String getTagName() 1083 { 1084 return dtm.getNodeName(node); 1085 } 1086 1087 /** 1088 * 1089 * @param name 1090 * 1091 * 1092 * @see org.w3c.dom.Element 1093 */ 1094 public final String getAttribute(String name) 1095 { 1096 1097 DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node); 1098 Node node = map.getNamedItem(name); 1099 return (null == node) ? EMPTYSTRING : node.getNodeValue(); } 1100 1101 /** 1102 * 1103 * @param name 1104 * @param value 1105 * 1106 * @throws DOMException 1107 * @see org.w3c.dom.Element 1108 */ 1109 public final void setAttribute(String name, String value) 1110 throws DOMException 1111 { 1112 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1113 } 1114 1115 /** 1116 * 1117 * @param name 1118 * 1119 * @throws DOMException 1120 * @see org.w3c.dom.Element 1121 */ 1122 public final void removeAttribute(String name) throws DOMException 1123 { 1124 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1125 } 1126 1127 /** 1128 * 1129 * @param name 1130 * 1131 * 1132 * @see org.w3c.dom.Element 1133 */ 1134 public final Attr getAttributeNode(String name) 1135 { 1136 1137 DTMNamedNodeMap map = new DTMNamedNodeMap(dtm, node); 1138 return (Attr)map.getNamedItem(name); 1139 } 1140 1141 /** 1142 * 1143 * @param newAttr 1144 * 1145 * 1146 * 1147 * @throws DOMException 1148 * @see org.w3c.dom.Element 1149 */ 1150 public final Attr setAttributeNode(Attr newAttr) throws DOMException 1151 { 1152 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1153 } 1154 1155 /** 1156 * 1157 * @param oldAttr 1158 * 1159 * 1160 * 1161 * @throws DOMException 1162 * @see org.w3c.dom.Element 1163 */ 1164 public final Attr removeAttributeNode(Attr oldAttr) throws DOMException 1165 { 1166 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1167 } 1168 1169 /** 1170 * Introduced in DOM Level 2. 1171 * 1172 * 1173 */ 1174 public boolean hasAttributes() 1175 { 1176 return DTM.NULL != dtm.getFirstAttribute(node); 1177 } 1178 1179 /** @see org.w3c.dom.Element */ 1180 public final void normalize() 1181 { 1182 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1183 } 1184 1185 /** 1186 * 1187 * @param namespaceURI 1188 * @param localName 1189 * 1190 * 1191 * @see org.w3c.dom.Element 1192 */ 1193 public final String getAttributeNS(String namespaceURI, String localName) 1194 { 1195 Node retNode = null; 1196 int n = dtm.getAttributeNode(node,namespaceURI,localName); 1197 if(n != DTM.NULL) 1198 retNode = dtm.getNode(n); 1199 return (null == retNode) ? EMPTYSTRING : retNode.getNodeValue(); 1200 } 1201 1202 /** 1203 * 1204 * @param namespaceURI 1205 * @param qualifiedName 1206 * @param value 1207 * 1208 * @throws DOMException 1209 * @see org.w3c.dom.Element 1210 */ 1211 public final void setAttributeNS( 1212 String namespaceURI, String qualifiedName, String value) 1213 throws DOMException 1214 { 1215 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1216 } 1217 1218 /** 1219 * 1220 * @param namespaceURI 1221 * @param localName 1222 * 1223 * @throws DOMException 1224 * @see org.w3c.dom.Element 1225 */ 1226 public final void removeAttributeNS(String namespaceURI, String localName) 1227 throws DOMException 1228 { 1229 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1230 } 1231 1232 /** 1233 * 1234 * @param namespaceURI 1235 * @param localName 1236 * 1237 * 1238 * @see org.w3c.dom.Element 1239 */ 1240 public final Attr getAttributeNodeNS(String namespaceURI, String localName) 1241 { 1242 Attr retAttr = null; 1243 int n = dtm.getAttributeNode(node,namespaceURI,localName); 1244 if(n != DTM.NULL) 1245 retAttr = (Attr) dtm.getNode(n); 1246 return retAttr; 1247 1248 } 1249 1250 /** 1251 * 1252 * @param newAttr 1253 * 1254 * 1255 * 1256 * @throws DOMException 1257 * @see org.w3c.dom.Element 1258 */ 1259 public final Attr setAttributeNodeNS(Attr newAttr) throws DOMException 1260 { 1261 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1262 } 1263 1264 /** 1265 * 1266 * 1267 * @see org.w3c.dom.Attr 1268 */ 1269 public final String getName() 1270 { 1271 return dtm.getNodeName(node); 1272 } 1273 1274 /** 1275 * 1276 * 1277 * @see org.w3c.dom.Attr 1278 */ 1279 public final boolean getSpecified() 1280 { 1281 // We really don't know which attributes might have come from the 1282 // source document versus from the DTD. Treat them all as having 1283 // been provided by the user. 1284 // %REVIEW% if/when we become aware of DTDs/schemae. 1285 return true; 1286 } 1287 1288 /** 1289 * 1290 * 1291 * @see org.w3c.dom.Attr 1292 */ 1293 public final String getValue() 1294 { 1295 return dtm.getNodeValue(node); 1296 } 1297 1298 /** 1299 * 1300 * @param value 1301 * @see org.w3c.dom.Attr 1302 */ 1303 public final void setValue(String value) 1304 { 1305 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1306 } 1307 1308 /** 1309 * Get the owner element of an attribute. 1310 * 1311 * 1312 * @see org.w3c.dom.Attr as of DOM Level 2 1313 */ 1314 public final Element getOwnerElement() 1315 { 1316 if (getNodeType() != Node.ATTRIBUTE_NODE) 1317 return null; 1318 // In XPath and DTM data models, unlike DOM, an Attr's parent is its 1319 // owner element. 1320 int newnode = dtm.getParent(node); 1321 return (newnode == DTM.NULL) ? null : (Element)(dtm.getNode(newnode)); 1322 } 1323 1324 /** 1325 * NEEDSDOC Method adoptNode 1326 * 1327 * 1328 * NEEDSDOC @param source 1329 * 1330 * NEEDSDOC (adoptNode) @return 1331 * 1332 * @throws DOMException 1333 */ 1334 public Node adoptNode(Node source) throws DOMException 1335 { 1336 1337 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1338 } 1339 1340 /** 1341 * <p>EXPERIMENTAL! Based on the <a 1342 * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document 1343 * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>. 1344 * <p> 1345 * An attribute specifying, as part of the XML declaration, the encoding 1346 * of this document. This is <code>null</code> when unspecified. 1347 * @since DOM Level 3 1348 * 1349 * NEEDSDOC ($objectName$) @return 1350 */ 1351 public String getInputEncoding() 1352 { 1353 1354 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1355 } 1356 1357 /** 1358 * <p>EXPERIMENTAL! Based on the <a 1359 * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document 1360 * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>. 1361 * <p> 1362 * An attribute specifying, as part of the XML declaration, the encoding 1363 * of this document. This is <code>null</code> when unspecified. 1364 * @since DOM Level 3 1365 * 1366 * NEEDSDOC @param encoding 1367 */ 1368 public void setEncoding(String encoding) 1369 { 1370 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1371 } 1372 1373 /** 1374 * <p>EXPERIMENTAL! Based on the <a 1375 * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document 1376 * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>. 1377 * <p> 1378 * An attribute specifying, as part of the XML declaration, whether this 1379 * document is standalone. 1380 * @since DOM Level 3 1381 * 1382 * NEEDSDOC ($objectName$) @return 1383 */ 1384 public boolean getStandalone() 1385 { 1386 1387 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1388 } 1389 1390 /** 1391 * <p>EXPERIMENTAL! Based on the <a 1392 * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document 1393 * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>. 1394 * <p> 1395 * An attribute specifying, as part of the XML declaration, whether this 1396 * document is standalone. 1397 * @since DOM Level 3 1398 * 1399 * NEEDSDOC @param standalone 1400 */ 1401 public void setStandalone(boolean standalone) 1402 { 1403 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1404 } 1405 1406 /** 1407 * <p>EXPERIMENTAL! Based on the <a 1408 * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document 1409 * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>. 1410 * <p> 1411 * An attribute specifying whether errors checking is enforced or not. 1412 * When set to <code>false</code>, the implementation is free to not 1413 * test every possible error case normally defined on DOM operations, 1414 * and not raise any <code>DOMException</code>. In case of error, the 1415 * behavior is undefined. This attribute is <code>true</code> by 1416 * defaults. 1417 * @since DOM Level 3 1418 * 1419 * NEEDSDOC ($objectName$) @return 1420 */ 1421 public boolean getStrictErrorChecking() 1422 { 1423 1424 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1425 } 1426 1427 /** 1428 * <p>EXPERIMENTAL! Based on the <a 1429 * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document 1430 * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>. 1431 * <p> 1432 * An attribute specifying whether errors checking is enforced or not. 1433 * When set to <code>false</code>, the implementation is free to not 1434 * test every possible error case normally defined on DOM operations, 1435 * and not raise any <code>DOMException</code>. In case of error, the 1436 * behavior is undefined. This attribute is <code>true</code> by 1437 * defaults. 1438 * @since DOM Level 3 1439 * 1440 * NEEDSDOC @param strictErrorChecking 1441 */ 1442 public void setStrictErrorChecking(boolean strictErrorChecking) 1443 { 1444 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1445 } 1446 1447 /** 1448 * <p>EXPERIMENTAL! Based on the <a 1449 * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document 1450 * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>. 1451 * <p> 1452 * An attribute specifying, as part of the XML declaration, the version 1453 * number of this document. This is <code>null</code> when unspecified. 1454 * @since DOM Level 3 1455 * 1456 * NEEDSDOC ($objectName$) @return 1457 */ 1458 public String getVersion() 1459 { 1460 1461 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1462 } 1463 1464 /** 1465 * <p>EXPERIMENTAL! Based on the <a 1466 * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document 1467 * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>. 1468 * <p> 1469 * An attribute specifying, as part of the XML declaration, the version 1470 * number of this document. This is <code>null</code> when unspecified. 1471 * @since DOM Level 3 1472 * 1473 * NEEDSDOC @param version 1474 */ 1475 public void setVersion(String version) 1476 { 1477 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1478 } 1479 1480 1481 /** Inner class to support getDOMImplementation. 1482 */ 1483 static class DTMNodeProxyImplementation implements DOMImplementation 1484 { 1485 public DocumentType createDocumentType(String qualifiedName,String publicId, String systemId) 1486 { 1487 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1488 } 1489 public Document createDocument(String namespaceURI,String qualfiedName,DocumentType doctype) 1490 { 1491 // Could create a DTM... but why, when it'd have to be permanantly empty? 1492 throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); 1493 } 1494 /** Ask whether we support a given DOM feature. 1495 * 1496 * In fact, we do not _fully_ support any DOM feature -- we're a 1497 * read-only subset -- so arguably we should always return false. 1498 * On the other hand, it may be more practically useful to return 1499 * true and simply treat the whole DOM as read-only, failing on the 1500 * methods we can't support. I'm not sure which would be more useful 1501 * to the caller. 1502 */ 1503 public boolean hasFeature(String feature,String version) 1504 { 1505 if( ("CORE".equals(feature.toUpperCase()) || "XML".equals(feature.toUpperCase())) 1506 && 1507 ("1.0".equals(version) || "2.0".equals(version))) 1508 return true; 1509 return false; 1510 } 1511 1512 /** 1513 * This method returns a specialized object which implements the 1514 * specialized APIs of the specified feature and version. The 1515 * specialized object may also be obtained by using binding-specific 1516 * casting methods but is not necessarily expected to, as discussed in Mixed DOM implementations 1517 . 1518 * @param feature The name of the feature requested (case-insensitive). 1519 * @param version This is the version number of the feature to test. If 1520 * the version is <code>null</code> or the empty string, supporting 1521 * any version of the feature will cause the method to return an 1522 * object that supports at least one version of the feature. 1523 * @return Returns an object which implements the specialized APIs of 1524 * the specified feature and version, if any, or <code>null</code> if 1525 * there is no object which implements interfaces associated with that 1526 * feature. If the <code>DOMObject</code> returned by this method 1527 * implements the <code>Node</code> interface, it must delegate to the 1528 * primary core <code>Node</code> and not return results inconsistent 1529 * with the primary core <code>Node</code> such as attributes, 1530 * childNodes, etc. 1531 * @since DOM Level 3 1532 */ 1533 public Object getFeature(String feature, String version) { 1534 // we don't have any alternate node, either this node does the job 1535 // or we don't have anything that does 1536 //return hasFeature(feature, version) ? this : null; 1537 return null; //PENDING 1538 } 1539 1540 } 1541 1542 1543 //RAMESH : Pending proper implementation of DOM Level 3 1544 1545 public Object setUserData(String key, 1546 Object data, 1547 UserDataHandler handler) { 1548 return getOwnerDocument().setUserData( key, data, handler); 1549 } 1550 1551 /** 1552 * Retrieves the object associated to a key on a this node. The object 1553 * must first have been set to this node by calling 1554 * <code>setUserData</code> with the same key. 1555 * @param key The key the object is associated to. 1556 * @return Returns the <code>DOMObject</code> associated to the given key 1557 * on this node, or <code>null</code> if there was none. 1558 * @since DOM Level 3 1559 */ 1560 public Object getUserData(String key) { 1561 return getOwnerDocument().getUserData( key); 1562 } 1563 1564 /** 1565 * This method returns a specialized object which implements the 1566 * specialized APIs of the specified feature and version. The 1567 * specialized object may also be obtained by using binding-specific 1568 * casting methods but is not necessarily expected to, as discussed in Mixed DOM implementations. 1569 * @param feature The name of the feature requested (case-insensitive). 1570 * @param version This is the version number of the feature to test. If 1571 * the version is <code>null</code> or the empty string, supporting 1572 * any version of the feature will cause the method to return an 1573 * object that supports at least one version of the feature. 1574 * @return Returns an object which implements the specialized APIs of 1575 * the specified feature and version, if any, or <code>null</code> if 1576 * there is no object which implements interfaces associated with that 1577 * feature. If the <code>DOMObject</code> returned by this method 1578 * implements the <code>Node</code> interface, it must delegate to the 1579 * primary core <code>Node</code> and not return results inconsistent 1580 * with the primary core <code>Node</code> such as attributes, 1581 * childNodes, etc. 1582 * @since DOM Level 3 1583 */ 1584 public Object getFeature(String feature, String version) { 1585 // we don't have any alternate node, either this node does the job 1586 // or we don't have anything that does 1587 return isSupported(feature, version) ? this : null; 1588 } 1589 1590 /** 1591 * Tests whether two nodes are equal. 1592 * <br>This method tests for equality of nodes, not sameness (i.e., 1593 * whether the two nodes are references to the same object) which can be 1594 * tested with <code>Node.isSameNode</code>. All nodes that are the same 1595 * will also be equal, though the reverse may not be true. 1596 * <br>Two nodes are equal if and only if the following conditions are 1597 * satisfied: The two nodes are of the same type.The following string 1598 * attributes are equal: <code>nodeName</code>, <code>localName</code>, 1599 * <code>namespaceURI</code>, <code>prefix</code>, <code>nodeValue</code> 1600 * , <code>baseURI</code>. This is: they are both <code>null</code>, or 1601 * they have the same length and are character for character identical. 1602 * The <code>attributes</code> <code>NamedNodeMaps</code> are equal. 1603 * This is: they are both <code>null</code>, or they have the same 1604 * length and for each node that exists in one map there is a node that 1605 * exists in the other map and is equal, although not necessarily at the 1606 * same index.The <code>childNodes</code> <code>NodeLists</code> are 1607 * equal. This is: they are both <code>null</code>, or they have the 1608 * same length and contain equal nodes at the same index. This is true 1609 * for <code>Attr</code> nodes as for any other type of node. Note that 1610 * normalization can affect equality; to avoid this, nodes should be 1611 * normalized before being compared. 1612 * <br>For two <code>DocumentType</code> nodes to be equal, the following 1613 * conditions must also be satisfied: The following string attributes 1614 * are equal: <code>publicId</code>, <code>systemId</code>, 1615 * <code>internalSubset</code>.The <code>entities</code> 1616 * <code>NamedNodeMaps</code> are equal.The <code>notations</code> 1617 * <code>NamedNodeMaps</code> are equal. 1618 * <br>On the other hand, the following do not affect equality: the 1619 * <code>ownerDocument</code> attribute, the <code>specified</code> 1620 * attribute for <code>Attr</code> nodes, the 1621 * <code>isWhitespaceInElementContent</code> attribute for 1622 * <code>Text</code> nodes, as well as any user data or event listeners 1623 * registered on the nodes. 1624 * @param arg The node to compare equality with. 1625 * @param deep If <code>true</code>, recursively compare the subtrees; if 1626 * <code>false</code>, compare only the nodes themselves (and its 1627 * attributes, if it is an <code>Element</code>). 1628 * @return If the nodes, and possibly subtrees are equal, 1629 * <code>true</code> otherwise <code>false</code>. 1630 * @since DOM Level 3 1631 */ 1632 public boolean isEqualNode(Node arg) { 1633 if (arg == this) { 1634 return true; 1635 } 1636 if (arg.getNodeType() != getNodeType()) { 1637 return false; 1638 } 1639 // in theory nodeName can't be null but better be careful 1640 // who knows what other implementations may be doing?... 1641 if (getNodeName() == null) { 1642 if (arg.getNodeName() != null) { 1643 return false; 1644 } 1645 } 1646 else if (!getNodeName().equals(arg.getNodeName())) { 1647 return false; 1648 } 1649 1650 if (getLocalName() == null) { 1651 if (arg.getLocalName() != null) { 1652 return false; 1653 } 1654 } 1655 else if (!getLocalName().equals(arg.getLocalName())) { 1656 return false; 1657 } 1658 1659 if (getNamespaceURI() == null) { 1660 if (arg.getNamespaceURI() != null) { 1661 return false; 1662 } 1663 } 1664 else if (!getNamespaceURI().equals(arg.getNamespaceURI())) { 1665 return false; 1666 } 1667 1668 if (getPrefix() == null) { 1669 if (arg.getPrefix() != null) { 1670 return false; 1671 } 1672 } 1673 else if (!getPrefix().equals(arg.getPrefix())) { 1674 return false; 1675 } 1676 1677 if (getNodeValue() == null) { 1678 if (arg.getNodeValue() != null) { 1679 return false; 1680 } 1681 } 1682 else if (!getNodeValue().equals(arg.getNodeValue())) { 1683 return false; 1684 } 1685 /* 1686 if (getBaseURI() == null) { 1687 if (((NodeImpl) arg).getBaseURI() != null) { 1688 return false; 1689 } 1690 } 1691 else if (!getBaseURI().equals(((NodeImpl) arg).getBaseURI())) { 1692 return false; 1693 } 1694 */ 1695 1696 return true; 1697 } 1698 1699 /** 1700 * DOM Level 3 1701 * Look up the namespace URI associated to the given prefix, starting from this node. 1702 * Use lookupNamespaceURI(null) to lookup the default namespace 1703 * 1704 * @param namespaceURI 1705 * @return th URI for the namespace 1706 * @since DOM Level 3 1707 */ 1708 public String lookupNamespaceURI(String specifiedPrefix) { 1709 short type = this.getNodeType(); 1710 switch (type) { 1711 case Node.ELEMENT_NODE : { 1712 1713 String namespace = this.getNamespaceURI(); 1714 String prefix = this.getPrefix(); 1715 if (namespace !=null) { 1716 // REVISIT: is it possible that prefix is empty string? 1717 if (specifiedPrefix== null && prefix==specifiedPrefix) { 1718 // looking for default namespace 1719 return namespace; 1720 } else if (prefix != null && prefix.equals(specifiedPrefix)) { 1721 // non default namespace 1722 return namespace; 1723 } 1724 } 1725 if (this.hasAttributes()) { 1726 NamedNodeMap map = this.getAttributes(); 1727 int length = map.getLength(); 1728 for (int i=0;i<length;i++) { 1729 Node attr = map.item(i); 1730 String attrPrefix = attr.getPrefix(); 1731 String value = attr.getNodeValue(); 1732 namespace = attr.getNamespaceURI(); 1733 if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) { 1734 // at this point we are dealing with DOM Level 2 nodes only 1735 if (specifiedPrefix == null && 1736 attr.getNodeName().equals("xmlns")) { 1737 // default namespace 1738 return value; 1739 } else if (attrPrefix !=null && 1740 attrPrefix.equals("xmlns") && 1741 attr.getLocalName().equals(specifiedPrefix)) { 1742 // non default namespace 1743 return value; 1744 } 1745 } 1746 } 1747 } 1748 /* 1749 NodeImpl ancestor = (NodeImpl)getElementAncestor(this); 1750 if (ancestor != null) { 1751 return ancestor.lookupNamespaceURI(specifiedPrefix); 1752 } 1753 */ 1754 1755 return null; 1756 1757 1758 } 1759 /* 1760 case Node.DOCUMENT_NODE : { 1761 return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ; 1762 } 1763 */ 1764 case Node.ENTITY_NODE : 1765 case Node.NOTATION_NODE: 1766 case Node.DOCUMENT_FRAGMENT_NODE: 1767 case Node.DOCUMENT_TYPE_NODE: 1768 // type is unknown 1769 return null; 1770 case Node.ATTRIBUTE_NODE:{ 1771 if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { 1772 return getOwnerElement().lookupNamespaceURI(specifiedPrefix); 1773 1774 } 1775 return null; 1776 } 1777 default:{ 1778 /* 1779 NodeImpl ancestor = (NodeImpl)getElementAncestor(this); 1780 if (ancestor != null) { 1781 return ancestor.lookupNamespaceURI(specifiedPrefix); 1782 } 1783 */ 1784 return null; 1785 } 1786 1787 } 1788 } 1789 1790 1791 /** 1792 * DOM Level 3 1793 * This method checks if the specified <code>namespaceURI</code> is the 1794 * default namespace or not. 1795 * @param namespaceURI The namespace URI to look for. 1796 * @return <code>true</code> if the specified <code>namespaceURI</code> 1797 * is the default namespace, <code>false</code> otherwise. 1798 * @since DOM Level 3 1799 */ 1800 public boolean isDefaultNamespace(String namespaceURI){ 1801 /* 1802 // REVISIT: remove casts when DOM L3 becomes REC. 1803 short type = this.getNodeType(); 1804 switch (type) { 1805 case Node.ELEMENT_NODE: { 1806 String namespace = this.getNamespaceURI(); 1807 String prefix = this.getPrefix(); 1808 1809 // REVISIT: is it possible that prefix is empty string? 1810 if (prefix == null || prefix.length() == 0) { 1811 if (namespaceURI == null) { 1812 return (namespace == namespaceURI); 1813 } 1814 return namespaceURI.equals(namespace); 1815 } 1816 if (this.hasAttributes()) { 1817 ElementImpl elem = (ElementImpl)this; 1818 NodeImpl attr = (NodeImpl)elem.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "xmlns"); 1819 if (attr != null) { 1820 String value = attr.getNodeValue(); 1821 if (namespaceURI == null) { 1822 return (namespace == value); 1823 } 1824 return namespaceURI.equals(value); 1825 } 1826 } 1827 1828 NodeImpl ancestor = (NodeImpl)getElementAncestor(this); 1829 if (ancestor != null) { 1830 return ancestor.isDefaultNamespace(namespaceURI); 1831 } 1832 return false; 1833 } 1834 case Node.DOCUMENT_NODE:{ 1835 return((NodeImpl)((Document)this).getDocumentElement()).isDefaultNamespace(namespaceURI); 1836 } 1837 1838 case Node.ENTITY_NODE : 1839 case Node.NOTATION_NODE: 1840 case Node.DOCUMENT_FRAGMENT_NODE: 1841 case Node.DOCUMENT_TYPE_NODE: 1842 // type is unknown 1843 return false; 1844 case Node.ATTRIBUTE_NODE:{ 1845 if (this.ownerNode.getNodeType() == Node.ELEMENT_NODE) { 1846 return ownerNode.isDefaultNamespace(namespaceURI); 1847 1848 } 1849 return false; 1850 } 1851 default:{ 1852 NodeImpl ancestor = (NodeImpl)getElementAncestor(this); 1853 if (ancestor != null) { 1854 return ancestor.isDefaultNamespace(namespaceURI); 1855 } 1856 return false; 1857 } 1858 1859 } 1860 */ 1861 return false; 1862 1863 1864 } 1865 1866 /** 1867 * 1868 * DOM Level 3 1869 * Look up the prefix associated to the given namespace URI, starting from this node. 1870 * 1871 * @param namespaceURI 1872 * @return the prefix for the namespace 1873 */ 1874 public String lookupPrefix(String namespaceURI){ 1875 1876 // REVISIT: When Namespaces 1.1 comes out this may not be true 1877 // Prefix can't be bound to null namespace 1878 if (namespaceURI == null) { 1879 return null; 1880 } 1881 1882 short type = this.getNodeType(); 1883 1884 switch (type) { 1885 /* 1886 case Node.ELEMENT_NODE: { 1887 1888 String namespace = this.getNamespaceURI(); // to flip out children 1889 return lookupNamespacePrefix(namespaceURI, (ElementImpl)this); 1890 } 1891 1892 case Node.DOCUMENT_NODE:{ 1893 return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI); 1894 } 1895 */ 1896 case Node.ENTITY_NODE : 1897 case Node.NOTATION_NODE: 1898 case Node.DOCUMENT_FRAGMENT_NODE: 1899 case Node.DOCUMENT_TYPE_NODE: 1900 // type is unknown 1901 return null; 1902 case Node.ATTRIBUTE_NODE:{ 1903 if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { 1904 return getOwnerElement().lookupPrefix(namespaceURI); 1905 1906 } 1907 return null; 1908 } 1909 default:{ 1910 /* 1911 NodeImpl ancestor = (NodeImpl)getElementAncestor(this); 1912 if (ancestor != null) { 1913 return ancestor.lookupPrefix(namespaceURI); 1914 } 1915 */ 1916 return null; 1917 } 1918 } 1919 } 1920 1921 /** 1922 * Returns whether this node is the same node as the given one. 1923 * <br>This method provides a way to determine whether two 1924 * <code>Node</code> references returned by the implementation reference 1925 * the same object. When two <code>Node</code> references are references 1926 * to the same object, even if through a proxy, the references may be 1927 * used completely interchangably, such that all attributes have the 1928 * same values and calling the same DOM method on either reference 1929 * always has exactly the same effect. 1930 * @param other The node to test against. 1931 * @return Returns <code>true</code> if the nodes are the same, 1932 * <code>false</code> otherwise. 1933 * @since DOM Level 3 1934 */ 1935 public boolean isSameNode(Node other) { 1936 // we do not use any wrapper so the answer is obvious 1937 return this == other; 1938 } 1939 1940 /** 1941 * This attribute returns the text content of this node and its 1942 * descendants. When it is defined to be null, setting it has no effect. 1943 * When set, any possible children this node may have are removed and 1944 * replaced by a single <code>Text</code> node containing the string 1945 * this attribute is set to. On getting, no serialization is performed, 1946 * the returned string does not contain any markup. No whitespace 1947 * normalization is performed, the returned string does not contain the 1948 * element content whitespaces . Similarly, on setting, no parsing is 1949 * performed either, the input string is taken as pure textual content. 1950 * <br>The string returned is made of the text content of this node 1951 * depending on its type, as defined below: 1952 * <table border='1'> 1953 * <tr> 1954 * <th>Node type</th> 1955 * <th>Content</th> 1956 * </tr> 1957 * <tr> 1958 * <td valign='top' rowspan='1' colspan='1'> 1959 * ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, 1960 * DOCUMENT_FRAGMENT_NODE</td> 1961 * <td valign='top' rowspan='1' colspan='1'>concatenation of the <code>textContent</code> 1962 * attribute value of every child node, excluding COMMENT_NODE and 1963 * PROCESSING_INSTRUCTION_NODE nodes</td> 1964 * </tr> 1965 * <tr> 1966 * <td valign='top' rowspan='1' colspan='1'>ATTRIBUTE_NODE, TEXT_NODE, 1967 * CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE</td> 1968 * <td valign='top' rowspan='1' colspan='1'> 1969 * <code>nodeValue</code></td> 1970 * </tr> 1971 * <tr> 1972 * <td valign='top' rowspan='1' colspan='1'>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td> 1973 * <td valign='top' rowspan='1' colspan='1'> 1974 * null</td> 1975 * </tr> 1976 * </table> 1977 * @exception DOMException 1978 * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. 1979 * @exception DOMException 1980 * DOMSTRING_SIZE_ERR: Raised when it would return more characters than 1981 * fit in a <code>DOMString</code> variable on the implementation 1982 * platform. 1983 * @since DOM Level 3 1984 */ 1985 public void setTextContent(String textContent) 1986 throws DOMException { 1987 setNodeValue(textContent); 1988 } 1989 /** 1990 * This attribute returns the text content of this node and its 1991 * descendants. When it is defined to be null, setting it has no effect. 1992 * When set, any possible children this node may have are removed and 1993 * replaced by a single <code>Text</code> node containing the string 1994 * this attribute is set to. On getting, no serialization is performed, 1995 * the returned string does not contain any markup. No whitespace 1996 * normalization is performed, the returned string does not contain the 1997 * element content whitespaces . Similarly, on setting, no parsing is 1998 * performed either, the input string is taken as pure textual content. 1999 * <br>The string returned is made of the text content of this node 2000 * depending on its type, as defined below: 2001 * <table border='1'> 2002 * <tr> 2003 * <th>Node type</th> 2004 * <th>Content</th> 2005 * </tr> 2006 * <tr> 2007 * <td valign='top' rowspan='1' colspan='1'> 2008 * ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, 2009 * DOCUMENT_FRAGMENT_NODE</td> 2010 * <td valign='top' rowspan='1' colspan='1'>concatenation of the <code>textContent</code> 2011 * attribute value of every child node, excluding COMMENT_NODE and 2012 * PROCESSING_INSTRUCTION_NODE nodes</td> 2013 * </tr> 2014 * <tr> 2015 * <td valign='top' rowspan='1' colspan='1'>ATTRIBUTE_NODE, TEXT_NODE, 2016 * CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE</td> 2017 * <td valign='top' rowspan='1' colspan='1'> 2018 * <code>nodeValue</code></td> 2019 * </tr> 2020 * <tr> 2021 * <td valign='top' rowspan='1' colspan='1'>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td> 2022 * <td valign='top' rowspan='1' colspan='1'> 2023 * null</td> 2024 * </tr> 2025 * </table> 2026 * @exception DOMException 2027 * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. 2028 * @exception DOMException 2029 * DOMSTRING_SIZE_ERR: Raised when it would return more characters than 2030 * fit in a <code>DOMString</code> variable on the implementation 2031 * platform. 2032 * @since DOM Level 3 2033 */ 2034 public String getTextContent() throws DOMException { 2035 return getNodeValue(); // overriden in some subclasses 2036 } 2037 2038 /** 2039 * Compares a node with this node with regard to their position in the 2040 * document. 2041 * @param other The node to compare against this node. 2042 * @return Returns how the given node is positioned relatively to this 2043 * node. 2044 * @since DOM Level 3 2045 */ 2046 public short compareDocumentPosition(Node other) throws DOMException { 2047 return 0; 2048 } 2049 2050 /** 2051 * The absolute base URI of this node or <code>null</code> if undefined. 2052 * This value is computed according to . However, when the 2053 * <code>Document</code> supports the feature "HTML" , the base URI is 2054 * computed using first the value of the href attribute of the HTML BASE 2055 * element if any, and the value of the <code>documentURI</code> 2056 * attribute from the <code>Document</code> interface otherwise. 2057 * <br> When the node is an <code>Element</code>, a <code>Document</code> 2058 * or a a <code>ProcessingInstruction</code>, this attribute represents 2059 * the properties [base URI] defined in . When the node is a 2060 * <code>Notation</code>, an <code>Entity</code>, or an 2061 * <code>EntityReference</code>, this attribute represents the 2062 * properties [declaration base URI] in the . How will this be affected 2063 * by resolution of relative namespace URIs issue?It's not.Should this 2064 * only be on Document, Element, ProcessingInstruction, Entity, and 2065 * Notation nodes, according to the infoset? If not, what is it equal to 2066 * on other nodes? Null? An empty string? I think it should be the 2067 * parent's.No.Should this be read-only and computed or and actual 2068 * read-write attribute?Read-only and computed (F2F 19 Jun 2000 and 2069 * teleconference 30 May 2001).If the base HTML element is not yet 2070 * attached to a document, does the insert change the Document.baseURI? 2071 * Yes. (F2F 26 Sep 2001) 2072 * @since DOM Level 3 2073 */ 2074 public String getBaseURI() { 2075 return null; 2076 } 2077 2078 /** 2079 * DOM Level 3 2080 * Renaming node 2081 */ 2082 public Node renameNode(Node n, 2083 String namespaceURI, 2084 String name) 2085 throws DOMException{ 2086 return n; 2087 } 2088 2089 2090 /** 2091 * DOM Level 3 2092 * Normalize document. 2093 */ 2094 public void normalizeDocument(){ 2095 2096 } 2097 /** 2098 * The configuration used when <code>Document.normalizeDocument</code> is 2099 * invoked. 2100 * @since DOM Level 3 2101 */ 2102 public DOMConfiguration getDomConfig(){ 2103 return null; 2104 } 2105 2106 2107 /** DOM Level 3 feature: documentURI */ 2108 protected String fDocumentURI; 2109 2110 /** 2111 * DOM Level 3 2112 */ 2113 public void setDocumentURI(String documentURI){ 2114 2115 fDocumentURI= documentURI; 2116 } 2117 2118 /** 2119 * DOM Level 3 2120 * The location of the document or <code>null</code> if undefined. 2121 * <br>Beware that when the <code>Document</code> supports the feature 2122 * "HTML" , the href attribute of the HTML BASE element takes precedence 2123 * over this attribute. 2124 * @since DOM Level 3 2125 */ 2126 public String getDocumentURI(){ 2127 return fDocumentURI; 2128 } 2129 2130 /**DOM Level 3 feature: Document actualEncoding */ 2131 protected String actualEncoding; 2132 2133 /** 2134 * DOM Level 3 2135 * An attribute specifying the actual encoding of this document. This is 2136 * <code>null</code> otherwise. 2137 * <br> This attribute represents the property [character encoding scheme] 2138 * defined in . 2139 * @since DOM Level 3 2140 */ 2141 public String getActualEncoding() { 2142 return actualEncoding; 2143 } 2144 2145 /** 2146 * DOM Level 3 2147 * An attribute specifying the actual encoding of this document. This is 2148 * <code>null</code> otherwise. 2149 * <br> This attribute represents the property [character encoding scheme] 2150 * defined in . 2151 * @since DOM Level 3 2152 */ 2153 public void setActualEncoding(String value) { 2154 actualEncoding = value; 2155 } 2156 2157 /** 2158 * DOM Level 3 2159 */ 2160 public Text replaceWholeText(String content) 2161 throws DOMException{ 2162 /* 2163 2164 if (needsSyncData()) { 2165 synchronizeData(); 2166 } 2167 2168 // make sure we can make the replacement 2169 if (!canModify(nextSibling)) { 2170 throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, 2171 DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null)); 2172 } 2173 2174 Node parent = this.getParentNode(); 2175 if (content == null || content.length() == 0) { 2176 // remove current node 2177 if (parent !=null) { // check if node in the tree 2178 parent.removeChild(this); 2179 return null; 2180 } 2181 } 2182 Text currentNode = null; 2183 if (isReadOnly()){ 2184 Text newNode = this.ownerDocument().createTextNode(content); 2185 if (parent !=null) { // check if node in the tree 2186 parent.insertBefore(newNode, this); 2187 parent.removeChild(this); 2188 currentNode = newNode; 2189 } else { 2190 return newNode; 2191 } 2192 } else { 2193 this.setData(content); 2194 currentNode = this; 2195 } 2196 Node sibling = currentNode.getNextSibling(); 2197 while ( sibling !=null) { 2198 parent.removeChild(sibling); 2199 sibling = currentNode.getNextSibling(); 2200 } 2201 2202 return currentNode; 2203 */ 2204 return null; //Pending 2205 } 2206 2207 /** 2208 * DOM Level 3 2209 * Returns all text of <code>Text</code> nodes logically-adjacent text 2210 * nodes to this node, concatenated in document order. 2211 * @since DOM Level 3 2212 */ 2213 public String getWholeText(){ 2214 2215 /* 2216 if (needsSyncData()) { 2217 synchronizeData(); 2218 } 2219 if (nextSibling == null) { 2220 return data; 2221 } 2222 StringBuffer buffer = new StringBuffer(); 2223 if (data != null && data.length() != 0) { 2224 buffer.append(data); 2225 } 2226 getWholeText(nextSibling, buffer); 2227 return buffer.toString(); 2228 */ 2229 return null; // PENDING 2230 2231 } 2232 2233 /** 2234 * DOM Level 3 2235 * Returns whether this text node contains whitespace in element content, 2236 * often abusively called "ignorable whitespace". 2237 */ 2238 public boolean isElementContentWhitespace(){ 2239 return false; 2240 } 2241 2242 2243 2244 2245 /** 2246 * NON-DOM: set the type of this attribute to be ID type. 2247 * 2248 * @param id 2249 */ 2250 public void setIdAttribute(boolean id){ 2251 //PENDING 2252 } 2253 2254 /** 2255 * DOM Level 3: register the given attribute node as an ID attribute 2256 */ 2257 public void setIdAttribute(String name, boolean makeId) { 2258 //PENDING 2259 } 2260 2261 2262 /** 2263 * DOM Level 3: register the given attribute node as an ID attribute 2264 */ 2265 public void setIdAttributeNode(Attr at, boolean makeId) { 2266 //PENDING 2267 } 2268 2269 /** 2270 * DOM Level 3: register the given attribute node as an ID attribute 2271 */ 2272 public void setIdAttributeNS(String namespaceURI, String localName, 2273 boolean makeId) { 2274 //PENDING 2275 } 2276 /** 2277 * Method getSchemaTypeInfo. 2278 * @return TypeInfo 2279 */ 2280 public TypeInfo getSchemaTypeInfo(){ 2281 return null; //PENDING 2282 } 2283 2284 public boolean isId() { 2285 return false; //PENDING 2286 } 2287 2288 2289 private String xmlEncoding; 2290 public String getXmlEncoding( ) { 2291 return xmlEncoding; 2292 } 2293 public void setXmlEncoding( String xmlEncoding ) { 2294 this.xmlEncoding = xmlEncoding; 2295 } 2296 2297 private boolean xmlStandalone; 2298 public boolean getXmlStandalone() { 2299 return xmlStandalone; 2300 } 2301 2302 public void setXmlStandalone(boolean xmlStandalone) throws DOMException { 2303 this.xmlStandalone = xmlStandalone; 2304 } 2305 2306 private String xmlVersion; 2307 public String getXmlVersion() { 2308 return xmlVersion; 2309 } 2310 2311 public void setXmlVersion(String xmlVersion) throws DOMException { 2312 this.xmlVersion = xmlVersion; 2313 } 2314 2315 2316 2317 } --- EOF ---