The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | * contributor license agreements. See the NOTICE file distributed with |
| 4 | * this work for additional information regarding copyright ownership. |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | * (the "License"); you may not use this file except in compliance with |
| 7 | * the License. You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | package javax.imageio.metadata; |
| 19 | |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.List; |
| 22 | |
| 23 | import org.w3c.dom.Attr; |
| 24 | import org.w3c.dom.DOMException; |
| 25 | import org.w3c.dom.Document; |
| 26 | import org.w3c.dom.Element; |
| 27 | import org.w3c.dom.NamedNodeMap; |
| 28 | import org.w3c.dom.Node; |
| 29 | import org.w3c.dom.NodeList; |
| 30 | |
| 31 | //???AWT |
| 32 | //import org.w3c.dom.TypeInfo; |
| 33 | //import org.w3c.dom.UserDataHandler; |
| 34 | |
| 35 | /** |
| 36 | * The Class IIOMetadataNode represents a node of the (DOM-style) metadata tree. |
| 37 | * |
| 38 | * @since Android 1.0 |
| 39 | */ |
| 40 | public class IIOMetadataNode implements Element, NodeList { |
| 41 | |
| 42 | /** |
| 43 | * The node name. |
| 44 | */ |
| 45 | private String nodeName; |
| 46 | |
| 47 | /** |
| 48 | * The node value. |
| 49 | */ |
| 50 | private String nodeValue; |
| 51 | |
| 52 | /** |
| 53 | * The attributes. |
| 54 | */ |
| 55 | private IIOMetadataNodeList attrs = new IIOMetadataNodeList(new ArrayList<IIOMetadataNode>()); |
| 56 | |
| 57 | /** |
| 58 | * The parent node. |
| 59 | */ |
| 60 | private IIOMetadataNode parent; |
| 61 | |
| 62 | /** |
| 63 | * The first child node. |
| 64 | */ |
| 65 | private IIOMetadataNode firstChild; |
| 66 | |
| 67 | /** |
| 68 | * The last child node. |
| 69 | */ |
| 70 | private IIOMetadataNode lastChild; |
| 71 | |
| 72 | /** |
| 73 | * The previous sibling. |
| 74 | */ |
| 75 | private IIOMetadataNode previousSibling; |
| 76 | |
| 77 | /** |
| 78 | * The next sibling. |
| 79 | */ |
| 80 | private IIOMetadataNode nextSibling; |
| 81 | |
| 82 | /** |
| 83 | * The number of children. |
| 84 | */ |
| 85 | private int nChildren; |
| 86 | |
| 87 | /** |
| 88 | * The user object associated with this node. |
| 89 | */ |
| 90 | private Object userObject; |
| 91 | |
| 92 | /** |
| 93 | * The text content of this node. |
| 94 | */ |
| 95 | private String textContent; |
| 96 | |
| 97 | /** |
| 98 | * Instantiates a new empty node. |
| 99 | */ |
| 100 | public IIOMetadataNode() { |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Instantiates a new empty node with the specified name. |
| 105 | * |
| 106 | * @param nodeName |
| 107 | * the node name. |
| 108 | */ |
| 109 | public IIOMetadataNode(String nodeName) { |
| 110 | this.nodeName = nodeName; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Instantiates a new IIOMetadataNode with the specified name and value. |
| 115 | * |
| 116 | * @param nodeName |
| 117 | * the node name. |
| 118 | * @param nodeValue |
| 119 | * the node value. |
| 120 | */ |
| 121 | private IIOMetadataNode(String nodeName, String nodeValue) { |
| 122 | this.nodeName = nodeName; |
| 123 | this.nodeValue = nodeValue; |
| 124 | } |
| 125 | |
| 126 | public String getTagName() { |
| 127 | return nodeName; |
| 128 | } |
| 129 | |
| 130 | public String getAttribute(String name) { |
| 131 | Attr attrNode = (Attr)attrs.getNamedItem(name); |
| 132 | return (attrNode == null) ? "" : attrNode.getValue(); |
| 133 | } |
| 134 | |
| 135 | public void setAttribute(String name, String value) throws DOMException { |
| 136 | Attr attr = (Attr)attrs.getNamedItem(name); |
| 137 | if (attr != null) { |
| 138 | attr.setValue(value); |
| 139 | } else { |
| 140 | attrs.list.add(new IIOMetadataAttr(name, value, this)); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | public void removeAttribute(String name) throws DOMException { |
| 145 | IIOMetadataAttr attr = (IIOMetadataAttr)attrs.getNamedItem(name); |
| 146 | if (attr != null) { |
| 147 | attr.setOwnerElement(null); |
| 148 | attrs.list.remove(attr); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | public Attr getAttributeNode(String name) { |
| 153 | return (Attr)attrs.getNamedItem(name); |
| 154 | } |
| 155 | |
| 156 | public Attr setAttributeNode(Attr newAttr) throws DOMException { |
| 157 | // Check if this attribute is already in use. |
| 158 | Element owner = newAttr.getOwnerElement(); |
| 159 | if (owner != null) { |
| 160 | if (owner == this) { // Replacing an attribute node by itself has no |
| 161 | // effect |
| 162 | return null; |
| 163 | } else { |
| 164 | throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, |
| 165 | "Attribute is already in use"); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | String name = newAttr.getName(); |
| 170 | Attr oldAttr = getAttributeNode(name); |
| 171 | if (oldAttr != null) { |
| 172 | removeAttributeNode(oldAttr); |
| 173 | } |
| 174 | |
| 175 | IIOMetadataAttr iioAttr; |
| 176 | if (newAttr instanceof IIOMetadataAttr) { |
| 177 | iioAttr = (IIOMetadataAttr)newAttr; |
| 178 | iioAttr.setOwnerElement(this); |
| 179 | } else { |
| 180 | iioAttr = new IIOMetadataAttr(name, newAttr.getValue(), this); |
| 181 | } |
| 182 | |
| 183 | attrs.list.add(iioAttr); |
| 184 | |
| 185 | return oldAttr; |
| 186 | } |
| 187 | |
| 188 | public Attr removeAttributeNode(Attr oldAttr) throws DOMException { |
| 189 | if (!attrs.list.remove(oldAttr)) { // Not found |
| 190 | throw new DOMException(DOMException.NOT_FOUND_ERR, "No such attribute!"); |
| 191 | } |
| 192 | |
| 193 | ((IIOMetadataAttr)oldAttr).setOwnerElement(null); |
| 194 | |
| 195 | return oldAttr; |
| 196 | } |
| 197 | |
| 198 | public NodeList getElementsByTagName(String name) { |
| 199 | ArrayList<IIOMetadataNode> nodes = new ArrayList<IIOMetadataNode>(); |
| 200 | |
| 201 | // Non-recursive tree walk |
| 202 | Node pos = this; |
| 203 | |
| 204 | while (pos != null) { |
| 205 | if (pos.getNodeName().equals(name)) { |
| 206 | nodes.add((IIOMetadataNode)pos); |
| 207 | } |
| 208 | |
| 209 | Node nextNode = pos.getFirstChild(); |
| 210 | |
| 211 | while (nextNode == null) { |
| 212 | if (pos == this) { |
| 213 | break; |
| 214 | } |
| 215 | |
| 216 | nextNode = pos.getNextSibling(); |
| 217 | |
| 218 | if (nextNode == null) { |
| 219 | pos = pos.getParentNode(); |
| 220 | |
| 221 | if (pos == null || pos == this) { |
| 222 | nextNode = null; |
| 223 | break; |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | pos = nextNode; |
| 228 | } |
| 229 | |
| 230 | return new IIOMetadataNodeList(nodes); |
| 231 | } |
| 232 | |
| 233 | public String getAttributeNS(String namespaceURI, String localName) throws DOMException { |
| 234 | return getAttribute(localName); |
| 235 | } |
| 236 | |
| 237 | public void setAttributeNS(String namespaceURI, String qualifiedName, String value) |
| 238 | throws DOMException { |
| 239 | setAttribute(qualifiedName, value); |
| 240 | } |
| 241 | |
| 242 | public void removeAttributeNS(String namespaceURI, String localName) throws DOMException { |
| 243 | removeAttribute(localName); |
| 244 | } |
| 245 | |
| 246 | public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException { |
| 247 | return getAttributeNode(localName); |
| 248 | } |
| 249 | |
| 250 | public Attr setAttributeNodeNS(Attr newAttr) throws DOMException { |
| 251 | return setAttributeNode(newAttr); |
| 252 | } |
| 253 | |
| 254 | public NodeList getElementsByTagNameNS(String namespaceURI, String localName) |
| 255 | throws DOMException { |
| 256 | return getElementsByTagName(localName); |
| 257 | } |
| 258 | |
| 259 | public boolean hasAttribute(String name) { |
| 260 | return attrs.getNamedItem(name) != null; |
| 261 | } |
| 262 | |
| 263 | public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException { |
| 264 | return hasAttribute(localName); |
| 265 | } |
| 266 | |
| 267 | // ???AWT |
| 268 | /* |
| 269 | * public TypeInfo getSchemaTypeInfo() { throw new |
| 270 | * DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } |
| 271 | */ |
| 272 | |
| 273 | /** |
| 274 | * <i>Description copied from interface: org.w3c.dom.Element (DOM Level |
| 275 | * 3)</i> |
| 276 | * <p> |
| 277 | * If the parameter isId is true, this method declares the specified |
| 278 | * attribute to be a user-determined ID attribute . This affects the value |
| 279 | * of Attr.isId and the behavior of Document.getElementById, but does not |
| 280 | * change any schema that may be in use, in particular this does not affect |
| 281 | * the Attr.schemaTypeInfo of the specified Attr node. Use the value false |
| 282 | * for the parameter isId to undeclare an attribute for being a |
| 283 | * user-determined ID attribute. To specify an attribute by local name and |
| 284 | * namespace URI, use the setIdAttributeNS method. |
| 285 | * </p> |
| 286 | * |
| 287 | * @param name |
| 288 | * the name of the attribute. |
| 289 | * @param isId |
| 290 | * the flag which determines whether this attribute is of type |
| 291 | * ID. |
| 292 | * @throws DOMException |
| 293 | * if a DOM error occurred while setting the attribute type. |
| 294 | * <p> |
| 295 | * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. |
| 296 | * <br> |
| 297 | * NOT_FOUND_ERR: Raised if the specified node is not an |
| 298 | * attribute of this element. |
| 299 | * </p> |
| 300 | */ |
| 301 | public void setIdAttribute(String name, boolean isId) throws DOMException { |
| 302 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * <i>Description copied from interface: org.w3c.dom.Element (DOM Level |
| 307 | * 3)</i> |
| 308 | * <p> |
| 309 | * If the parameter isId is true, this method declares the specified |
| 310 | * attribute to be a user-determined ID attribute . This affects the value |
| 311 | * of Attr.isId and the behavior of Document.getElementById, but does not |
| 312 | * change any schema that may be in use, in particular this does not affect |
| 313 | * the Attr.schemaTypeInfo of the specified Attr node. Use the value false |
| 314 | * for the parameter isId to undeclare an attribute for being a |
| 315 | * user-determined ID attribute. |
| 316 | * </p> |
| 317 | * |
| 318 | * @param namespaceURI |
| 319 | * the namespace URI of the attribute. |
| 320 | * @param localName |
| 321 | * the local name of the attribute. |
| 322 | * @param isId |
| 323 | * the flag which determines whether this attribute is of type |
| 324 | * ID. |
| 325 | * @throws DOMException |
| 326 | * if a DOM error occurred while setting the attribute type. |
| 327 | * <p> |
| 328 | * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. |
| 329 | * <br> |
| 330 | * NOT_FOUND_ERR: Raised if the specified node is not an |
| 331 | * attribute of this element. |
| 332 | * </p> |
| 333 | */ |
| 334 | public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) |
| 335 | throws DOMException { |
| 336 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * <i>Description copied from interface: org.w3c.dom.Element (DOM Level |
| 341 | * 3)</i> |
| 342 | * <p> |
| 343 | * If the parameter isId is true, this method declares the specified |
| 344 | * attribute to be a user-determined ID attribute . This affects the value |
| 345 | * of Attr.isId and the behavior of Document.getElementById, but does not |
| 346 | * change any schema that may be in use, in particular this does not affect |
| 347 | * the Attr.schemaTypeInfo of the specified Attr node. Use the value false |
| 348 | * for the parameter isId to undeclare an attribute for being a |
| 349 | * user-determined ID attribute. |
| 350 | * </p> |
| 351 | * |
| 352 | * @param idAttr |
| 353 | * the attribute node. |
| 354 | * @param isId |
| 355 | * the flag which determines whether this attribute is of type |
| 356 | * ID. |
| 357 | * @throws DOMException |
| 358 | * if a DOM error occurred while setting the attribute type. |
| 359 | * <p> |
| 360 | * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. |
| 361 | * <br> |
| 362 | * NOT_FOUND_ERR: Raised if the specified node is not an |
| 363 | * attribute of this element. |
| 364 | * </p> |
| 365 | */ |
| 366 | public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException { |
| 367 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 368 | } |
| 369 | |
| 370 | public String getNodeName() { |
| 371 | return nodeName; |
| 372 | } |
| 373 | |
| 374 | public String getNodeValue() throws DOMException { |
| 375 | return nodeValue; |
| 376 | } |
| 377 | |
| 378 | public void setNodeValue(String nodeValue) throws DOMException { |
| 379 | this.nodeValue = nodeValue; |
| 380 | } |
| 381 | |
| 382 | public short getNodeType() { |
| 383 | return ELEMENT_NODE; |
| 384 | } |
| 385 | |
| 386 | public Node getParentNode() { |
| 387 | return parent; |
| 388 | } |
| 389 | |
| 390 | public NodeList getChildNodes() { |
| 391 | return this; |
| 392 | } |
| 393 | |
| 394 | public Node getFirstChild() { |
| 395 | return firstChild; |
| 396 | } |
| 397 | |
| 398 | public Node getLastChild() { |
| 399 | return lastChild; |
| 400 | } |
| 401 | |
| 402 | public Node getPreviousSibling() { |
| 403 | return previousSibling; |
| 404 | } |
| 405 | |
| 406 | public Node getNextSibling() { |
| 407 | return nextSibling; |
| 408 | } |
| 409 | |
| 410 | public NamedNodeMap getAttributes() { |
| 411 | return attrs; |
| 412 | } |
| 413 | |
| 414 | public Document getOwnerDocument() { |
| 415 | return null; |
| 416 | } |
| 417 | |
| 418 | public Node insertBefore(Node newChild, Node refChild) throws DOMException { |
| 419 | if (newChild == null) { |
| 420 | throw new IllegalArgumentException("newChild == null!"); |
| 421 | } |
| 422 | |
| 423 | IIOMetadataNode newIIOChild = (IIOMetadataNode)newChild; |
| 424 | IIOMetadataNode refIIOChild = (IIOMetadataNode)refChild; |
| 425 | |
| 426 | newIIOChild.parent = this; |
| 427 | |
| 428 | if (refIIOChild == null) { |
| 429 | newIIOChild.nextSibling = null; |
| 430 | newIIOChild.previousSibling = lastChild; |
| 431 | |
| 432 | // Fix this node |
| 433 | lastChild = newIIOChild; |
| 434 | if (firstChild == null) { |
| 435 | firstChild = newIIOChild; |
| 436 | } |
| 437 | } else { |
| 438 | newIIOChild.nextSibling = refIIOChild; |
| 439 | newIIOChild.previousSibling = refIIOChild.previousSibling; |
| 440 | |
| 441 | // Fix this node |
| 442 | if (firstChild == refIIOChild) { |
| 443 | firstChild = newIIOChild; |
| 444 | } |
| 445 | |
| 446 | // Fix next node |
| 447 | if (refIIOChild != null) { |
| 448 | refIIOChild.previousSibling = newIIOChild; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | // Fix prev node |
| 453 | if (newIIOChild.previousSibling != null) { |
| 454 | newIIOChild.previousSibling.nextSibling = newIIOChild; |
| 455 | } |
| 456 | |
| 457 | nChildren++; |
| 458 | |
| 459 | return newIIOChild; |
| 460 | } |
| 461 | |
| 462 | public Node replaceChild(Node newChild, Node oldChild) throws DOMException { |
| 463 | if (newChild == null) { |
| 464 | throw new IllegalArgumentException("newChild == null!"); |
| 465 | } |
| 466 | |
| 467 | IIOMetadataNode newIIOChild = (IIOMetadataNode)newChild; |
| 468 | IIOMetadataNode oldIIOChild = (IIOMetadataNode)oldChild; |
| 469 | |
| 470 | IIOMetadataNode next = oldIIOChild.nextSibling; |
| 471 | IIOMetadataNode previous = oldIIOChild.previousSibling; |
| 472 | |
| 473 | // Fix new node |
| 474 | newIIOChild.parent = this; |
| 475 | newIIOChild.nextSibling = next; |
| 476 | newIIOChild.previousSibling = previous; |
| 477 | |
| 478 | // Fix this node |
| 479 | if (lastChild == oldIIOChild) { |
| 480 | lastChild = newIIOChild; |
| 481 | } |
| 482 | if (firstChild == oldIIOChild) { |
| 483 | firstChild = newIIOChild; |
| 484 | } |
| 485 | |
| 486 | // Fix siblings |
| 487 | if (next != null) { |
| 488 | next.previousSibling = newIIOChild; |
| 489 | } |
| 490 | if (previous != null) { |
| 491 | previous.nextSibling = newIIOChild; |
| 492 | } |
| 493 | |
| 494 | // Fix old child |
| 495 | oldIIOChild.parent = null; |
| 496 | oldIIOChild.nextSibling = next; |
| 497 | oldIIOChild.previousSibling = previous; |
| 498 | |
| 499 | return oldIIOChild; |
| 500 | } |
| 501 | |
| 502 | public Node removeChild(Node oldChild) throws DOMException { |
| 503 | if (oldChild == null) { |
| 504 | throw new IllegalArgumentException("oldChild == null!"); |
| 505 | } |
| 506 | |
| 507 | IIOMetadataNode oldIIOChild = (IIOMetadataNode)oldChild; |
| 508 | |
| 509 | // Fix next and previous |
| 510 | IIOMetadataNode previous = oldIIOChild.previousSibling; |
| 511 | IIOMetadataNode next = oldIIOChild.nextSibling; |
| 512 | |
| 513 | if (previous != null) { |
| 514 | previous.nextSibling = next; |
| 515 | } |
| 516 | if (next != null) { |
| 517 | next.previousSibling = previous; |
| 518 | } |
| 519 | |
| 520 | // Fix this node |
| 521 | if (lastChild == oldIIOChild) { |
| 522 | lastChild = previous; |
| 523 | } |
| 524 | if (firstChild == oldIIOChild) { |
| 525 | firstChild = next; |
| 526 | } |
| 527 | nChildren--; |
| 528 | |
| 529 | // Fix old child |
| 530 | oldIIOChild.parent = null; |
| 531 | oldIIOChild.previousSibling = null; |
| 532 | oldIIOChild.nextSibling = null; |
| 533 | |
| 534 | return oldIIOChild; |
| 535 | } |
| 536 | |
| 537 | public Node appendChild(Node newChild) throws DOMException { |
| 538 | return insertBefore(newChild, null); |
| 539 | } |
| 540 | |
| 541 | public boolean hasChildNodes() { |
| 542 | return nChildren != 0; |
| 543 | } |
| 544 | |
| 545 | public Node cloneNode(boolean deep) { |
| 546 | IIOMetadataNode cloned = new IIOMetadataNode(nodeName); |
| 547 | cloned.setUserObject(getUserObject()); |
| 548 | |
| 549 | if (deep) { // Clone recursively |
| 550 | IIOMetadataNode c = firstChild; |
| 551 | while (c != null) { |
| 552 | cloned.insertBefore(c.cloneNode(true), null); |
| 553 | c = c.nextSibling; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | return cloned; // To change body of implemented methods use File | |
| 558 | // Settings | File Templates. |
| 559 | } |
| 560 | |
| 561 | public void normalize() { |
| 562 | // Do nothing |
| 563 | } |
| 564 | |
| 565 | public boolean isSupported(String feature, String version) { |
| 566 | return false; |
| 567 | } |
| 568 | |
| 569 | public String getNamespaceURI() { |
| 570 | return null; |
| 571 | } |
| 572 | |
| 573 | public String getPrefix() { |
| 574 | return null; |
| 575 | } |
| 576 | |
| 577 | public void setPrefix(String prefix) throws DOMException { |
| 578 | // Do nothing |
| 579 | } |
| 580 | |
| 581 | public String getLocalName() { |
| 582 | return nodeName; |
| 583 | } |
| 584 | |
| 585 | public boolean hasAttributes() { |
| 586 | return attrs.list.size() > 0; |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 591 | * <p> |
| 592 | * The absolute base URI of this node or null if the implementation wasn't |
| 593 | * able to obtain an absolute URI. This value is computed as described in. |
| 594 | * However, when the Document supports the feature "HTML" [DOM Level 2 |
| 595 | * HTML], the base URI is computed using first the value of the href |
| 596 | * attribute of the HTML BASE element if any, and the value of the |
| 597 | * documentURI attribute from the Document interface otherwise. |
| 598 | * </p> |
| 599 | * |
| 600 | * @return the string representation of the absolute base URI. |
| 601 | */ |
| 602 | public String getBaseURI() { |
| 603 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 608 | * <p> |
| 609 | * Compares the reference node, i.e. the node on which this method is being |
| 610 | * called, with a node, i.e. the one passed as a parameter, with regard to |
| 611 | * their position in the document and according to the document order. |
| 612 | * </p> |
| 613 | * |
| 614 | * @param other |
| 615 | * the node to compare against the reference node. |
| 616 | * @return Returns how the node is positioned relatively to the reference |
| 617 | * node. |
| 618 | * @throws DOMException |
| 619 | * NOT_SUPPORTED_ERR: when the compared nodes are from different |
| 620 | * DOM implementations that do not coordinate to return |
| 621 | * consistent implementation-specific results. |
| 622 | */ |
| 623 | public short compareDocumentPosition(Node other) throws DOMException { |
| 624 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 629 | * <p> |
| 630 | * This attribute returns the text content of this node and its descendants. |
| 631 | * When it is defined to be null, setting it has no effect. On setting, any |
| 632 | * possible children this node may have are removed and, if it the new |
| 633 | * string is not empty or null, replaced by a single Text node containing |
| 634 | * the string this attribute is set to. On getting, no serialization is |
| 635 | * performed, the returned string does not contain any markup. No whitespace |
| 636 | * normalization is performed and the returned string does not contain the |
| 637 | * white spaces in element content (see the attribute |
| 638 | * Text.isElementContentWhitespace). Similarly, on setting, no parsing is |
| 639 | * performed either, the input string is taken as pure textual content. The |
| 640 | * string returned is made of the text content of this node depending on its |
| 641 | * type, as defined below: |
| 642 | * <table> |
| 643 | * <tr> |
| 644 | * <td><strong>Node type</strong></td> |
| 645 | * <td><strong>Content</strong></td> |
| 646 | * </tr> |
| 647 | * <tr> |
| 648 | * <td>ELEMENT_NODE, ATTRIBUTE_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, |
| 649 | * DOCUMENT_FRAGMENT_NODE</td> |
| 650 | * <td>concatenation of the textContent attribute value of every child node, |
| 651 | * excluding COMMENT_NODE and PROCESSING_INSTRUCTION_NODE nodes. This is the |
| 652 | * empty string if the node has no children.</td> |
| 653 | * </tr> |
| 654 | * <tr> |
| 655 | * <td>TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE, |
| 656 | * PROCESSING_INSTRUCTION_NODE</td> |
| 657 | * <td>nodeValue</td> |
| 658 | * </tr> |
| 659 | * <tr> |
| 660 | * <td>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td> |
| 661 | * <td>null</td> |
| 662 | * </tr> |
| 663 | * </table> |
| 664 | * </p> |
| 665 | * |
| 666 | * @return the text content depending on the type of this node. |
| 667 | * @throws DOMException |
| 668 | * DOMSTRING_SIZE_ERR: Raised when it would return more |
| 669 | * characters than fit in a DOMString variable on the |
| 670 | * implementation platform. |
| 671 | */ |
| 672 | public String getTextContent() throws DOMException { |
| 673 | return textContent; |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 678 | * <p> |
| 679 | * This attribute returns the text content of this node and its descendants. |
| 680 | * When it is defined to be null, setting it has no effect. On setting, any |
| 681 | * possible children this node may have are removed and, if it the new |
| 682 | * string is not empty or null, replaced by a single Text node containing |
| 683 | * the string this attribute is set to. On getting, no serialization is |
| 684 | * performed, the returned string does not contain any markup. No whitespace |
| 685 | * normalization is performed and the returned string does not contain the |
| 686 | * white spaces in element content (see the attribute |
| 687 | * Text.isElementContentWhitespace). Similarly, on setting, no parsing is |
| 688 | * performed either, the input string is taken as pure textual content. The |
| 689 | * string returned is made of the text content of this node depending on its |
| 690 | * type, as defined below: |
| 691 | * <table> |
| 692 | * <tr> |
| 693 | * <td><strong>Node type</strong></td> |
| 694 | * <td><strong>Content</strong></td> |
| 695 | * </tr> |
| 696 | * <tr> |
| 697 | * <td>ELEMENT_NODE, ATTRIBUTE_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, |
| 698 | * DOCUMENT_FRAGMENT_NODE</td> |
| 699 | * <td>concatenation of the textContent attribute value of every child node, |
| 700 | * excluding COMMENT_NODE and PROCESSING_INSTRUCTION_NODE nodes. This is the |
| 701 | * empty string if the node has no children.</td> |
| 702 | * </tr> |
| 703 | * <tr> |
| 704 | * <td>TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE, |
| 705 | * PROCESSING_INSTRUCTION_NODE</td> |
| 706 | * <td>nodeValue</td> |
| 707 | * </tr> |
| 708 | * <tr> |
| 709 | * <td>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td> |
| 710 | * <td>null</td> |
| 711 | * </tr> |
| 712 | * </table> |
| 713 | * </p> |
| 714 | * |
| 715 | * @param textContent |
| 716 | * the text content for this node. |
| 717 | * @throws DOMException |
| 718 | * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is |
| 719 | * readonly. |
| 720 | */ |
| 721 | public void setTextContent(String textContent) throws DOMException { |
| 722 | this.textContent = textContent; |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 727 | * <p> |
| 728 | * Returns whether this node is the same node as the given one. This method |
| 729 | * provides a way to determine whether two Node references returned by the |
| 730 | * implementation reference the same object. When two Node references are |
| 731 | * references to the same object, even if through a proxy, the references |
| 732 | * may be used completely interchangeably, such that all attributes have the |
| 733 | * same values and calling the same DOM method on either reference always |
| 734 | * has exactly the same effect. |
| 735 | * </p> |
| 736 | * |
| 737 | * @param other |
| 738 | * the node to test against. |
| 739 | * @return true, if the nodes are the same, false otherwise. |
| 740 | */ |
| 741 | public boolean isSameNode(Node other) { |
| 742 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 747 | * <p> |
| 748 | * Look up the prefix associated to the given namespace URI, starting from |
| 749 | * this node. The default namespace declarations are ignored by this method. |
| 750 | * See for details on the algorithm used by this method. |
| 751 | * </p> |
| 752 | * |
| 753 | * @param namespaceURI |
| 754 | * the namespace URI to look for. |
| 755 | * @return the associated namespace prefix if found or null if none is |
| 756 | * found. If more than one prefix are associated to the namespace |
| 757 | * prefix, the returned namespace prefix is implementation |
| 758 | * dependent. |
| 759 | */ |
| 760 | public String lookupPrefix(String namespaceURI) { |
| 761 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 766 | * <p> |
| 767 | * This method checks if the specified namespaceURI is the default namespace |
| 768 | * or not. |
| 769 | * </p> |
| 770 | * |
| 771 | * @param namespaceURI |
| 772 | * the namespace URI to look for. |
| 773 | * @return true, if the specified namespaceURI is the default namespace, |
| 774 | * false otherwise. |
| 775 | */ |
| 776 | public boolean isDefaultNamespace(String namespaceURI) { |
| 777 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 782 | * <p> |
| 783 | * Look up the namespace URI associated to the given prefix, starting from |
| 784 | * this node. See for details on the algorithm used by this method. |
| 785 | * </p> |
| 786 | * |
| 787 | * @param prefix |
| 788 | * the prefix to look for. If this parameter is null, the method |
| 789 | * will return the default namespace URI if any. |
| 790 | * @return the associated namespace URI or null if none is found. |
| 791 | */ |
| 792 | public String lookupNamespaceURI(String prefix) { |
| 793 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 794 | } |
| 795 | |
| 796 | /** |
| 797 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 798 | * <p> |
| 799 | * Tests whether two nodes are equal. This method tests for equality of |
| 800 | * nodes, not sameness (i.e., whether the two nodes are references to the |
| 801 | * same object) which can be tested with Node.isSameNode(). All nodes that |
| 802 | * are the same will also be equal, though the reverse may not be true. Two |
| 803 | * nodes are equal if and only if the following conditions are satisfied: |
| 804 | * <p> |
| 805 | * <li>The two nodes are of the same type.</li> |
| 806 | * <li>The following string attributes are equal: nodeName, localName, |
| 807 | * namespaceURI, prefix, nodeValue . This is: they are both null, or they |
| 808 | * have the same length and are character for character identical.</li> |
| 809 | * <li>The attributes NamedNodeMaps are equal. This is: they are both null, |
| 810 | * or they have the same length and for each node that exists in one map |
| 811 | * there is a node that exists in the other map and is equal, although not |
| 812 | * necessarily at the same index.</li> |
| 813 | * <li>The childNodes NodeLists are equal. This is: they are both null, or |
| 814 | * they have the same length and contain equal nodes at the same index. Note |
| 815 | * that normalization can affect equality; to avoid this, nodes should be |
| 816 | * normalized before being compared.</li> |
| 817 | * </p> |
| 818 | * For two DocumentType nodes to be equal, the following conditions must |
| 819 | * also be satisfied: |
| 820 | * <p> |
| 821 | * <li>The following string attributes are equal: publicId, systemId, |
| 822 | * internalSubset.</li> |
| 823 | * <li>The entities NamedNodeMaps are equal.</li> |
| 824 | * <li>The notations NamedNodeMaps are equal.</li> |
| 825 | * </p> |
| 826 | * On the other hand, the following do not affect equality: the |
| 827 | * ownerDocument, baseURI, and parentNode attributes, the specified |
| 828 | * attribute for Attr nodes, the schemaTypeInfo attribute for Attr and |
| 829 | * Element nodes, the Text.isElementContentWhitespace attribute for Text |
| 830 | * nodes, as well as any user data or event listeners registered on the |
| 831 | * nodes. </p> |
| 832 | * <p> |
| 833 | * Note: As a general rule, anything not mentioned in the description above |
| 834 | * is not significant in consideration of equality checking. Note that |
| 835 | * future versions of this specification may take into account more |
| 836 | * attributes and implementations conform to this specification are expected |
| 837 | * to be updated accordingly. |
| 838 | * </p> |
| 839 | * |
| 840 | * @param arg |
| 841 | * the node to compare equality with. |
| 842 | * @return true, if the nodes are equal, false otherwise. |
| 843 | */ |
| 844 | public boolean isEqualNode(Node arg) { |
| 845 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 850 | * <p> |
| 851 | * This method returns a specialized object which implements the specialized |
| 852 | * APIs of the specified feature and version, as specified in. The |
| 853 | * specialized object may also be obtained by using binding-specific casting |
| 854 | * methods but is not necessarily expected to, as discussed in. This method |
| 855 | * also allow the implementation to provide specialized objects which do not |
| 856 | * support the Node interface. |
| 857 | * </p> |
| 858 | * |
| 859 | * @param feature |
| 860 | * the name of the feature requested. Note that any plus sign "+" |
| 861 | * prepended to the name of the feature will be ignored since it |
| 862 | * is not significant in the context of this method. |
| 863 | * @param version |
| 864 | * this is the version number of the feature to test. |
| 865 | * @return the object which implements the specialized APIs of the specified |
| 866 | * feature and version, if any, or null if there is no object which |
| 867 | * implements interfaces associated with that feature. If the |
| 868 | * DOMObject returned by this method implements the Node interface, |
| 869 | * it must delegate to the primary core Node and not return results |
| 870 | * inconsistent with the primary core Node such as attributes, |
| 871 | * childNodes, etc. |
| 872 | */ |
| 873 | public Object getFeature(String feature, String version) { |
| 874 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 875 | } |
| 876 | |
| 877 | // ???AWT |
| 878 | /* |
| 879 | * public Object setUserData(String key, Object data, UserDataHandler |
| 880 | * handler) { throw new DOMException(DOMException.NOT_SUPPORTED_ERR, |
| 881 | * "Method not supported"); } |
| 882 | */ |
| 883 | |
| 884 | /** |
| 885 | * <i>Description copied from interface: org.w3c.dom.Node (DOM Level 3)</i> |
| 886 | * <p> |
| 887 | * Retrieves the object associated to a key on a this node. The object must |
| 888 | * first have been set to this node by calling setUserData with the same |
| 889 | * key. |
| 890 | * </p> |
| 891 | * |
| 892 | * @param key |
| 893 | * the key the object is associated to. |
| 894 | * @return the DOMUserData associated to the given key on this node, or null |
| 895 | * if there was none. |
| 896 | */ |
| 897 | public Object getUserData(String key) { |
| 898 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 899 | } |
| 900 | |
| 901 | public Node item(int index) { |
| 902 | if (index < 0 || index >= nChildren) { |
| 903 | return null; |
| 904 | } |
| 905 | |
| 906 | Node n; |
| 907 | for (n = getFirstChild(); index > 0; index--) { |
| 908 | n = n.getNextSibling(); |
| 909 | } |
| 910 | |
| 911 | return n; |
| 912 | } |
| 913 | |
| 914 | public int getLength() { |
| 915 | return nChildren; |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * Gets the user object associated with this node. |
| 920 | * |
| 921 | * @return the user object associated with this node. |
| 922 | */ |
| 923 | public Object getUserObject() { |
| 924 | return userObject; |
| 925 | } |
| 926 | |
| 927 | /** |
| 928 | * Sets the user object associated with this node. |
| 929 | * |
| 930 | * @param userObject |
| 931 | * the new user object associated with this node. |
| 932 | */ |
| 933 | public void setUserObject(Object userObject) { |
| 934 | this.userObject = userObject; |
| 935 | } |
| 936 | |
| 937 | /** |
| 938 | * The Class IIOMetadataAttr. |
| 939 | */ |
| 940 | private class IIOMetadataAttr extends IIOMetadataNode implements Attr { |
| 941 | |
| 942 | /** |
| 943 | * The owner element. |
| 944 | */ |
| 945 | private Element ownerElement; |
| 946 | |
| 947 | /** |
| 948 | * Instantiates a new iIO metadata attr. |
| 949 | * |
| 950 | * @param name |
| 951 | * the name. |
| 952 | * @param value |
| 953 | * the value. |
| 954 | * @param owner |
| 955 | * the owner. |
| 956 | */ |
| 957 | public IIOMetadataAttr(String name, String value, Element owner) { |
| 958 | super(name, value); |
| 959 | this.ownerElement = owner; |
| 960 | } |
| 961 | |
| 962 | public String getName() { |
| 963 | return getNodeName(); |
| 964 | } |
| 965 | |
| 966 | public boolean getSpecified() { |
| 967 | return true; |
| 968 | } |
| 969 | |
| 970 | public String getValue() { |
| 971 | return nodeValue; |
| 972 | } |
| 973 | |
| 974 | public void setValue(String value) throws DOMException { |
| 975 | nodeValue = value; |
| 976 | } |
| 977 | |
| 978 | public Element getOwnerElement() { |
| 979 | return ownerElement; |
| 980 | } |
| 981 | |
| 982 | /** |
| 983 | * Sets the owner element. |
| 984 | * |
| 985 | * @param ownerElement |
| 986 | * the new owner element. |
| 987 | */ |
| 988 | public void setOwnerElement(Element ownerElement) { |
| 989 | this.ownerElement = ownerElement; |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * @return |
| 994 | */ |
| 995 | public boolean isId() { |
| 996 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); |
| 997 | } |
| 998 | |
| 999 | @Override |
| 1000 | public short getNodeType() { |
| 1001 | return ATTRIBUTE_NODE; |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | /** |
| 1006 | * The Class IIOMetadataNodeList. |
| 1007 | */ |
| 1008 | private class IIOMetadataNodeList implements NodeList, NamedNodeMap { |
| 1009 | |
| 1010 | /** |
| 1011 | * The list. |
| 1012 | */ |
| 1013 | private List<IIOMetadataNode> list; |
| 1014 | |
| 1015 | /** |
| 1016 | * Instantiates a new iIO metadata node list. |
| 1017 | * |
| 1018 | * @param list |
| 1019 | * the list. |
| 1020 | */ |
| 1021 | IIOMetadataNodeList(List<IIOMetadataNode> list) { |
| 1022 | this.list = list; |
| 1023 | } |
| 1024 | |
| 1025 | public Node item(int index) { |
| 1026 | try { |
| 1027 | return list.get(index); |
| 1028 | } catch (IndexOutOfBoundsException e) { |
| 1029 | return null; |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | public int getLength() { |
| 1034 | return list.size(); |
| 1035 | } |
| 1036 | |
| 1037 | public Node getNamedItem(String name) { |
| 1038 | for (IIOMetadataNode node : list) { |
| 1039 | if (name.equals(node.getNodeName())) { |
| 1040 | return node; |
| 1041 | } |
| 1042 | } |
| 1043 | return null; |
| 1044 | } |
| 1045 | |
| 1046 | public Node setNamedItem(Node arg) throws DOMException { |
| 1047 | throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, |
| 1048 | "This NamedNodeMap is read-only!"); |
| 1049 | } |
| 1050 | |
| 1051 | public Node removeNamedItem(String name) throws DOMException { |
| 1052 | throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, |
| 1053 | "This NamedNodeMap is read-only!"); |
| 1054 | } |
| 1055 | |
| 1056 | public Node getNamedItemNS(String namespaceURI, String localName) throws DOMException { |
| 1057 | return getNamedItem(localName); |
| 1058 | } |
| 1059 | |
| 1060 | public Node setNamedItemNS(Node arg) throws DOMException { |
| 1061 | throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, |
| 1062 | "This NamedNodeMap is read-only!"); |
| 1063 | } |
| 1064 | |
| 1065 | public Node removeNamedItemNS(String namespaceURI, String localName) throws DOMException { |
| 1066 | throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, |
| 1067 | "This NamedNodeMap is read-only!"); |
| 1068 | } |
| 1069 | } |
| 1070 | } |