1 9 package org.netbeans.test.editor.indentation.programmatic; 10 26 public class DefinitionScanner { 27 28 org.w3c.dom.Document document; 29 30 private IndentCoreGenerator.TestCase testCase; 31 32 33 public DefinitionScanner(org.w3c.dom.Document document) { 34 this.document = document; 35 } 36 37 38 public void visitDocument() { 39 org.w3c.dom.Element element = document.getDocumentElement(); 40 if ((element != null) && element.getTagName().equals("definition")) { 41 visitElement_definition(element); 42 } 43 if ((element != null) && element.getTagName().equals("fail")) { 44 visitElement_fail(element); 45 } 46 if ((element != null) && element.getTagName().equals("indentation-properties")) { 47 visitElement_indentation_properties(element); 48 } 49 if ((element != null) && element.getTagName().equals("property")) { 50 visitElement_property(element); 51 } 52 if ((element != null) && element.getTagName().equals("reason")) { 53 visitElement_reason(element); 54 } 55 if ((element != null) && element.getTagName().equals("test-case")) { 56 visitElement_test_case(element); 57 } 58 if ((element != null) && element.getTagName().equals("text")) { 59 visitElement_text(element); 60 } 61 } 62 63 64 void visitElement_definition(org.w3c.dom.Element element) { org.w3c.dom.NodeList nodes = element.getChildNodes(); 67 for (int i = 0; i < nodes.getLength(); i++) { 68 org.w3c.dom.Node node = nodes.item(i); 69 switch (node.getNodeType()) { 70 case org.w3c.dom.Node.CDATA_SECTION_NODE: 71 break; 73 case org.w3c.dom.Node.ELEMENT_NODE: 74 org.w3c.dom.Element nodeElement = (org.w3c.dom.Element )node; 75 if (nodeElement.getTagName().equals("test-case")) { 76 visitElement_test_case(nodeElement); 77 } 78 break; 79 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE: 80 break; 83 } 84 } 85 } 86 87 88 void visitElement_fail(org.w3c.dom.Element element) { org.w3c.dom.NamedNodeMap attrs = element.getAttributes(); 91 for (int i = 0; i < attrs.getLength(); i++) { 92 org.w3c.dom.Attr attr = (org.w3c.dom.Attr )attrs.item(i); 93 if (attr.getName().equals("supposed-to-fail")) { testCase.setWillFail(Boolean.valueOf(attr.getValue()).booleanValue()); 95 } 96 } 97 org.w3c.dom.NodeList nodes = element.getChildNodes(); 98 for (int i = 0; i < nodes.getLength(); i++) { 99 org.w3c.dom.Node node = nodes.item(i); 100 switch (node.getNodeType()) { 101 case org.w3c.dom.Node.CDATA_SECTION_NODE: 102 break; 104 case org.w3c.dom.Node.ELEMENT_NODE: 105 org.w3c.dom.Element nodeElement = (org.w3c.dom.Element )node; 106 if (nodeElement.getTagName().equals("reason")) { 107 visitElement_reason(nodeElement); 108 } 109 break; 110 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE: 111 break; 114 } 115 } 116 } 117 118 119 void visitElement_indentation_properties(org.w3c.dom.Element element) { org.w3c.dom.NodeList nodes = element.getChildNodes(); 122 for (int i = 0; i < nodes.getLength(); i++) { 123 org.w3c.dom.Node node = nodes.item(i); 124 switch (node.getNodeType()) { 125 case org.w3c.dom.Node.CDATA_SECTION_NODE: 126 break; 128 case org.w3c.dom.Node.ELEMENT_NODE: 129 org.w3c.dom.Element nodeElement = (org.w3c.dom.Element )node; 130 if (nodeElement.getTagName().equals("property")) { 131 visitElement_property(nodeElement); 132 } 133 break; 134 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE: 135 break; 138 } 139 } 140 } 141 142 143 void visitElement_property(org.w3c.dom.Element element) { org.w3c.dom.NamedNodeMap attrs = element.getAttributes(); 146 String property_name = null; 147 String property_value = null; 148 for (int i = 0; i < attrs.getLength(); i++) { 149 org.w3c.dom.Attr attr = (org.w3c.dom.Attr )attrs.item(i); 150 if (attr.getName().equals("name")) { property_name = attr.getValue(); 152 } 153 if (attr.getName().equals("value")) { property_value = attr.getValue(); 155 } 156 } 157 testCase.addIndentProperty(property_name, property_value); 158 org.w3c.dom.NodeList nodes = element.getChildNodes(); 159 for (int i = 0; i < nodes.getLength(); i++) { 160 org.w3c.dom.Node node = nodes.item(i); 161 switch (node.getNodeType()) { 162 case org.w3c.dom.Node.CDATA_SECTION_NODE: 163 break; 165 case org.w3c.dom.Node.ELEMENT_NODE: 166 org.w3c.dom.Element nodeElement = (org.w3c.dom.Element )node; 167 break; 168 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE: 169 break; 172 } 173 } 174 } 175 176 177 void visitElement_reason(org.w3c.dom.Element element) { testCase.setFailReason(element.getNodeValue()); org.w3c.dom.NodeList nodes = element.getChildNodes(); 180 for (int i = 0; i < nodes.getLength(); i++) { 181 org.w3c.dom.Node node = nodes.item(i); 182 switch (node.getNodeType()) { 183 case org.w3c.dom.Node.CDATA_SECTION_NODE: 184 break; 186 case org.w3c.dom.Node.ELEMENT_NODE: 187 org.w3c.dom.Element nodeElement = (org.w3c.dom.Element )node; 188 break; 189 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE: 190 break; 193 case org.w3c.dom.Node.TEXT_NODE: 194 break; 196 } 197 } 198 } 199 200 201 void visitElement_test_case(org.w3c.dom.Element element) { testCase = new IndentCoreGenerator.TestCase(); 204 org.w3c.dom.NamedNodeMap attrs = element.getAttributes(); 205 for (int i = 0; i < attrs.getLength(); i++) { 206 org.w3c.dom.Attr attr = (org.w3c.dom.Attr )attrs.item(i); 207 if (attr.getName().equals("name")) { testCase.setName(attr.getValue()); 209 } 210 } 211 org.w3c.dom.NodeList nodes = element.getChildNodes(); 212 for (int i = 0; i < nodes.getLength(); i++) { 213 org.w3c.dom.Node node = nodes.item(i); 214 switch (node.getNodeType()) { 215 case org.w3c.dom.Node.CDATA_SECTION_NODE: 216 break; 218 case org.w3c.dom.Node.ELEMENT_NODE: 219 org.w3c.dom.Element nodeElement = (org.w3c.dom.Element )node; 220 if (nodeElement.getTagName().equals("fail")) { 221 visitElement_fail(nodeElement); 222 } 223 if (nodeElement.getTagName().equals("indentation-properties")) { 224 visitElement_indentation_properties(nodeElement); 225 } 226 if (nodeElement.getTagName().equals("text")) { 227 visitElement_text(nodeElement); 228 } 229 break; 230 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE: 231 break; 234 } 235 } 236 IndentCoreGenerator.addTestCase(testCase); 237 } 238 239 240 void visitElement_text(org.w3c.dom.Element element) { org.w3c.dom.NamedNodeMap attrs = element.getAttributes(); 243 for (int i = 0; i < attrs.getLength(); i++) { 244 org.w3c.dom.Attr attr = (org.w3c.dom.Attr )attrs.item(i); 245 if (attr.getName().equals("location")) { testCase.setTextLocation(attr.getValue()); 247 } 248 if (attr.getName().equals("mime-type")) { testCase.setTextMIMEType(attr.getValue()); 250 } 251 } 252 org.w3c.dom.NodeList nodes = element.getChildNodes(); 253 for (int i = 0; i < nodes.getLength(); i++) { 254 org.w3c.dom.Node node = nodes.item(i); 255 switch (node.getNodeType()) { 256 case org.w3c.dom.Node.CDATA_SECTION_NODE: 257 break; 259 case org.w3c.dom.Node.ELEMENT_NODE: 260 org.w3c.dom.Element nodeElement = (org.w3c.dom.Element )node; 261 break; 262 case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE: 263 break; 266 } 267 } 268 } 269 270 271 } 272 | Popular Tags |