1 5 6 package org.w3c.tidy; 7 8 import org.w3c.dom.DOMException ; 9 10 30 31 public class DOMNodeImpl implements org.w3c.dom.Node { 32 33 protected Node adaptee; 34 35 protected DOMNodeImpl(Node adaptee) 36 { 37 this.adaptee = adaptee; 38 } 39 40 41 42 43 46 public String getNodeValue() throws DOMException 47 { 48 String value = ""; if (adaptee.type == Node.TextNode || 50 adaptee.type == Node.CDATATag || 51 adaptee.type == Node.CommentTag || 52 adaptee.type == Node.ProcInsTag) 53 { 54 55 if (adaptee.textarray != null && adaptee.start < adaptee.end) 56 { 57 value = Lexer.getString(adaptee.textarray, 58 adaptee.start, 59 adaptee.end - adaptee.start); 60 } 61 } 62 return value; 63 } 64 65 68 public void setNodeValue(String nodeValue) throws DOMException 69 { 70 if (adaptee.type == Node.TextNode || 71 adaptee.type == Node.CDATATag || 72 adaptee.type == Node.CommentTag || 73 adaptee.type == Node.ProcInsTag) 74 { 75 byte[] textarray = Lexer.getBytes(nodeValue); 76 adaptee.textarray = textarray; 77 adaptee.start = 0; 78 adaptee.end = textarray.length; 79 } 80 } 81 82 85 public String getNodeName() 86 { 87 return adaptee.element; 88 } 89 90 93 public short getNodeType() 94 { 95 short result = -1; 96 switch (adaptee.type) { 97 case Node.RootNode: 98 result = org.w3c.dom.Node.DOCUMENT_NODE; 99 break; 100 case Node.DocTypeTag: 101 result = org.w3c.dom.Node.DOCUMENT_TYPE_NODE; 102 break; 103 case Node.CommentTag: 104 result = org.w3c.dom.Node.COMMENT_NODE; 105 break; 106 case Node.ProcInsTag: 107 result = org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE; 108 break; 109 case Node.TextNode: 110 result = org.w3c.dom.Node.TEXT_NODE; 111 break; 112 case Node.CDATATag: 113 result = org.w3c.dom.Node.CDATA_SECTION_NODE; 114 break; 115 case Node.StartTag: 116 case Node.StartEndTag: 117 result = org.w3c.dom.Node.ELEMENT_NODE; 118 break; 119 } 120 return result; 121 } 122 123 126 public org.w3c.dom.Node getParentNode() 127 { 128 if (adaptee.parent != null) 129 return adaptee.parent.getAdapter(); 130 else 131 return null; 132 } 133 134 137 public org.w3c.dom.NodeList getChildNodes() 138 { 139 return new DOMNodeListImpl(adaptee); 140 } 141 142 145 public org.w3c.dom.Node getFirstChild() 146 { 147 if (adaptee.content != null) 148 return adaptee.content.getAdapter(); 149 else 150 return null; 151 } 152 153 156 public org.w3c.dom.Node getLastChild() 157 { 158 if (adaptee.last != null) 159 return adaptee.last.getAdapter(); 160 else 161 return null; 162 } 163 164 167 public org.w3c.dom.Node getPreviousSibling() 168 { 169 if (adaptee.prev != null) 170 return adaptee.prev.getAdapter(); 171 else 172 return null; 173 } 174 175 178 public org.w3c.dom.Node getNextSibling() 179 { 180 if (adaptee.next != null) 181 return adaptee.next.getAdapter(); 182 else 183 return null; 184 } 185 186 189 public org.w3c.dom.NamedNodeMap getAttributes() 190 { 191 return new DOMAttrMapImpl(adaptee.attributes); 192 } 193 194 197 public org.w3c.dom.Document getOwnerDocument() 198 { 199 Node node; 200 201 node = this.adaptee; 202 if (node != null && node.type == Node.RootNode) 203 return null; 204 205 for (node = this.adaptee; 206 node != null && node.type != Node.RootNode; node = node.parent); 207 208 if (node != null) 209 return (org.w3c.dom.Document )node.getAdapter(); 210 else 211 return null; 212 } 213 214 217 public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, 218 org.w3c.dom.Node refChild) 219 throws DOMException 220 { 221 223 if (newChild == null) 224 return null; 225 if (!(newChild instanceof DOMNodeImpl)) { 226 throw new DOMExceptionImpl(DOMException.WRONG_DOCUMENT_ERR, 227 "newChild not instanceof DOMNodeImpl"); 228 } 229 DOMNodeImpl newCh = (DOMNodeImpl)newChild; 230 231 if (this.adaptee.type == Node.RootNode) { 232 if (newCh.adaptee.type != Node.DocTypeTag && 233 newCh.adaptee.type != Node.ProcInsTag) { 234 throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, 235 "newChild cannot be a child of this node"); 236 } 237 } else if (this.adaptee.type == Node.StartTag) { 238 if (newCh.adaptee.type != Node.StartTag && 239 newCh.adaptee.type != Node.StartEndTag && 240 newCh.adaptee.type != Node.CommentTag && 241 newCh.adaptee.type != Node.TextNode && 242 newCh.adaptee.type != Node.CDATATag) { 243 throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, 244 "newChild cannot be a child of this node"); 245 } 246 } 247 if (refChild == null) { 248 Node.insertNodeAtEnd(this.adaptee, newCh.adaptee); 249 if (this.adaptee.type == Node.StartEndTag) { 250 this.adaptee.setType(Node.StartTag); 251 } 252 } else { 253 Node ref = this.adaptee.content; 254 while (ref != null) { 255 if (ref.getAdapter() == refChild) break; 256 ref = ref.next; 257 } 258 if (ref == null) { 259 throw new DOMExceptionImpl(DOMException.NOT_FOUND_ERR, 260 "refChild not found"); 261 } 262 Node.insertNodeBeforeElement(ref, newCh.adaptee); 263 } 264 return newChild; 265 } 266 267 270 public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, 271 org.w3c.dom.Node oldChild) 272 throws DOMException 273 { 274 276 if (newChild == null) 277 return null; 278 if (!(newChild instanceof DOMNodeImpl)) { 279 throw new DOMExceptionImpl(DOMException.WRONG_DOCUMENT_ERR, 280 "newChild not instanceof DOMNodeImpl"); 281 } 282 DOMNodeImpl newCh = (DOMNodeImpl)newChild; 283 284 if (this.adaptee.type == Node.RootNode) { 285 if (newCh.adaptee.type != Node.DocTypeTag && 286 newCh.adaptee.type != Node.ProcInsTag) { 287 throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, 288 "newChild cannot be a child of this node"); 289 } 290 } else if (this.adaptee.type == Node.StartTag) { 291 if (newCh.adaptee.type != Node.StartTag && 292 newCh.adaptee.type != Node.StartEndTag && 293 newCh.adaptee.type != Node.CommentTag && 294 newCh.adaptee.type != Node.TextNode && 295 newCh.adaptee.type != Node.CDATATag) { 296 throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, 297 "newChild cannot be a child of this node"); 298 } 299 } 300 if (oldChild == null) { 301 throw new DOMExceptionImpl(DOMException.NOT_FOUND_ERR, 302 "oldChild not found"); 303 } else { 304 Node n; 305 Node ref = this.adaptee.content; 306 while (ref != null) { 307 if (ref.getAdapter() == oldChild) break; 308 ref = ref.next; 309 } 310 if (ref == null) { 311 throw new DOMExceptionImpl(DOMException.NOT_FOUND_ERR, 312 "oldChild not found"); 313 } 314 newCh.adaptee.next = ref.next; 315 newCh.adaptee.prev = ref.prev; 316 newCh.adaptee.last = ref.last; 317 newCh.adaptee.parent = ref.parent; 318 newCh.adaptee.content = ref.content; 319 if (ref.parent != null) { 320 if (ref.parent.content == ref) 321 ref.parent.content = newCh.adaptee; 322 if (ref.parent.last == ref) 323 ref.parent.last = newCh.adaptee; 324 } 325 if (ref.prev != null) { 326 ref.prev.next = newCh.adaptee; 327 } 328 if (ref.next != null) { 329 ref.next.prev = newCh.adaptee; 330 } 331 for (n = ref.content; n != null; n = n.next) { 332 if (n.parent == ref) 333 n.parent = newCh.adaptee; 334 } 335 } 336 return oldChild; 337 } 338 339 342 public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) 343 throws DOMException 344 { 345 if (oldChild == null) 346 return null; 347 348 Node ref = this.adaptee.content; 349 while (ref != null) { 350 if (ref.getAdapter() == oldChild) break; 351 ref = ref.next; 352 } 353 if (ref == null) { 354 throw new DOMExceptionImpl(DOMException.NOT_FOUND_ERR, 355 "refChild not found"); 356 } 357 Node.discardElement(ref); 358 359 if (this.adaptee.content == null 360 && this.adaptee.type == Node.StartTag) { 361 this.adaptee.setType(Node.StartEndTag); 362 } 363 364 return oldChild; 365 } 366 367 370 public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) 371 throws DOMException 372 { 373 375 if (newChild == null) 376 return null; 377 if (!(newChild instanceof DOMNodeImpl)) { 378 throw new DOMExceptionImpl(DOMException.WRONG_DOCUMENT_ERR, 379 "newChild not instanceof DOMNodeImpl"); 380 } 381 DOMNodeImpl newCh = (DOMNodeImpl)newChild; 382 383 if (this.adaptee.type == Node.RootNode) { 384 if (newCh.adaptee.type != Node.DocTypeTag && 385 newCh.adaptee.type != Node.ProcInsTag) { 386 throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, 387 "newChild cannot be a child of this node"); 388 } 389 } else if (this.adaptee.type == Node.StartTag) { 390 if (newCh.adaptee.type != Node.StartTag && 391 newCh.adaptee.type != Node.StartEndTag && 392 newCh.adaptee.type != Node.CommentTag && 393 newCh.adaptee.type != Node.TextNode && 394 newCh.adaptee.type != Node.CDATATag) { 395 throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, 396 "newChild cannot be a child of this node"); 397 } 398 } 399 Node.insertNodeAtEnd(this.adaptee, newCh.adaptee); 400 401 if (this.adaptee.type == Node.StartEndTag) { 402 this.adaptee.setType(Node.StartTag); 403 } 404 405 return newChild; 406 } 407 408 411 public boolean hasChildNodes() 412 { 413 return (adaptee.content != null); 414 } 415 416 419 public org.w3c.dom.Node cloneNode(boolean deep) 420 { 421 Node node = adaptee.cloneNode(deep); 422 node.parent = null; 423 return node.getAdapter(); 424 } 425 426 429 public void normalize() 430 { 431 } 432 433 436 public boolean supports(String feature, String version) 437 { 438 return isSupported(feature, version); 439 } 440 441 444 public String getNamespaceURI() 445 { 446 return null; 447 } 448 449 452 public String getPrefix() 453 { 454 return null; 455 } 456 457 460 public void setPrefix(String prefix) 461 throws DOMException 462 { 463 } 464 465 468 public String getLocalName() 469 { 470 return null; 471 } 472 473 476 public boolean isSupported(String feature,String version) { 477 return false; 478 } 479 480 484 public boolean hasAttributes() 485 { 486 return adaptee.attributes != null; 487 } 488 489 public org.w3c.dom.Node adoptNode (org.w3c.dom.Node oNode) { 490 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl adoptNode() Not implemented"); 491 } 492 493 public short compareDocumentPosition (org.w3c.dom.Node oNode) { 494 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl compareDocumentPosition() Not implemented"); 495 } 496 497 public boolean isDefaultNamespace(String sStr1) { 498 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl isDefaultNamespace() Not implemented"); 499 } 500 501 public boolean isEqualNode(org.w3c.dom.Node oNode) { 502 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl isEqualNode() Not implemented"); 503 } 504 505 public boolean isSameNode(org.w3c.dom.Node oNode) { 506 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl isSameNode() Not implemented"); 507 } 508 509 public String lookupPrefix(String sStr1) { 510 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl lookupPreffix() Not implemented"); 511 } 512 513 public String lookupNamespaceURI(String sStr1) { 514 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl lookupNamespaceURI() Not implemented"); 515 } 516 517 public String getDocumentURI() { 518 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getDocumentURI() Not implemented"); 519 } 520 521 public void setDocumentURI(String sStr1) { 522 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl setDocumentURI() Not implemented"); 523 } 524 525 public boolean getStrictErrorChecking() { 526 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getStrictErrorChecking() Not implemented"); 527 } 528 529 public void setStrictErrorChecking(boolean bStrictCheck) { 530 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl setStrictErrorChecking() Not implemented"); 531 } 532 533 public boolean getXmlStandalone() { 534 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getXmlStandalone() Not implemented"); 535 } 536 537 public void setXmlStandalone(boolean bXmlStandalone) { 538 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl setXmlStandalone() Not implemented"); 539 } 540 541 public Object getFeature(String sStr1, String sStr2) { 542 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getFeature() Not implemented"); 543 } 544 545 public String getInputEncoding() { 546 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getInputEncoding() Not implemented"); 547 } 548 549 public String getXmlEncoding() { 550 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getXmlEncoding() Not implemented"); 551 } 552 553 public String getXmlVersion() { 554 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getXmlVersion() Not implemented"); 555 } 556 557 public void setXmlVersion(String sStr1) { 558 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl setXmlVersion() Not implemented"); 559 } 560 561 public Object getUserData(String sStr1) { 562 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getUserData() Not implemented"); 563 } 564 565 public Object setUserData(String sStr1, Object oObj2, org.w3c.dom.UserDataHandler oHndlr) { 566 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl setUserData() Not implemented"); 567 } 568 569 public org.w3c.dom.DOMConfiguration getDomConfig () { 570 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getDomConfig() Not implemented"); 571 } 572 573 public void normalizeDocument () { 574 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl normalizeDocument() Not implemented"); 575 } 576 577 public org.w3c.dom.Node renameNode (org.w3c.dom.Node oNode, String sStr1, String sStr2) { 578 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl renameNode() Not implemented"); 579 } 580 581 public String getBaseURI() { 582 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getBaseURI() Not implemented"); 583 } 584 585 public String getTextContent() { 586 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl getTextContent() Not implemented"); 587 } 588 589 public void setTextContent(String sStr1) { 590 throw new UnsupportedOperationException ("org.w3c.tidy.DOMNodeImpl setTextContent() Not implemented"); 591 } 592 593 } 594 | Popular Tags |