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, import a entity node ent4 40 * from this document to a new document object. The replacement text of this entity is an element 41 * node, a cdata node and a pi. Verify if the nodes have been 42 * imported correctly by checking the nodeNames of the imported element node, the data for the 43 * cdata nodes and the PItarget and PIData for the pi nodes. 44 * @author IBM 45 * @author Neil Delima 46 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core">http://www.w3.org/TR/DOM-Level-2-Core/core</a> 47 * @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> 48 */ 49 public final class documentimportnode20 extends DOMTestCase { 50 51 /** 52 * Constructor. 53 * @param factory document factory, may not be null 54 * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration 55 */ 56 public documentimportnode20(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException { 57 58 org.w3c.domts.DocumentBuilderSetting[] settings = 59 new org.w3c.domts.DocumentBuilderSetting[] { 60 org.w3c.domts.DocumentBuilderSetting.namespaceAware, 61 org.w3c.domts.DocumentBuilderSetting.notExpandEntityReferences 62 }; 63 DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings); 64 setFactory(testFactory); 65 66 // 67 // check if loaded documents are supported for content type 68 // 69 String contentType = getContentType(); 70 preload(contentType, "staffNS", true); 71 } 72 73 /** 74 * Runs the test case. 75 * @throws Throwable Any uncaught exception causes test to fail 76 */ 77 public void runTest() throws Throwable { 78 Document doc; 79 Document docImp; 80 DOMImplementation domImpl; 81 DocumentType docType; 82 DocumentType docTypeNull = null; 83 84 NamedNodeMap nodeMap; 85 Entity entity4; 86 Entity entityImp4; 87 Element element; 88 CharacterData cdata; 89 ProcessingInstruction pi; 90 NodeList childList; 91 NodeList elemchildList; 92 String ent4Name; 93 String ent4ImpName; 94 String cdataVal; 95 String piTargetVal; 96 String piDataVal; 97 doc = (Document) load("staffNS", true); 98 domImpl = doc.getImplementation(); 99 docType = doc.getDoctype(); 100 docImp = domImpl.createDocument("http://www.w3.org/DOM/Test", "a:b", docTypeNull); 101 nodeMap = docType.getEntities(); 102 entity4 = (Entity) nodeMap.getNamedItem("ent4"); 103 entityImp4 = (Entity) docImp.importNode(entity4, true); 104 childList = entityImp4.getChildNodes(); 105 element = (Element) childList.item(0); 106 elemchildList = element.getChildNodes(); 107 cdata = (CharacterData) elemchildList.item(0); 108 pi = (ProcessingInstruction) childList.item(1); 109 ent4Name = entity4.getNodeName(); 110 ent4ImpName = entityImp4.getNodeName(); 111 cdataVal = cdata.getData(); 112 piTargetVal = pi.getTarget(); 113 piDataVal = pi.getData(); 114 assertEquals("documentimportnode20_Ent4NodeName", ent4Name, ent4ImpName); 115 assertEquals("documentimportnode20_Cdata", "Element data", cdataVal); 116 assertEquals("documentimportnode20_PITarget", "PItarget", piTargetVal); 117 assertEquals("documentimportnode20_PIData", "PIdata", piDataVal); 118 } 119 /** 120 * Gets URI that identifies the test. 121 * @return uri identifier of test 122 */ 123 public String getTargetURI() { 124 return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/documentimportnode20"; 125 } 126 /** 127 * Runs this test from the command line. 128 * @param args command line arguments 129 */ 130 public static void main(final String[] args) { 131 DOMTestCase.doMain(documentimportnode20.class, args); 132 } 133 } 134 135