1 2 /* 3 This Java source file was generated by test-to-java.xsl 4 and is a derived work from the source document. 5 The source document contained the following notice: 6 7 8 9 Copyright (c) 2001 World Wide Web Consortium, 10 (Massachusetts Institute of Technology, Institut National de 11 Recherche en Informatique et en Automatique, Keio University). All 12 Rights Reserved. This program is distributed under the W3C's Software 13 Intellectual Property License. This program is distributed in the 14 hope that it will be useful, but WITHOUT ANY WARRANTY; without even 15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 PURPOSE. 17 18 See W3C License http://www.w3.org/Consortium/Legal/ for more details. 19 20 21 */ 22 23 package org.w3c.domts.level2.core; 24 25 import org.w3c.dom.*; 26 27 28 import org.w3c.domts.DOMTestCase; 29 import org.w3c.domts.DOMTestDocumentBuilderFactory; 30 31 32 33 /** 34 * The importNode method imports a node from another document to this document. 35 * The returned node has no parent; (parentNode is null). The source node is not 36 * altered or removed from the original document but a new copy of the source node 37 * is created. 38 * 39 * Using the method importNode with deep=true, retreive the entity refs present in the 40 * second element node whose tagName is address and import these nodes into another document. 41 * Verify if the nodes have been imported correctly by checking the nodeNames of the 42 * imported nodes, since they are imported into a new document which doesnot have thes defined, 43 * the imported nodes should not have any children. 44 * Now import the entityRef nodes into the same document and verify if the nodes have been 45 * imported correctly by checking the nodeNames of the imported nodes, and by checking the 46 * value of the replacement text of the imported nodes. 47 * @author IBM 48 * @author Neil Delima 49 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core">http://www.w3.org/TR/DOM-Level-2-Core/core</a> 50 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#Core-Document-importNode">http://www.w3.org/TR/DOM-Level-2-Core/core#Core-Document-importNode</a> 51 */ 52 public final class documentimportnode21 extends DOMTestCase { 53 54 /** 55 * Constructor. 56 * @param factory document factory, may not be null 57 * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration 58 */ 59 public documentimportnode21(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException { 60 61 org.w3c.domts.DocumentBuilderSetting[] settings = 62 new org.w3c.domts.DocumentBuilderSetting[] { 63 org.w3c.domts.DocumentBuilderSetting.namespaceAware, 64 org.w3c.domts.DocumentBuilderSetting.notExpandEntityReferences 65 }; 66 DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings); 67 setFactory(testFactory); 68 69 // 70 // check if loaded documents are supported for content type 71 // 72 String contentType = getContentType(); 73 preload(contentType, "staffNS", true); 74 } 75 76 /** 77 * Runs the test case. 78 * @throws Throwable Any uncaught exception causes test to fail 79 */ 80 public void runTest() throws Throwable { 81 Document doc; 82 DocumentType docTypeNull = null; 83 84 Document docImp; 85 DOMImplementation domImpl; 86 NodeList addressList; 87 NodeList addressChildList; 88 Element element; 89 EntityReference entRef2; 90 EntityReference entRefImp2; 91 EntityReference entRef3; 92 EntityReference entRefImp3; 93 String nodeName2; 94 String nodeName3; 95 String nodeNameImp2; 96 String nodeNameImp3; 97 NodeList nodes; 98 Node nodeImp3; 99 Node nodeImp2; 100 String nodeValueImp2; 101 String nodeValueImp3; 102 doc = (Document) load("staffNS", true); 103 domImpl = doc.getImplementation(); 104 docImp = domImpl.createDocument("http://www.w3.org/DOM/Test", "a:b", docTypeNull); 105 addressList = doc.getElementsByTagName("address"); 106 element = (Element) addressList.item(1); 107 addressChildList = element.getChildNodes(); 108 entRef2 = (EntityReference) addressChildList.item(0); 109 entRef3 = (EntityReference) addressChildList.item(2); 110 entRefImp2 = (EntityReference) docImp.importNode(entRef2, true); 111 entRefImp3 = (EntityReference) docImp.importNode(entRef3, false); 112 nodeName2 = entRef2.getNodeName(); 113 nodeName3 = entRef3.getNodeName(); 114 nodeNameImp2 = entRefImp2.getNodeName(); 115 nodeNameImp3 = entRefImp3.getNodeName(); 116 assertEquals("documentimportnode21_Ent2NodeName", nodeName2, nodeNameImp2); 117 assertEquals("documentimportnode21_Ent3NodeName", nodeName3, nodeNameImp3); 118 entRefImp2 = (EntityReference) doc.importNode(entRef2, true); 119 entRefImp3 = (EntityReference) doc.importNode(entRef3, false); 120 nodes = entRefImp2.getChildNodes(); 121 nodeImp2 = nodes.item(0); 122 nodeValueImp2 = nodeImp2.getNodeValue(); 123 nodes = entRefImp3.getChildNodes(); 124 nodeImp3 = nodes.item(0); 125 nodeValueImp3 = nodeImp3.getNodeValue(); 126 assertEquals("documentimportnode21_Ent2NodeValue", "1900 Dallas Road", nodeValueImp2); 127 assertEquals("documentimportnode21_Ent3Nodevalue", "Texas", nodeValueImp3); 128 } 129 /** 130 * Gets URI that identifies the test. 131 * @return uri identifier of test 132 */ 133 public String getTargetURI() { 134 return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/documentimportnode21"; 135 } 136 /** 137 * Runs this test from the command line. 138 * @param args command line arguments 139 */ 140 public static void main(final String[] args) { 141 DOMTestCase.doMain(documentimportnode21.class, args); 142 } 143 } 144 145