1 2 57 58 package dom; 59 60 import java.lang.reflect.InvocationTargetException ; 61 import java.lang.reflect.Method ; 62 63 import org.w3c.dom.Attr ; 64 import org.w3c.dom.CDATASection ; 65 import org.w3c.dom.CharacterData ; 66 import org.w3c.dom.Comment ; 67 import org.w3c.dom.DOMException ; 68 import org.w3c.dom.DOMImplementation ; 69 import org.w3c.dom.Document ; 70 import org.w3c.dom.DocumentFragment ; 71 import org.w3c.dom.DocumentType ; 72 import org.w3c.dom.Element ; 73 import org.w3c.dom.Entity ; 74 import org.w3c.dom.EntityReference ; 75 import org.w3c.dom.NamedNodeMap ; 76 import org.w3c.dom.Node ; 77 import org.w3c.dom.NodeList ; 78 import org.w3c.dom.Notation ; 79 import org.w3c.dom.ProcessingInstruction ; 80 import org.w3c.dom.Text ; 81 82 import dom.util.Assertion; 83 84 92 93 public class DTest { 94 95 public static Element testElementNode; 96 public static Attr testAttributeNode; 97 public static Text testTextNode; 98 public static CDATASection testCDATASectionNode; 99 public static EntityReference testEntityReferenceNode; 100 public static Entity testEntityNode; 101 public static ProcessingInstruction testProcessingInstructionNode; 102 public static Comment testCommentNode; 103 public static Document testDocumentNode; 104 public static DocumentType testDocumentTypeNode; 105 public static DocumentFragment testDocumentFragmentNode; 106 public static Notation testNotationNode; 107 108 114 public DTest() { 115 super(); 116 117 } 118 125 public Document createDocument() { 126 return new org.enhydra.apache.xerces.dom.DocumentImpl(); } 128 136 public DocumentType createDocumentType(Document doc, String name) { 137 return ((org.enhydra.apache.xerces.dom.DocumentImpl) doc).createDocumentType(name, null, null); } 139 148 public Entity createEntity(Document doc, String name) { 149 return new org.enhydra.apache.xerces.dom.EntityImpl((org.enhydra.apache.xerces.dom.DocumentImpl)doc, name); } 151 160 public Notation createNotation(Document doc, String name) { 161 return new org.enhydra.apache.xerces.dom.NotationImpl((org.enhydra.apache.xerces.dom.DocumentImpl) doc, name); } 163 172 public void docBuilder(org.w3c.dom.Document document, String name) 173 { 174 Document doc = document; 175 boolean OK = true; 176 177 Element docFirstElement = doc.createElement(name + "FirstElement"); 178 doc.appendChild(docFirstElement); 179 docFirstElement.setAttribute(name + "FirstElement", name + "firstElement"); 180 181 ProcessingInstruction docProcessingInstruction = doc.createProcessingInstruction(name + 182 "TargetProcessorChannel", "This is " + doc + "'s processing instruction"); 183 docFirstElement.appendChild(docProcessingInstruction); 184 185 Element docBody = doc.createElement(name + "TestBody"); 186 docFirstElement.appendChild(docBody); 187 188 Element docBodyLevel21 = doc.createElement(name + "BodyLevel21"); 189 Element docBodyLevel22 = doc.createElement(name + "BodyLevel22"); 190 Element docBodyLevel23 = doc.createElement(name + "BodyLevel23"); 191 Element docBodyLevel24 = doc.createElement(name + "BodyLevel24"); 192 docBody.appendChild(docBodyLevel21); 193 docBody.appendChild(docBodyLevel22); 194 docBody.appendChild(docBodyLevel23); 195 docBody.appendChild(docBodyLevel24); 196 197 Element docBodyLevel31 = doc.createElement(name + "BodyLevel31"); 198 Element docBodyLevel32 = doc.createElement(name + "BodyLevel32"); 199 Element docBodyLevel33 = doc.createElement(name + "BodyLevel33"); 200 Element docBodyLevel34 = doc.createElement(name + "BodyLevel34"); 201 docBodyLevel21.appendChild(docBodyLevel31); 202 docBodyLevel21.appendChild(docBodyLevel32); 203 docBodyLevel22.appendChild(docBodyLevel33); 204 docBodyLevel22.appendChild(docBodyLevel34); 205 206 Text docTextNode11 = doc.createTextNode(name + "BodyLevel31'sChildTextNode11"); 207 Text docTextNode12 = doc.createTextNode(name + "BodyLevel31'sChildTextNode12"); 208 Text docTextNode13 = doc.createTextNode(name + "BodyLevel31'sChildTextNode13"); 209 Text docTextNode2 = doc.createTextNode(name + "TextNode2"); 210 Text docTextNode3 = doc.createTextNode(name + "TextNode3"); 211 Text docTextNode4 = doc.createTextNode(name + "TextNode4"); 212 docBodyLevel31.appendChild(docTextNode11); 213 docBodyLevel31.appendChild(docTextNode12); 214 docBodyLevel31.appendChild(docTextNode13); 215 docBodyLevel32.appendChild(docTextNode2); 216 docBodyLevel33.appendChild(docTextNode3); 217 docBodyLevel34.appendChild(docTextNode4); 218 219 CDATASection docCDATASection = doc.createCDATASection("<![CDATA[<greeting>Hello, world!</greeting>]]>"); 220 docBodyLevel23.appendChild(docCDATASection); 221 222 Comment docComment = doc.createComment("This should be a comment of some kind "); 223 docBodyLevel23.appendChild(docComment); 224 225 EntityReference docReferenceEntity = doc.createEntityReference("ourEntityNode"); 226 docBodyLevel24.appendChild(docReferenceEntity); 227 228 DTest make = new DTest(); 229 Notation docNotation = make.createNotation(doc, "ourNotationNode"); 230 DocumentType docType = (DocumentType )doc.getFirstChild(); 232 docType.getNotations().setNamedItem(docNotation); 233 234 DocumentFragment docDocFragment = doc.createDocumentFragment(); 235 236 238 239 Text docNode3 = doc.createTextNode(name + "docTextNode3"); 241 Text docNode4 = doc.createTextNode(name + "docTextNode4"); 242 243 Entity docEntity = (Entity ) doc.getDoctype().getEntities().getNamedItem("ourEntityNode"); DocumentType docDocType = (DocumentType ) doc.getFirstChild(); EntityReference entityReferenceText = (EntityReference ) doc.getLastChild().getLastChild().getLastChild().getFirstChild(); 246 Text entityReferenceText2 = doc.createTextNode("entityReferenceText information"); 247 249 OK &= Assertion.assertTrue(DOMExceptionsTest(document, "appendChild", new Class []{Node .class}, new Object []{docBody}, DOMException.HIERARCHY_REQUEST_ERR )); 250 OK &= Assertion.assertTrue(DOMExceptionsTest(docNode3, "appendChild", new Class []{Node .class}, new Object []{docNode4}, DOMException.HIERARCHY_REQUEST_ERR )); 251 OK &= Assertion.assertTrue(DOMExceptionsTest(doc, "insertBefore", new Class []{Node .class, Node .class}, new Object []{docEntity, docFirstElement}, DOMException.HIERARCHY_REQUEST_ERR )); 252 OK &= Assertion.assertTrue(DOMExceptionsTest(doc, "replaceChild", new Class []{Node .class, Node .class}, new Object []{docCDATASection, docFirstElement}, DOMException.HIERARCHY_REQUEST_ERR )); 253 254 docFirstElement.setNodeValue("This shouldn't do anything!"); 255 OK &= Assertion.assertTrue(docFirstElement.getNodeValue() == null); 256 docReferenceEntity.setNodeValue("This shouldn't do anything!"); 257 OK &= Assertion.assertTrue(docReferenceEntity.getNodeValue() == null); 258 docEntity.setNodeValue("This shouldn't do anything!"); 259 OK &= Assertion.assertTrue(docEntity.getNodeValue() == null); 260 doc.setNodeValue("This shouldn't do anything!"); 261 OK &= Assertion.assertTrue(doc.getNodeValue() == null); 262 docType.setNodeValue("This shouldn't do anything!"); 263 OK &= Assertion.assertTrue(docType.getNodeValue() == null); 264 docDocFragment.setNodeValue("This shouldn't do anything!"); 265 OK &= Assertion.assertTrue(docDocFragment.getNodeValue() == null); 266 docNotation.setNodeValue("This shouldn't do anything!"); 267 OK &= Assertion.assertTrue(docNotation.getNodeValue() == null); 268 269 OK &= Assertion.assertTrue(DOMExceptionsTest(docReferenceEntity, "appendChild", new Class []{Node .class}, new Object []{entityReferenceText2 }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 270 OK &= Assertion.assertTrue(DOMExceptionsTest(docBodyLevel32, "insertBefore", new Class []{Node .class, Node .class}, new Object []{docTextNode11,docBody }, DOMException.NOT_FOUND_ERR )); 271 OK &= Assertion.assertTrue(DOMExceptionsTest(docBodyLevel32, "removeChild", new Class []{Node .class}, new Object []{docFirstElement}, DOMException.NOT_FOUND_ERR )); 272 OK &= Assertion.assertTrue(DOMExceptionsTest(docBodyLevel32, "replaceChild", new Class []{Node .class, Node .class}, new Object []{docTextNode11,docFirstElement }, DOMException.NOT_FOUND_ERR )); 273 274 275 277 279 } 292 public static boolean DOMExceptionsTest(Object node, String methodName, Class [] methodSignature, Object [] parameters, short code) { 293 294 boolean asExpected = false; 295 Method method; 296 297 try 298 { 299 method = node.getClass().getMethod(methodName,methodSignature); 300 method.invoke(node, parameters); 301 }catch(InvocationTargetException exc) 302 { 303 Throwable realE = exc.getTargetException(); 304 if(realE instanceof DOMException ) 305 { 306 asExpected = (((DOMException )realE).code== code); 307 if(!asExpected) 308 System.out.println("Wrong DOMException(" + ((DOMException )realE).code + ")"); 309 } 310 else 311 System.out.println("Wrong Exception (" + code + ")"); 312 313 if(!asExpected) 314 { 315 System.out.println("Expected DOMException (" + code + ") not thrown"); 316 } 317 }catch(Exception exc) 318 { 319 System.out.println("test invocation failure (" + exc + ")"); 320 } 321 322 return (asExpected); 323 } 324 325 329 public void findTestNodes(Document document) { 330 Node node = document; 331 int nodeCount = 0; 332 333 while (node != null && nodeCount < 12) 335 { 336 337 switch (node.getNodeType()) 338 { 339 case org.w3c.dom.Node.ELEMENT_NODE : 340 if (testElementNode == null) {testElementNode = (Element )node; nodeCount++;} 341 break; 342 case org.w3c.dom.Node.ATTRIBUTE_NODE : 343 if (testAttributeNode == null) {testAttributeNode = (Attr )node; nodeCount++;} 344 break; 345 case org.w3c.dom.Node.TEXT_NODE : 346 if (testTextNode == null) {testTextNode = (Text )node; nodeCount++;} 347 break; 348 case org.w3c.dom.Node.CDATA_SECTION_NODE : 349 if (testCDATASectionNode == null) {testCDATASectionNode = (CDATASection )node; nodeCount++;} 350 break; 351 case org.w3c.dom.Node.ENTITY_REFERENCE_NODE : 352 if (testEntityReferenceNode == null) {testEntityReferenceNode = (EntityReference )node; nodeCount++;} 353 break; 354 case org.w3c.dom.Node.ENTITY_NODE : 355 if (testEntityNode == null) {testEntityNode = (Entity )node; nodeCount++;} 356 break; 357 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE : 358 if (testProcessingInstructionNode == null) {testProcessingInstructionNode = (ProcessingInstruction )node; nodeCount++;} 359 break; 360 case org.w3c.dom.Node.COMMENT_NODE : 361 if (testCommentNode == null) {testCommentNode = (Comment )node; nodeCount++;} 362 break; 363 case org.w3c.dom.Node.DOCUMENT_TYPE_NODE : 364 if (testDocumentTypeNode == null) {testDocumentTypeNode = (DocumentType )node; nodeCount++;} 365 break; 366 case org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE : 367 if (testDocumentFragmentNode == null) {testDocumentFragmentNode = (DocumentFragment )node; nodeCount++;} 368 break; 369 case org.w3c.dom.Node.NOTATION_NODE : 370 if (testNotationNode == null) {testNotationNode = (Notation )node; nodeCount++;} 371 break; 372 case org.w3c.dom.Node.DOCUMENT_NODE : 373 if (testDocumentNode == null) {testDocumentNode = (Document )node; nodeCount++;} 374 break; 375 default: 376 } }} 379 380 384 public void findTestNodes(Node node) { 385 386 DTest test = new DTest(); 387 Node kid; 388 390 391 if (node.getFirstChild() != null) 392 { 393 kid = node.getFirstChild(); 394 test.findTestNodes(kid); 395 } 396 397 398 if (node.getNextSibling() != null) 399 { 400 kid = node.getNextSibling(); 401 test.findTestNodes(kid); 402 } 403 404 switch (node.getNodeType()) 405 { 406 case org.w3c.dom.Node.ELEMENT_NODE : 407 if (testElementNode == null) {testElementNode = (Element )node; } 408 break; 409 case org.w3c.dom.Node.ATTRIBUTE_NODE : 410 if (testAttributeNode == null) {testAttributeNode = (Attr )node; } 411 break; 412 case org.w3c.dom.Node.TEXT_NODE : 413 if (testTextNode == null) {testTextNode = (Text )node; } 414 break; 415 case org.w3c.dom.Node.CDATA_SECTION_NODE : 416 if (testCDATASectionNode == null) {testCDATASectionNode = (CDATASection )node; } 417 break; 418 case org.w3c.dom.Node.ENTITY_REFERENCE_NODE : 419 if (testEntityReferenceNode == null) {testEntityReferenceNode = (EntityReference )node;} 420 break; 421 case org.w3c.dom.Node.ENTITY_NODE : 422 if (testEntityNode == null) {testEntityNode = (Entity )node;} 423 break; 424 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE : 425 if (testProcessingInstructionNode == null) {testProcessingInstructionNode = (ProcessingInstruction )node;} 426 break; 427 case org.w3c.dom.Node.COMMENT_NODE : 428 if (testCommentNode == null) {testCommentNode = (Comment )node;} 429 break; 430 case org.w3c.dom.Node.DOCUMENT_TYPE_NODE : 431 if (testDocumentTypeNode == null) {testDocumentTypeNode = (DocumentType )node; } 432 break; 433 case org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE : 434 if (testDocumentFragmentNode == null) {testDocumentFragmentNode = (DocumentFragment )node;} 435 break; 436 case org.w3c.dom.Node.NOTATION_NODE : 437 if (testNotationNode == null) {testNotationNode = (Notation )node;} 438 break; 439 case org.w3c.dom.Node.DOCUMENT_NODE : 440 if (testDocumentNode == null) {testDocumentNode = (Document )node;} 441 break; 442 default: 443 }} 445 446 452 453 public static void main(String args[]) { 454 System.out.println("# main()"); 455 456 DTest test = new DTest(); 457 458 long avgTime = 0; 459 boolean OK = true; 460 long startTime = 0; 462 startTime = System.currentTimeMillis(); 465 468 Document d = test.createDocument(); 469 471 DocumentType docDocType = test.createDocumentType(d,"testDocument1"); 472 d.appendChild(docDocType); 473 474 Entity docEntity = test.createEntity( d, "ourEntityNode"); 475 Text entityChildText = d.createTextNode("entityChildText information"); ((org.enhydra.apache.xerces.dom.NodeImpl)docEntity).setReadOnly(false, true); 477 docEntity.appendChild(entityChildText); ((org.enhydra.apache.xerces.dom.NodeImpl)docEntity).setReadOnly(true, true); 479 docDocType.getEntities().setNamedItem(docEntity); 480 481 test.docBuilder(d, "d"); 482 483 test.findTestNodes((Node )d); 484 try { 486 test.testAttr(d); 487 test.testCDATASection(d); 488 test.testCharacterData(d); 489 test.testChildNodeList(d); 490 test.testComment(d); 491 test.testDeepNodeList(d); 492 test.testDocument(d); 493 test.testDocumentFragment(d); 494 test.testDocumentType(d); 495 test.testDOMImplementation(d); 496 test.testElement(d); 497 test.testEntity(d); 498 test.testEntityReference(d); 499 test.testNode(d); 500 test.testNotation(d); 501 test.testPI(d); 502 test.testText(d); 503 test.testDOMerrors(d); 504 505 507 512 516 517 524 525 527 528 549 550 551 557 558 } catch (Exception e) { 559 System.out.println("Exception is: "); 560 e.printStackTrace(); 561 OK = false; 562 563 } 564 avgTime += System.currentTimeMillis() - startTime; 566 568 569 574 575 577 } 578 585 public void testAttr(org.w3c.dom.Document document) 586 { 587 588 Node node; 589 Attr attributeNode, attribute2; 590 String compare; 591 boolean T = true; 592 boolean F = false; 593 boolean OK = true; 594 596 Attr testAttribute = document.createAttribute("testAttribute"); 597 testAttribute.setValue("testAttribute's value"); 598 node = document.getDocumentElement(); ((Element )node).setAttributeNode(testAttribute); 600 attributeNode = ((Element )node).getAttributeNode("testAttribute"); 601 602 compare = "testAttribute"; 603 if (!compare.equals(attributeNode.getName())) 604 { 605 System.out.println("Warning!!! Attr's 'getName' method failed to work properly!"); 606 OK = false; 607 } 608 compare = "testAttribute's value"; 609 if (!compare.equals(attributeNode.getNodeValue())) 610 { 611 System.out.println("Warning!!! Attr's 'getNodeValue' method failed to work properly!"); 612 OK = false; 613 } 614 if (! T ==attributeNode.getSpecified()) 615 { 616 System.out.println("Warning!!! Attr's 'getSpecified' method failed to work properly!"); 617 OK = false; 618 } 619 620 if (!compare.equals(attributeNode.getValue())) 621 { 622 System.out.println("Warning!!! Attr's 'getValue' method failed to work properly!"); 623 OK = false; 624 } 625 626 attributeNode.setNodeValue("Reset Value"); 627 compare = "Reset Value"; 628 if (!compare.equals(attributeNode.getNodeValue())) 629 { 630 System.out.println("Warning!!! Attr's 'setNodeValue' method failed to work properly!"); 631 OK = false; 632 } 633 ((org.enhydra.apache.xerces.dom.AttrImpl)attributeNode).setSpecified(F); if (! F ==attributeNode.getSpecified()) 635 { 636 System.out.println("Warning!!! Attr's 'setSpecified' method failed to work properly!"); 637 OK = false; 638 } 639 640 attributeNode.setValue(null); 641 if (! attributeNode.getValue().equals("")) 642 { 643 System.out.println("Warning!!! Attr's 'setValue' to 'null' method failed to work properly!"); 644 OK = false; 645 } 646 647 attributeNode.setValue("Another value "); 648 compare = "Another value "; 649 if (!compare.equals(attributeNode.getValue())) 650 { 651 System.out.println("Warning!!! Attr's 'setValue' method failed to work properly!"); 652 OK = false; 653 } 654 655 node = attributeNode.cloneNode(T); if (! (node.getNodeName().equals(attributeNode.getNodeName()) && (node.getNodeValue() != null && attributeNode.getNodeValue() != null) ? node.getNodeValue().equals(attributeNode.getNodeValue()) : (node.getNodeValue() == null && attributeNode.getNodeValue() == null))) { 662 System.out.println("'cloneNode' did not clone the Attribute node correctly"); 663 OK = false; 664 } 665 667 Assertion.assertTrue( 669 DOMExceptionsTest(document.getDocumentElement(), 670 "appendChild", 671 new Class []{Node .class}, 672 new Object []{attributeNode}, 673 DOMException.HIERARCHY_REQUEST_ERR)); 674 675 attribute2 = document.createAttribute("testAttribute2"); 676 Assertion.assertTrue( 677 DOMExceptionsTest(document.getDocumentElement(), 678 "removeAttributeNode", 679 new Class []{Attr .class}, 680 new Object []{attribute2}, 681 DOMException.NOT_FOUND_ERR)); 682 683 Element element = (Element )document.getLastChild().getLastChild(); 684 Assertion.assertTrue( 686 DOMExceptionsTest(element, 687 "setAttributeNode", 688 new Class []{Attr .class}, 689 new Object []{testAttribute}, 690 DOMException.INUSE_ATTRIBUTE_ERR)); 691 692 if (! OK) 693 System.out.println("\n*****The Attr method calls listed above failed, all others worked correctly.*****"); 694 } 696 703 public void testCDATASection(org.w3c.dom.Document document) 704 { 705 706 Node node, node2; 707 boolean T = true; 708 boolean OK = true; 709 node = document.getDocumentElement().getElementsByTagName("dBodyLevel23").item(0).getFirstChild(); 712 node2 = node.cloneNode(T); if (! (node.getNodeName().equals(node2.getNodeName()) && (node.getNodeValue() != null && node2.getNodeValue() != null) ? node.getNodeValue().equals(node2.getNodeValue()) : (node.getNodeValue() == null && node2.getNodeValue() == null))) { 719 System.out.println("'cloneNode' did not clone the CDATASection node correctly"); 720 OK = false; 721 } 722 724 726 if (! OK) 727 System.out.println("\n*****The CDATASection method calls listed above failed, all others worked correctly.*****"); 728 } 730 737 public void testCharacterData(org.w3c.dom.Document document) 738 { 739 CharacterData charData; 740 String compareData, newData, resetData; 741 boolean OK = true; 742 charData = (CharacterData ) document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); compareData = "dBodyLevel31'sChildTextNode11"; 745 if (!compareData.equals(charData.getData())) 746 { 747 System.out.println("Warning!!! CharacterData's 'getData' failed to work properly!\n This may corrupt other CharacterData tests!!!*****"); 748 OK = false; 749 } 750 751 resetData = charData.getData(); 752 754 newData = " This is new data for this node"; 755 compareData = charData.getData() + newData; 756 charData.appendData(newData); 757 if (!compareData.equals(charData.getData())) 758 { 759 System.out.println("Warning!!! CharacterData's 'appendData' failed to work properly!"); 760 OK = false; 761 } 762 764 compareData = "dBodyLevel"; 765 charData.deleteData(10, 100); 766 if (!compareData.equals(charData.getData())) 767 { 768 System.out.println("Warning!!! CharacterData's 'deleteData' failed to work properly!"); 769 OK = false; 770 } 771 773 int length = 10; 774 if (!(length == charData.getLength())) 775 { 776 System.out.println("Warning!!! CharacterData's 'getLength' failed to work properly!"); 777 OK = false; 778 } 779 781 compareData = "dBody' This is data inserted into this node'Level"; 782 charData.insertData(5, "' This is data inserted into this node'"); 783 if (!compareData.equals(charData.getData())) 784 { 785 System.out.println("Warning!!! CharacterData's 'insertData' failed to work properly!"); 786 OK = false; 787 } 788 790 compareData = "dBody' This is ' replacement data'ted into this node'Level"; 791 charData.replaceData(15, 10, "' replacement data'"); 792 if (!compareData.equals(charData.getData())) 793 { 794 System.out.println("Warning!!! CharacterData's 'replaceData' failed to work properly!"); 795 OK = false; 796 } 797 799 compareData = "New data A123456789B123456789C123456789D123456789E123456789"; 800 charData.setData("New data A123456789B123456789C123456789D123456789E123456789"); 801 if (!compareData.equals(charData.getData())) 802 { 803 System.out.println("Warning!!! CharacterData's 'setData' failed to work properly!"); 804 OK = false; 805 } 806 808 compareData = "123456789D123456789E123456789"; 809 if (!compareData.equals(charData.substringData(30, 30))) 810 { 811 System.out.println("Warning!!! CharacterData's 'substringData' failed to work properly!"); 812 OK = false; 813 } 814 816 compareData = "New data A123456789B12345"; 817 if (!compareData.equals(charData.substringData(0, 25))) 818 { 819 System.out.println("Warning!!! CharacterData's 'substringData' failed to work properly!"); 820 OK = false; 821 } 822 824 826 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "deleteData", new Class []{int.class, int.class}, 828 new Object []{new Integer (-1),new Integer (5) }, DOMException.INDEX_SIZE_ERR )); 829 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "deleteData", new Class []{int.class, int.class}, 830 new Object []{new Integer (2),new Integer (-1) }, DOMException.INDEX_SIZE_ERR )); 831 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "deleteData", new Class []{int.class, int.class}, 832 new Object []{new Integer (100),new Integer (5) }, DOMException.INDEX_SIZE_ERR )); 833 834 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "insertData", new Class []{int.class, String .class}, 835 new Object []{new Integer (-1),"Stuff inserted" }, DOMException.INDEX_SIZE_ERR )); 836 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "insertData", new Class []{int.class, String .class}, 837 new Object []{new Integer (100),"Stuff inserted" }, DOMException.INDEX_SIZE_ERR )); 838 839 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "replaceData", new Class []{int.class, int.class, String .class}, 840 new Object []{new Integer (-1),new Integer (5),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR )); 841 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "replaceData", new Class []{int.class, int.class, String .class}, 842 new Object []{new Integer (100),new Integer (5),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR )); 843 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "replaceData", new Class []{int.class, int.class, String .class}, 844 new Object []{new Integer (2),new Integer (-1),"Replacement stuff" }, DOMException.INDEX_SIZE_ERR )); 845 846 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "substringData", new Class []{int.class, int.class}, 847 new Object []{new Integer (-1),new Integer (5) }, DOMException.INDEX_SIZE_ERR )); 848 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "substringData", new Class []{int.class, int.class}, 849 new Object []{new Integer (100),new Integer (5) }, DOMException.INDEX_SIZE_ERR )); 850 OK &= Assertion.assertTrue(DOMExceptionsTest(charData, "substringData", new Class []{int.class, int.class}, 851 new Object []{new Integer (2),new Integer (-1) }, DOMException.INDEX_SIZE_ERR )); 852 853 854 Node node = document.getDocumentElement().getElementsByTagName("dBodyLevel24").item(0).getFirstChild().getChildNodes().item(0); 857 OK &= Assertion.assertTrue(DOMExceptionsTest(node, "appendData", new Class []{String .class}, 858 new Object []{"new data" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 859 OK &= Assertion.assertTrue(DOMExceptionsTest(node, "deleteData", new Class []{int.class, int.class}, 860 new Object []{new Integer (5),new Integer (10) }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 861 OK &= Assertion.assertTrue(DOMExceptionsTest(node, "insertData", new Class []{int.class, String .class}, 862 new Object []{new Integer (5),"Stuff inserted" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 863 OK &= Assertion.assertTrue(DOMExceptionsTest(node, "replaceData", new Class []{int.class, int.class, String .class}, 864 new Object []{new Integer (5),new Integer (10),"Replacementstuff" }, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 865 OK &= Assertion.assertTrue(DOMExceptionsTest(node, "setData", new Class []{String .class}, 866 new Object []{"New setdata stuff"}, DOMException.NO_MODIFICATION_ALLOWED_ERR )); 867 868 869 if (!OK) 871 System.out.println("\n*****The CharacterData method calls listed above failed, all others worked correctly.*****"); 872 charData.setData(resetData); } 875 882 public void testChildNodeList(org.w3c.dom.Document document) 883 { 884 885 Node node, node2; 886 boolean OK = true; 887 node = document.getDocumentElement().getLastChild(); 890 if (!(node.getChildNodes().getLength()== 4)) 891 OK = false; 892 node2 = node.getChildNodes().item(2); 893 if (! node2.getNodeName().equals("dBodyLevel23")) 894 OK = false; 895 896 if (!OK) 898 System.out.println("\n*****The ChildNodeList method calls listed above failed, all others worked correctly.*****"); 899 } 901 908 public void testComment(org.w3c.dom.Document document) 909 { 910 Node node, node2; 911 boolean T = true; 912 boolean OK = true; 913 node = document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); node2 = node.cloneNode(T); 916 if (!(node.getNodeName().equals(node2.getNodeName()) && (node.getNodeValue() != null && node2.getNodeValue() != null) ? node.getNodeValue().equals(node2.getNodeValue()) : (node.getNodeValue() == null && node2.getNodeValue() == null))) OK = false; 923 if (OK) 925 if (!OK) 927 System.out.println("\n*****The Comment method calls listed above failed, all others worked correctly.*****"); 928 } 930 937 public void testDeepNodeList(org.w3c.dom.Document document) 938 { 939 940 Node node, node2; 941 boolean OK = true; 942 node = document.getLastChild().getLastChild(); if (!(8 == ((Element ) node).getElementsByTagName("*").getLength())) 945 { 946 System.out.println ("Warning!!! DeepNodeList's 'getLength' failed to work properly!"); 947 OK = false; 948 } 949 node2 = ((Element ) node).getElementsByTagName("*").item(2); if (! node2.getNodeName().equals("dBodyLevel32")) 951 { 952 System.out.println ("Warning!!! DeepNodeList's 'item' (or Element's 'getElementsBy TagName)failed to work properly!"); 953 OK = false; 954 } 955 node2 = document.getLastChild(); 956 if (! ((Element ) node2).getElementsByTagName("dTestBody").item(0).getNodeName().equals("dTestBody")) { 958 System.out.println ("Warning!!! DeepNodeList's 'item' (or Element's 'getElementsBy TagName)failed to work properly!"); 959 OK = false; 960 } 961 962 963 if (!OK) 965 System.out.println("\n*****The DeepNodeList method calls listed above failed, all others worked correctly.*****"); 966 } 968 977 public void testDocument(org.w3c.dom.Document document) 978 { 979 DTest make = new DTest(); 980 DocumentFragment docFragment, docFragment2; 981 Element newElement; 982 Node node, node2; 983 String [] elementNames = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32", 984 "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"}; 985 String [] newElementNames = {"dFirstElement", "dTestBody", "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23"}; 986 boolean result; 987 boolean OK = true; 988 990 DocumentType checkDocType = make.createDocumentType(document,"testDocument1"); 991 DocumentType docType = document.getDoctype(); 992 if (! (checkDocType.getNodeName().equals(docType.getNodeName()) && (checkDocType.getNodeValue() != null && docType.getNodeValue() != null) ? checkDocType.getNodeValue().equals(docType.getNodeValue()) : (checkDocType.getNodeValue() == null && docType.getNodeValue() == null))) { 997 System.out.println("Warning!!! Document's 'getDocType method failed!" ); 998 OK = false; 999 } 1000 1001 Node rootElement = document.getLastChild(); 1002 if (! (rootElement.getNodeName().equals(document.getDocumentElement().getNodeName()) && (rootElement.getNodeValue() != null && document.getDocumentElement().getNodeValue() != null) ? rootElement.getNodeValue().equals(document.getDocumentElement().getNodeValue()) : (rootElement.getNodeValue() == null && document.getDocumentElement().getNodeValue() == null))) { 1007 System.out.println("Warning!!! Document's 'getDocumentElement' method failed!" ); 1008 OK = false; 1009 } 1010 1011 NodeList docElements = document.getElementsByTagName("*"); 1012 int docSize = docElements.getLength(); 1013 int i; 1014 for (i = 0; i < docSize; i++) 1015 { 1016 Node n = (Node ) docElements.item(i); 1017 if (! (elementNames[i].equals(n.getNodeName()))) 1018 { 1019 System.out.println("Comparison of this document's elements failed at element number " + i + " : " + n.getNodeName()); 1020 OK = false; 1021 break; 1022 } 1023 } 1024 if (document.equals(document.getImplementation())) 1025 { 1026 System.out.println("Warning!!! Document's 'getImplementation' method failed!" ); 1027 OK = false; 1028 } 1029 1030 newElement = document.createElement("NewElementTestsInsertBefore"); 1031 1034 docFragment = document.createDocumentFragment(); 1035 docFragment.appendChild(docElements.item(1).removeChild(docElements.item(9))); 1037 docFragment2 = document.createDocumentFragment(); 1038 docFragment2.appendChild(docElements.item(1).removeChild(docElements.item(2))); 1040 docSize = docElements.getLength(); 1041 for (i = 0; i < docSize; i++) 1042 { 1043 Node n = (Node ) docElements.item(i); 1044 if (! (newElementNames[i].equals(n.getNodeName()))) 1045 { 1046 System.out.println("Comparison of new document's elements failed at element number " + i + " : " + n.getNodeName()); 1047 OK = false; 1048 break; 1049 } 1050 } 1051 docElements.item(1).insertBefore(docFragment, null); docElements.item(1).insertBefore(docFragment2, docElements.item(2)); 1054 1056 docSize = docElements.getLength(); 1057 for (i = 0; i < docSize; i++) 1058 { 1059 Node n = (Node ) docElements.item(i); 1060 if (! (elementNames[i].equals(n.getNodeName()))) 1061 { 1062 System.out.println("Comparison of restored document's elements failed at element number " + i + " : " + n.getNodeName()); 1063 OK = false; 1064 break; 1065 } 1066 } 1067 1068 1069 1072 1075 1080 1082 node = document; 1083 node2 = document.cloneNode(true); 1084 result = treeCompare(node, node2); if (!result) 1086 { 1087 System.out.println("Warning!!! Deep clone of the document failed!"); 1088 OK = false; 1089 } 1090 1091 Document doc2 = (Document ) node2; 1093 Assertion.assertTrue(doc2.getDocumentElement().getOwnerDocument() == doc2); 1094 1095 1097 node2 = doc2.createElement("foo"); 1099 doc2.getDocumentElement().appendChild(node2); 1100 1101 if (!OK) 1103 System.out.println("\n*****The Document method calls listed above failed, all others worked correctly.*****"); 1104} 1106 1116public void testDocumentFragment(org.w3c.dom.Document document) 1117{ 1118 boolean OK = true; 1119 DocumentFragment testDocFragment = document.createDocumentFragment(); 1121 1122 1124 if (!OK) 1126 System.out.println("\n*****The DocumentFragment method calls listed above failed, all others worked correctly.*****"); 1127} 1129 1136public void testDocumentType(org.w3c.dom.Document document) 1137{ 1138 DTest test = new DTest(); 1139 DocumentType docType, holdDocType; 1140 NamedNodeMap docEntityMap, docNotationMap; 1141 Node node, node2; 1142 String compare; 1143 boolean OK = true; 1144 DocumentType newDocumentType = test.createDocumentType(document, "TestDocument"); 1146 node = document.getFirstChild(); node2 = node.cloneNode(true); 1148 if (! (node.getNodeName().equals(node2.getNodeName()) && (node.getNodeValue() != null && node2.getNodeValue() != null) ? node.getNodeValue().equals(node2.getNodeValue()) : (node.getNodeValue() == null && node2.getNodeValue() == null))) { 1154 System.out.println("'cloneNode' did not clone the DocumentType node correctly"); 1155 OK = false; 1156 } 1157 1159 docType = (DocumentType ) document.getFirstChild(); 1160 compare = "ourEntityNode"; 1161 docEntityMap = docType.getEntities(); 1162 if (! compare.equals(docEntityMap.item(0).getNodeName())) 1163 { 1164 System.out.println("Warning!!! DocumentType's 'getEntities' failed!" ); 1165 OK = false; 1166 } 1167 docNotationMap = docType.getNotations(); 1168 compare = "ourNotationNode"; 1169 if (! compare.equals(docNotationMap.item(0).getNodeName())) 1170 { 1171 System.out.println("Warning!!! DocumentType's 'getNotations' failed!"); 1172 OK = false; 1173 } 1174 holdDocType = (DocumentType ) document.removeChild(document.getFirstChild()); document.insertBefore(newDocumentType, document.getDocumentElement()); 1177 1179 document.removeChild(document.getFirstChild()); document.insertBefore(holdDocType, document.getFirstChild()); 1182 1183 if (!OK) 1185 System.out.println("\n*****The DocumentType method calls listed above failed, all others worked correctly.*****"); 1186} 1188 1192public void testDOMerrors(Document document) { 1193 1194 boolean OK = true; 1195 1196 OK &= Assertion.assertTrue(DOMExceptionsTest(document, "appendChild", new Class []{Node .class}, new Object []{testElementNode}, DOMException.HIERARCHY_REQUEST_ERR )); 1197 OK &= Assertion.assertTrue(DOMExceptionsTest(testTextNode, "appendChild", new Class []{Node .class}, new Object []{testTextNode}, DOMException.HIERARCHY_REQUEST_ERR )); 1198 1201 1215 1216 1218 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232} 1233 1240public void testDOMImplementation(org.w3c.dom.Document document) 1241{ 1242 1243 DOMImplementation implementation; 1244 boolean result = false; 1245 boolean OK = true; 1246 implementation = document.getImplementation(); 1249 result = implementation.hasFeature("XML", "1.0"); 1250 if(!result) 1251 { 1252 System.out.println("Warning!!! DOMImplementation's 'hasFeature' that should be 'true' failed!"); 1253 OK = false; 1254 } 1255 1256 result = implementation.hasFeature("HTML", "4.0"); 1257 if(result) 1258 { 1259 System.out.println("Warning!!! DOMImplementation's 'hasFeature' that should be 'false' failed!"); 1260 OK = false; 1261 } 1262 1263 1264 if (!OK) 1266 System.out.println("\n*****The DOMImplementation method calls listed above failed, all others worked correctly.*****"); 1267} 1269 1276public void testElement(org.w3c.dom.Document document) 1277{ 1278 Attr attributeNode, newAttributeNode; 1279 Element element, element2; 1280 Node node, node2; 1281 String attribute, compare; 1282 String [] attributeCompare = {"AnotherFirstElementAttribute", "dFirstElement", "testAttribute"}; 1283 String [] elementNames = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32", 1284 "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"}; 1285 String [] textCompare = {"dBodyLevel31'sChildTextNode11", "dBodyLevel31'sChildTextNode12", "dBodyLevel31'sChildTextNode13"}; 1286 NamedNodeMap nodeMap; 1287 boolean OK = true; 1288 node = document.getDocumentElement(); node2 = node.cloneNode(true); 1291 if (!(node.getNodeName().equals(node2.getNodeName()) && (node.getNodeValue() != null && node2.getNodeValue() != null) ? node.getNodeValue().equals(node2.getNodeValue()) :(node.getNodeValue() == null && node2.getNodeValue() == null))) { 1297 System.out.println("'cloneNode' did not clone the Element node correctly"); 1298 OK = false; 1299 } 1300 1302 element = document.getDocumentElement(); compare = ""; 1304 attribute = element.getAttribute(document + "'s test attribute"); 1305 if (! compare.equals(element.getAttribute(document + "'s test attribute"))) 1306 { 1307 System.out.println("Warning!!! Element's 'getAttribute' failed!"); 1308 OK = false; 1309 } 1310 1311 attributeNode = element.getAttributeNode(document + "FirstElement"); 1312 if(! (attributeNode == null)) 1313 { 1314 System.out.println("Warning!!! Element's 'getAttributeNode' failed! It should have returned 'null' here!"); 1315 OK = false; 1316 } 1317 1318 newAttributeNode = document.createAttribute("AnotherFirstElementAttribute"); 1319 newAttributeNode.setValue("A new attribute which helps test calls in Element"); 1320 element.setAttributeNode(newAttributeNode); 1321 nodeMap = element.getAttributes(); 1322 int size = nodeMap.getLength(); 1323 int k; 1324 for (k = 0; k < size; k++) 1325 { 1326 Node n = (Node ) nodeMap.item(k); 1327 if (! (attributeCompare[k].equals(n.getNodeName()))) 1328 { 1329 System.out.println("Warning!!! Comparison of firstElement's attributes failed at attribute #"+ (k+1) +" " + n.getNodeValue()); 1330 System.out.println("This failure can be a result of Element's 'setValue' and/or 'setAttributeNode' and/or 'getAttributes' failing."); 1331 OK = false; 1332 break; 1333 } 1334 } 1336 NodeList docElements = document.getElementsByTagName("*"); 1337 int docSize = docElements.getLength(); 1338 int i; 1339 for (i = 0; i < docSize; i++) 1340 { 1341 Node n = (Node ) docElements.item(i); 1342 if (! (elementNames[i].equals(n.getNodeName()))) 1343 { 1344 System.out.println("Warning!!! Comparison of Element's 'getElementsByTagName' and/or 'item' failed at element number " 1345 + i + " : " + n.getNodeName()); 1346 OK = false; 1347 break; 1348 } 1349 } 1351 element = (Element ) document.getElementsByTagName("dBodyLevel21").item(0); element2 = (Element ) document.getElementsByTagName("dBodyLevel31").item(0); NodeList text = ((Node ) element2).getChildNodes(); 1354 int textSize = text.getLength(); 1355 int j; 1356 for (j = 0; j < textSize; j++) 1357 { 1358 Node n = (Node ) text.item(j); 1359 if (! (textCompare[j].equals(n.getNodeValue()))) 1360 { 1361 System.out.println("Warning!!! Comparison of original text nodes via Node 'getChildNodes' & NodeList 'item'" 1362 + "failed at text node: #" + j +" " + n.getNodeValue()); 1363 OK = false; 1364 break; 1365 } 1366 } 1368 element = document.getDocumentElement(); element.normalize(); NodeList text2 = ((Node ) element2).getChildNodes(); 1371 compare = "dBodyLevel31'sChildTextNode11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13"; 1372 Node n = (Node ) text2.item(0); 1373 if (! (compare.equals(n.getNodeValue()))) 1374 { 1375 System.out.println("Warning!!! Comparison of concatenated text nodes created by Element's 'normalize' failed!"); 1376 OK = false; 1377 } 1378 1379 element.setAttribute("FirstElementLastAttribute", "More attribute stuff for firstElement!!"); 1380 element.removeAttribute("FirstElementLastAttribute"); 1381 element.removeAttributeNode(newAttributeNode); 1382 1383 1385 if (!OK) 1387 System.out.println("\n*****The Element method calls listed above failed, all others worked correctly.*****"); 1388} 1390 1397public void testEntity(org.w3c.dom.Document document) 1398{ 1399 Entity entity; 1400 Node node, node2; 1401 boolean OK = true; 1402 String compare; 1403 entity = (Entity ) document.getDoctype().getEntities().getNamedItem("ourEntityNode"); 1405 node = entity; 1406 node2 = entity.cloneNode(true); 1407 if (!(node.getNodeName().equals(node2.getNodeName()) && (node.getNodeValue() != null && node2.getNodeValue() != null) ? node.getNodeValue().equals(node2.getNodeValue()) : (node.getNodeValue() == null && node2.getNodeValue() == null))) { 1413 System.out.println("Warning!!! 'cloneNode' did not clone the Entity node correctly"); 1414 OK = false; 1415 } 1416 1418 ((org.enhydra.apache.xerces.dom.EntityImpl) entity).setNotationName("testNotationName"); 1419 compare = "testNotationName"; 1420 if(! compare.equals(entity.getNotationName())) 1421 { 1422 System.out.println("Warning!!! Entity's 'setNotationName' and/or getNotationName' failed!"); 1423 OK = false; 1424 } 1425 ((org.enhydra.apache.xerces.dom.EntityImpl) entity).setPublicId("testPublicId"); 1426 compare = "testPublicId"; 1427 if(! compare.equals(entity.getPublicId())) 1428 { 1429 System.out.println("Warning!!! Entity's 'setPublicId' and/or getPublicId' failed!"); 1430 OK = false; 1431 } 1432 ((org.enhydra.apache.xerces.dom.EntityImpl) entity).setSystemId("testSystemId"); 1433 compare = "testSystemId"; 1434 if(! compare.equals(entity.getSystemId())) 1435 { 1436 System.out.println("Warning!!! Entity's 'setSystemId' and/or getSystemId' failed!"); 1437 OK = false; 1438 } 1439 1441 if (!OK) 1443 System.out.println("\n*****The Entity method calls listed above failed, all others worked correctly.*****"); 1444} 1446 1453public void testEntityReference(org.w3c.dom.Document document) 1454{ 1455 EntityReference entityReference; 1456 Node node, node2; 1457 boolean OK = true; 1458 entityReference = (EntityReference ) document.getLastChild().getLastChild().getLastChild().getFirstChild(); 1460 node = entityReference; 1461 node2 = node.cloneNode(true); 1462 if (!(node.getNodeName().equals(node2.getNodeName()) && (node.getNodeValue() != null && node2.getNodeValue() != null) ? node.getNodeValue().equals(node2.getNodeValue()) :(node.getNodeValue() == null && node2.getNodeValue() == null))) { 1468 System.out.println("'cloneNode' did not clone the EntityReference node correctly"); 1469 OK = false; 1470 } 1471 1473 1475 if (!OK) 1477 System.out.println("\n*****The EntityReference method calls listed above failed, all others worked correctly.*****"); 1478} 1480 1491public void testNode(org.w3c.dom.Document document) 1492{ 1493 Node node, node2; 1494 boolean result; 1495 boolean OK = true; 1496 node = document.getDocumentElement(); 1498 node2 = node.cloneNode(true); 1499 result = treeCompare(node, node2); if (result) 1501 { 1502 } 1504 else 1505 { 1506 System.out.println("'cloneNode' did not successfully clone this whole node tree (deep)!"); 1507 OK = false; 1508 } 1509 node = document.getDocumentElement(); 1511 node2 = node.getFirstChild(); 1512 result = treeCompare(node, node2); 1513 if (!result) 1514 { 1515 } 1517 else 1518 { 1519 System.out.println("'cloneNode' was supposed to fail here, either it or 'treeCompare' failed!!!"); 1520 OK = false; 1521 } 1522 1524 if (!OK) 1526 System.out.println("\n*****The Node method calls listed above failed, all others worked correctly.*****"); 1527} 1529 1536public void testNotation(org.w3c.dom.Document document) 1537{ 1538 Node node, node2; 1539 Notation notation; 1540 boolean OK = true; 1541 String compare; 1542 notation = (Notation ) document.getDoctype().getNotations().getNamedItem("ourNotationNode"); 1544 node = notation; 1545 node2 = notation.cloneNode(true); if (!(node.getNodeName().equals(node2.getNodeName()) && (node.getNodeValue() != null && node2.getNodeValue() != null) ? node.getNodeValue().equals(node2.getNodeValue()) :(node.getNodeValue() == null && node2.getNodeValue() == null))) { 1552 System.out.println("'cloneNode' did not clone the Notation node correctly"); 1553 OK = false; 1554 } 1555 1557 ((org.enhydra.apache.xerces.dom.NotationImpl) notation).setPublicId("testPublicId"); compare = "testPublicId"; 1559 if (!compare.equals(notation.getPublicId())) 1560 { 1561 System.out.println("Warning!!! Notation's 'getPublicId' failed!"); 1562 OK = false; 1563 } 1564 ((org.enhydra.apache.xerces.dom.NotationImpl) notation).setSystemId("testSystemId"); compare = "testSystemId"; 1566 if (! compare.equals(notation.getSystemId())) 1567 { 1568 System.out.println("Warning!!! Notation's 'getSystemId' failed!"); 1569 OK = false; 1570 } 1571 1573 if (!OK) 1575 System.out.println("\n*****The Notation method calls listed above failed, all others worked correctly.*****"); 1576} 1578 1585public void testPI(org.w3c.dom.Document document) 1586{ 1587 Node node, node2; 1588 ProcessingInstruction pI, pI2; 1589 String compare; 1590 boolean OK = true; 1591 pI = (ProcessingInstruction ) document.getDocumentElement().getFirstChild(); pI2 = (org.enhydra.apache.xerces.dom.ProcessingInstructionImpl) pI.cloneNode(true); if (!(pI.getNodeName().equals(pI2.getNodeName()) && (pI.getNodeValue() != null && pI2.getNodeValue() != null) ? pI.getNodeValue().equals(pI2.getNodeValue()) :(pI.getNodeValue() == null && pI2.getNodeValue() == null))) { 1600 System.out.println("'cloneNode' did not clone the Entity node correctly"); 1601 OK = false; 1602 } 1603 compare = "This is [#document: null]'s processing instruction"; 1605 if (! compare.equals(pI.getData())) 1606 { 1607 System.out.println("Warning!!! PI's 'getData' failed!"); 1608 OK = false; 1609 } 1610 1611 pI.setData("PI's reset data"); 1612 compare = "PI's reset data"; 1613 if (! compare.equals(pI.getData())) 1614 { 1615 System.out.println("Warning!!! PI's 'setData' failed!"); 1616 OK = false; 1617 } 1618 compare = "dTargetProcessorChannel"; 1619 if (! compare.equals(pI.getTarget())) 1620 { 1621 System.out.println("Warning!!! PI's 'getTarget' failed!"); 1622 OK = false; 1623 } 1624 1625 if (!OK) 1627 System.out.println("\n*****The PI method calls listed above failed, all others worked correctly.*****"); 1628 1629} 1631 1638public void testText(org.w3c.dom.Document document) 1639{ 1640 Node node, node2; 1641 Text text; 1642 String compare; 1643 boolean OK = true; 1644 node = document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); text = (Text ) node; 1647 node2 = node.cloneNode(true); if (!(node.getNodeName().equals(node2.getNodeName()) && (node.getNodeValue() != null && node2.getNodeValue() != null) ? node.getNodeValue().equals(node2.getNodeValue()) :(node.getNodeValue() == null && node2.getNodeValue() == null))) { 1654 System.out.println("'cloneNode' did not clone the Text node correctly"); 1655 OK = false; 1656 } 1657 text.splitText(25); 1659 compare = "dBodyLevel31'sChildTextNo"; if (! compare.equals(text.getNodeValue())) 1661 { 1662 System.out.println("First part of Text's split text failed!" ); 1663 OK = false; 1664 } 1665 compare = "de11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13"; if (! compare.equals(text.getNextSibling().getNodeValue())) 1667 { 1668 System.out.println("The second part of Text's split text failed!") ; 1669 OK = false; 1670 } 1671 1672 1673 1674 1675 1677 1681 if (!OK) 1683 System.out.println("\n*****The Text method calls listed above failed, all others worked correctly.*****"); 1684 1685} 1687 1694public boolean treeCompare(Node node, Node node2) 1695{ 1696 boolean answer = true; 1697 1698 Node kid, kid2; kid = node.getFirstChild(); 1700 kid2 = node2.getFirstChild(); 1701 if (kid != null && kid2 != null) 1702 { 1703 answer = treeCompare(kid, kid2); 1704 if (!answer) 1705 return answer; 1706 else 1707 if (kid.getNextSibling() != null && kid2.getNextSibling() != null) 1708 { 1709 while (kid.getNextSibling() != null && kid2.getNextSibling() != null) 1710 { 1711 answer = treeCompare(kid.getNextSibling(), kid2.getNextSibling()); 1712 if (!answer) 1713 return answer; 1714 else 1715 { 1716 kid = kid.getNextSibling(); 1717 kid2 = kid2.getNextSibling(); 1718 } 1719 } 1720 } else 1721 if (!(kid.getNextSibling() == null && kid2.getNextSibling() == null)) 1722 { 1723 return false; 1724 } 1725 } else 1726 if (kid != kid2) 1727 { 1728 return false; 1729 } 1730 1731 if (!(node.getNodeName().equals(node2.getNodeName()) && (node.getNodeValue() != null && node2.getNodeValue() != null) ? node.getNodeValue().equals(node2.getNodeValue()) :(node.getNodeValue() == null && node2.getNodeValue() == null))) { 1737 return false; } 1739 return answer; 1740} 1741} 1742 | Popular Tags |