1 18 package org.enhydra.util.dom; 19 20 import org.enhydra.xml.dom.DOMOps; 21 import org.enhydra.xml.io.DOMFormatter; 22 import org.enhydra.xml.io.DocumentInfo; 23 import org.enhydra.xml.xmlc.XMLCError; 24 import org.enhydra.xml.xmlc.XMLCUtil; 25 import org.enhydra.xml.xmlc.XMLObject; 26 import org.enhydra.xml.xmlc.XMLObjectLink; 27 import org.enhydra.xml.xmlc.dom.XMLCDomFactory; 28 import org.w3c.dom.Attr ; 29 import org.w3c.dom.CDATASection ; 30 import org.w3c.dom.Comment ; 31 import org.w3c.dom.DOMConfiguration ; 32 import org.w3c.dom.DOMException ; 33 import org.w3c.dom.DOMImplementation ; 34 import org.w3c.dom.Document ; 35 import org.w3c.dom.DocumentFragment ; 36 import org.w3c.dom.DocumentType ; 37 import org.w3c.dom.Element ; 38 import org.w3c.dom.EntityReference ; 39 import org.w3c.dom.NamedNodeMap ; 40 import org.w3c.dom.Node ; 41 import org.w3c.dom.NodeList ; 42 import org.w3c.dom.ProcessingInstruction ; 43 import org.w3c.dom.Text ; 44 import org.w3c.dom.UserDataHandler ; 45 46 64 public class SimpleXMLObjectImpl implements XMLObject { 65 66 70 private static DOMFormatter fFormatter = null; 71 72 75 private Document fDocument; 76 77 80 private String fMIMEType; 81 82 85 private String encoding; 86 87 90 private XMLObject fDelegate; 91 92 96 public SimpleXMLObjectImpl() { 97 } 98 99 104 public Node cloneNode(boolean parm1) { 105 106 throw new java.lang.UnsupportedOperationException ("Method cloneNode() not yet implemented."); 107 } 108 109 113 protected void syncWithDocument(Node node) { 114 115 } 116 117 120 public void buildDocument() { 121 122 throw new java.lang.UnsupportedOperationException ("Method buildDocument() not yet implemented."); 123 } 124 125 129 protected XMLCDomFactory getDomFactory() { 130 131 throw new java.lang.UnsupportedOperationException ("Method getDomFactory() not yet implemented."); 132 } 133 134 135 142 public void setDocument(Document document, String mimeType, String encoding) { 143 fDocument = document; 144 fMIMEType = mimeType; 145 this.encoding = encoding; 146 147 if (document instanceof XMLObjectLink) { 149 ( (XMLObjectLink) document).setXMLObject(this); 150 } 151 } 152 153 156 public Document getDocument() { 157 if (fDelegate != null) { 158 return fDelegate.getDocument(); 159 } 160 else { 161 return fDocument; 162 } 163 } 164 165 168 public String getMIMEType() { 169 if (fDelegate != null) { 170 return fDelegate.getMIMEType(); 171 } 172 else { 173 return fMIMEType; 174 } 175 } 176 177 180 public void setDelegate(XMLObject delegate) { 181 fDelegate = delegate; 182 } 183 184 187 public XMLObject getDelegate() { 188 return fDelegate; 189 } 190 191 195 protected void cloneDeepCheck(boolean deep) { 196 if (!deep) { 197 throw new XMLCError("Must use deep clone when cloning entire document"); 198 } 199 } 200 201 204 public DocumentType getDoctype() { 205 if (fDelegate != null) { 206 return fDelegate.getDoctype(); 207 } 208 else { 209 return fDocument.getDoctype(); 210 } 211 } 212 213 216 public DOMImplementation getImplementation() { 217 if (fDelegate != null) { 218 return fDelegate.getImplementation(); 219 } 220 else { 221 return fDocument.getImplementation(); 222 } 223 } 224 225 228 public Element getDocumentElement() { 229 if (fDelegate != null) { 230 return fDelegate.getDocumentElement(); 231 } 232 else { 233 return fDocument.getDocumentElement(); 234 } 235 } 236 237 240 public Node importNode(Node importedNode, boolean deep) throws DOMException { 241 if (fDelegate != null) { 242 return fDelegate.importNode(importedNode, deep); 243 } 244 else { 245 return fDocument.importNode(importedNode, deep); 246 } 247 } 248 249 252 public Element createElement(String tagName) throws DOMException { 253 if (fDelegate != null) { 254 return fDelegate.createElement(tagName); 255 } 256 else { 257 return fDocument.createElement(tagName); 258 } 259 } 260 261 264 public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException { 265 if (fDelegate != null) { 266 return fDelegate.createElementNS(namespaceURI, qualifiedName); 267 } 268 else { 269 return fDocument.createElementNS(namespaceURI, qualifiedName); 270 } 271 } 272 273 276 public DocumentFragment createDocumentFragment() { 277 if (fDelegate != null) { 278 return fDelegate.createDocumentFragment(); 279 } 280 else { 281 return fDocument.createDocumentFragment(); 282 } 283 } 284 285 288 public Text createTextNode(String data) { 289 if (fDelegate != null) { 290 return fDelegate.createTextNode(data); 291 } 292 else { 293 return fDocument.createTextNode(data); 294 } 295 } 296 297 300 public Comment createComment(String data) { 301 if (fDelegate != null) { 302 return fDelegate.createComment(data); 303 } 304 else { 305 return fDocument.createComment(data); 306 } 307 } 308 309 312 public CDATASection createCDATASection(String data) throws DOMException { 313 if (fDelegate != null) { 314 return fDelegate.createCDATASection(data); 315 } 316 else { 317 return fDocument.createCDATASection(data); 318 } 319 } 320 321 324 public ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException { 325 if (fDelegate != null) { 326 return fDelegate.createProcessingInstruction(target, data); 327 } 328 else { 329 return fDocument.createProcessingInstruction(target, data); 330 } 331 } 332 333 336 public Attr createAttribute(String qualifiedName) throws DOMException { 337 if (fDelegate != null) { 338 return fDelegate.createAttribute(qualifiedName); 339 } 340 else { 341 return fDocument.createAttribute(qualifiedName); 342 } 343 } 344 345 348 public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException { 349 if (fDelegate != null) { 350 return fDelegate.createAttributeNS(namespaceURI, qualifiedName); 351 } 352 else { 353 return fDocument.createAttributeNS(namespaceURI, qualifiedName); 354 } 355 } 356 357 360 public EntityReference createEntityReference(String name) throws DOMException { 361 if (fDelegate != null) { 362 return fDelegate.createEntityReference(name); 363 } 364 else { 365 return fDocument.createEntityReference(name); 366 } 367 } 368 369 372 public NodeList getElementsByTagName(String tagname) { 373 if (fDelegate != null) { 374 return fDelegate.getElementsByTagName(tagname); 375 } 376 else { 377 return fDocument.getElementsByTagName(tagname); 378 } 379 } 380 381 384 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) { 385 if (fDelegate != null) { 386 return fDelegate.getElementsByTagNameNS(namespaceURI, localName); 387 } 388 else { 389 return fDocument.getElementsByTagNameNS(namespaceURI, localName); 390 } 391 } 392 393 396 public Element getElementById(String elementId) { 397 if (fDelegate != null) { 398 return fDelegate.getElementById(elementId); 399 } 400 else { 401 return fDocument.getElementById(elementId); 402 } 403 } 404 405 408 public String getEncoding() { 409 if (fDelegate != null) { 410 return fDelegate.getEncoding(); 411 } 412 else { 413 return this.encoding; 414 } 415 } 416 417 420 public void setEncoding(String encoding) { 421 if (fDelegate != null) { 422 fDelegate.setEncoding(encoding); 423 } 424 else { 425 DOMOps.setEncoding(fDocument, encoding); 426 } 427 } 428 429 432 public boolean getStandalone() { 433 if (fDelegate != null) { 434 return fDelegate.getStandalone(); 435 } 436 else { 437 return DOMOps.getStandalone(fDocument); 438 } 439 } 440 441 444 public void setStandalone(boolean standalone) { 445 if (fDelegate != null) { 446 fDelegate.setStandalone(standalone); 447 } 448 else { 449 DOMOps.setStandalone(fDocument, standalone); 450 } 451 } 452 453 456 public boolean getStrictErrorChecking() { 457 if (fDelegate != null) { 458 return fDelegate.getStrictErrorChecking(); 459 } 460 else { 461 return DOMOps.getStrictErrorChecking(fDocument); 462 } 463 } 464 465 468 public void setStrictErrorChecking(boolean strictErrorChecking) { 469 if (fDelegate != null) { 470 fDelegate.setStrictErrorChecking(strictErrorChecking); 471 } 472 else { 473 DOMOps.setStrictErrorChecking(fDocument, strictErrorChecking); 474 } 475 } 476 477 480 public String getVersion() { 481 if (fDelegate != null) { 482 return fDelegate.getVersion(); 483 } 484 else { 485 return DOMOps.getVersion(fDocument); 486 } 487 } 488 489 492 public void setVersion(String version) { 493 if (fDelegate != null) { 494 fDelegate.setVersion(version); 495 } 496 else { 497 DOMOps.setVersion(fDocument, version); 498 } 499 } 500 501 504 public Node adoptNode(Node source) throws DOMException { 505 if (fDelegate != null) { 506 return fDelegate.adoptNode(source); 507 } 508 else { 509 return DOMOps.adoptNode(fDocument, source); 510 } 511 } 512 513 516 public String getNodeName() { 517 if (fDelegate != null) { 518 return fDelegate.getNodeName(); 519 } 520 else { 521 return fDocument.getNodeName(); 522 } 523 } 524 525 528 public String getNodeValue() throws DOMException { 529 if (fDelegate != null) { 530 return fDelegate.getNodeValue(); 531 } 532 else { 533 return fDocument.getNodeValue(); 534 } 535 } 536 537 540 public void setNodeValue(String nodeValue) throws DOMException { 541 if (fDelegate != null) { 542 fDelegate.setNodeValue(nodeValue); 543 } 544 else { 545 fDocument.setNodeValue(nodeValue); 546 } 547 } 548 549 552 public short getNodeType() { 553 if (fDelegate != null) { 554 return fDelegate.getNodeType(); 555 } 556 else { 557 return fDocument.getNodeType(); 558 } 559 } 560 561 564 public Node getParentNode() { 565 if (fDelegate != null) { 566 return fDelegate.getParentNode(); 567 } 568 else { 569 return fDocument.getParentNode(); 570 } 571 } 572 573 576 public NodeList getChildNodes() { 577 if (fDelegate != null) { 578 return fDelegate.getChildNodes(); 579 } 580 else { 581 return fDocument.getChildNodes(); 582 } 583 } 584 585 588 public Node getFirstChild() { 589 if (fDelegate != null) { 590 return fDelegate.getFirstChild(); 591 } 592 else { 593 return fDocument.getFirstChild(); 594 } 595 } 596 597 600 public Node getLastChild() { 601 if (fDelegate != null) { 602 return fDelegate.getLastChild(); 603 } 604 else { 605 return fDocument.getLastChild(); 606 } 607 } 608 609 612 public Node getPreviousSibling() { 613 if (fDelegate != null) { 614 return fDelegate.getPreviousSibling(); 615 } 616 else { 617 return fDocument.getPreviousSibling(); 618 } 619 } 620 621 624 public Node getNextSibling() { 625 if (fDelegate != null) { 626 return fDelegate.getNextSibling(); 627 } 628 else { 629 return fDocument.getNextSibling(); 630 } 631 } 632 633 636 public NamedNodeMap getAttributes() { 637 if (fDelegate != null) { 638 return fDelegate.getAttributes(); 639 } 640 else { 641 return fDocument.getAttributes(); 642 } 643 } 644 645 648 public Document getOwnerDocument() { 649 if (fDelegate != null) { 650 return fDelegate.getOwnerDocument(); 651 } 652 else { 653 return fDocument.getOwnerDocument(); 654 } 655 } 656 657 660 public Node insertBefore(Node newChild, Node refChild) throws DOMException { 661 if (fDelegate != null) { 662 return fDelegate.insertBefore(newChild, refChild); 663 } 664 else { 665 return fDocument.insertBefore(newChild, refChild); 666 } 667 } 668 669 672 public Node replaceChild(Node newChild, Node oldChild) throws DOMException { 673 if (fDelegate != null) { 674 return fDelegate.replaceChild(newChild, oldChild); 675 } 676 else { 677 return fDocument.replaceChild(newChild, oldChild); 678 } 679 } 680 681 684 public Node removeChild(Node oldChild) throws DOMException { 685 if (fDelegate != null) { 686 return fDelegate.removeChild(oldChild); 687 } 688 else { 689 return fDocument.removeChild(oldChild); 690 } 691 } 692 693 696 public Node appendChild(Node newChild) throws DOMException { 697 if (fDelegate != null) { 698 return fDelegate.appendChild(newChild); 699 } 700 else { 701 return fDocument.appendChild(newChild); 702 } 703 } 704 705 708 public void normalize() { 709 if (fDelegate != null) { 710 fDelegate.normalize(); 711 } 712 else { 713 fDocument.normalize(); 714 } 715 } 716 717 720 public boolean isSupported(String feature, String version) { 721 if (fDelegate != null) { 722 return fDelegate.isSupported(feature, version); 723 } 724 else { 725 return fDocument.isSupported(feature, version); 726 } 727 } 728 729 732 public String getNamespaceURI() { 733 if (fDelegate != null) { 734 return fDelegate.getNamespaceURI(); 735 } 736 else { 737 return fDocument.getNamespaceURI(); 738 } 739 } 740 741 744 public String getPrefix() { 745 if (fDelegate != null) { 746 return fDelegate.getPrefix(); 747 } 748 else { 749 return fDocument.getPrefix(); 750 } 751 } 752 753 756 public void setPrefix(String prefix) { 757 if (fDelegate != null) { 758 fDelegate.setPrefix(prefix); 759 } 760 else { 761 fDocument.setPrefix(prefix); 762 } 763 } 764 765 768 public String getLocalName() { 769 if (fDelegate != null) { 770 return fDelegate.getLocalName(); 771 } 772 else { 773 return fDocument.getLocalName(); 774 } 775 } 776 777 780 public boolean hasChildNodes() { 781 if (fDelegate != null) { 782 return fDelegate.hasChildNodes(); 783 } 784 else { 785 return fDocument.hasChildNodes(); 786 } 787 } 788 789 792 public boolean hasAttributes() { 793 if (fDelegate != null) { 794 return fDelegate.hasAttributes(); 795 } 796 else { 797 return fDocument.hasAttributes(); 798 } 799 } 800 801 804 public String toDocument() { 805 if (fFormatter == null) { 807 fFormatter = new DOMFormatter(DOMFormatter.getDefaultOutputOptions( 808 getDocument())); 809 } 810 811 if (fDelegate != null) { 812 return fFormatter.toString(fDelegate); 813 } 814 else { 815 return fFormatter.toString(this); 816 } 817 } 818 819 822 private void syncAccessMethods(Node node) { 823 syncWithDocument(node); 824 for (Node child = node.getFirstChild(); child != null; 825 child = child.getNextSibling()) { 826 syncAccessMethods(child); 827 } 828 } 829 830 833 public void syncAccessMethods() { 834 if (fDelegate != null) { 835 fDelegate.syncAccessMethods(); 836 } 837 else { 838 syncAccessMethods(fDocument); 839 } 840 } 841 842 850 public void initFields() { 851 syncAccessMethods(); 852 } 853 854 857 public boolean isURLAttribute(Element element, String attrName) { 858 return getDomFactory().isURLAttribute(element, attrName); 859 } 860 861 865 protected final void doSetText(Element element, String text) { 866 if (text == null) { 867 throw new IllegalArgumentException ( "attempt to set a DOM text node value to null"); 868 } 869 XMLCUtil.getFirstText(element).setData(text); 870 } 871 872 875 public String getInputEncoding() { 876 return null; 878 } 879 880 883 public String getXmlEncoding() { 884 return null; 886 } 887 888 891 public boolean getXmlStandalone() { 892 return false; 894 } 895 896 899 public void setXmlStandalone(boolean arg0) throws DOMException { 900 902 } 903 904 907 public String getXmlVersion() { 908 return null; 910 } 911 912 915 public void setXmlVersion(String arg0) throws DOMException { 916 918 } 919 920 923 public String getDocumentURI() { 924 return null; 926 } 927 928 931 public void setDocumentURI(String arg0) { 932 934 } 935 936 939 public DOMConfiguration getDomConfig() { 940 return null; 942 } 943 944 947 public void normalizeDocument() { 948 950 } 951 952 955 public Node renameNode(Node arg0, String arg1, String arg2) throws DOMException { 956 return null; 958 } 959 960 963 public String getBaseURI() { 964 return null; 966 } 967 968 971 public short compareDocumentPosition(Node arg0) throws DOMException { 972 return 0; 974 } 975 976 979 public String getTextContent() throws DOMException { 980 return null; 982 } 983 984 987 public void setTextContent(String arg0) throws DOMException { 988 990 } 991 992 995 public boolean isSameNode(Node arg0) { 996 return false; 998 } 999 1000 1003public String lookupPrefix(String arg0) { 1004 return null; 1006} 1007 1008 1011public boolean isDefaultNamespace(String arg0) { 1012 return false; 1014} 1015 1016 1019public String lookupNamespaceURI(String arg0) { 1020 return null; 1022} 1023 1024 1027public boolean isEqualNode(Node arg0) { 1028 return false; 1030} 1031 1032 1035public Object getFeature(String arg0, String arg1) { 1036 return null; 1038} 1039 1040 1043public Object setUserData(String arg0, Object arg1, UserDataHandler arg2) { 1044 return null; 1046} 1047 1048 1051public Object getUserData(String arg0) { 1052 return null; 1054} 1055} | Popular Tags |