0N/A/*
2362N/A * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.imageio.metadata;
0N/A
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.Iterator;
0N/Aimport java.util.List;
0N/A
0N/Aimport org.w3c.dom.Attr;
0N/Aimport org.w3c.dom.Document;
0N/Aimport org.w3c.dom.Element;
0N/Aimport org.w3c.dom.DOMException;
0N/Aimport org.w3c.dom.NamedNodeMap;
0N/Aimport org.w3c.dom.Node;
0N/Aimport org.w3c.dom.NodeList;
0N/Aimport org.w3c.dom.TypeInfo;
0N/Aimport org.w3c.dom.UserDataHandler;
0N/A
0N/A
0N/Aclass IIODOMException extends DOMException {
0N/A
0N/A public IIODOMException(short code, String message) {
0N/A super(code, message);
0N/A }
0N/A}
0N/A
0N/Aclass IIONamedNodeMap implements NamedNodeMap {
0N/A
0N/A List nodes;
0N/A
0N/A public IIONamedNodeMap(List nodes) {
0N/A this.nodes = nodes;
0N/A }
0N/A
0N/A public int getLength() {
0N/A return nodes.size();
0N/A }
0N/A
0N/A public Node getNamedItem(String name) {
0N/A Iterator iter = nodes.iterator();
0N/A while (iter.hasNext()) {
0N/A Node node = (Node)iter.next();
0N/A if (name.equals(node.getNodeName())) {
0N/A return node;
0N/A }
0N/A }
0N/A
0N/A return null;
0N/A }
0N/A
0N/A public Node item(int index) {
0N/A Node node = (Node)nodes.get(index);
0N/A return node;
0N/A }
0N/A
0N/A public Node removeNamedItem(java.lang.String name) {
0N/A throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
0N/A "This NamedNodeMap is read-only!");
0N/A }
0N/A
0N/A public Node setNamedItem(Node arg) {
0N/A throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
0N/A "This NamedNodeMap is read-only!");
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>getNamedItem(localName)</code>.
0N/A */
0N/A public Node getNamedItemNS(String namespaceURI, String localName) {
0N/A return getNamedItem(localName);
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>setNamedItem(arg)</code>.
0N/A */
0N/A public Node setNamedItemNS(Node arg) {
0N/A return setNamedItem(arg);
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>removeNamedItem(localName)</code>.
0N/A */
0N/A public Node removeNamedItemNS(String namespaceURI, String localName) {
0N/A return removeNamedItem(localName);
0N/A }
0N/A}
0N/A
0N/Aclass IIONodeList implements NodeList {
0N/A
0N/A List nodes;
0N/A
0N/A public IIONodeList(List nodes) {
0N/A this.nodes = nodes;
0N/A }
0N/A
0N/A public int getLength() {
0N/A return nodes.size();
0N/A }
0N/A
0N/A public Node item(int index) {
0N/A if (index < 0 || index > nodes.size()) {
0N/A return null;
0N/A }
0N/A return (Node)nodes.get(index);
0N/A }
0N/A}
0N/A
0N/Aclass IIOAttr extends IIOMetadataNode implements Attr {
0N/A
0N/A Element owner;
0N/A String name;
0N/A String value;
0N/A
0N/A public IIOAttr(Element owner, String name, String value) {
0N/A this.owner = owner;
0N/A this.name = name;
0N/A this.value = value;
0N/A }
0N/A
0N/A public String getName() {
0N/A return name;
0N/A }
0N/A
0N/A public String getNodeName() {
0N/A return name;
0N/A }
0N/A
0N/A public short getNodeType() {
0N/A return ATTRIBUTE_NODE;
0N/A }
0N/A
0N/A public boolean getSpecified() {
0N/A return true;
0N/A }
0N/A
0N/A public String getValue() {
0N/A return value;
0N/A }
0N/A
0N/A public String getNodeValue() {
0N/A return value;
0N/A }
0N/A
0N/A public void setValue(String value) {
0N/A this.value = value;
0N/A }
0N/A
0N/A public void setNodeValue(String value) {
0N/A this.value = value;
0N/A }
0N/A
0N/A public Element getOwnerElement() {
0N/A return owner;
0N/A }
0N/A
0N/A public void setOwnerElement(Element owner) {
0N/A this.owner = owner;
0N/A }
0N/A
0N/A /** This method is new in the DOM L3 for Attr interface.
0N/A * Could throw DOMException here, but its probably OK
0N/A * to always return false. One reason for this, is we have no good
0N/A * way to document this exception, since this class, IIOAttr,
0N/A * is not a public class. The rest of the methods that throw
0N/A * DOMException are publically documented as such on IIOMetadataNode.
0N/A * @return false
0N/A */
0N/A public boolean isId() {
0N/A return false;
0N/A }
0N/A
0N/A
0N/A}
0N/A
0N/A/**
0N/A * A class representing a node in a meta-data tree, which implements
0N/A * the <a
0N/A * href="../../../../api/org/w3c/dom/Element.html">
0N/A * <code>org.w3c.dom.Element</code></a> interface and additionally allows
0N/A * for the storage of non-textual objects via the
0N/A * <code>getUserObject</code> and <code>setUserObject</code> methods.
0N/A *
0N/A * <p> This class is not intended to be used for general XML
0N/A * processing. In particular, <code>Element</code> nodes created
0N/A * within the Image I/O API are not compatible with those created by
0N/A * Sun's standard implementation of the <code>org.w3.dom</code> API.
0N/A * In particular, the implementation is tuned for simple uses and may
0N/A * not perform well for intensive processing.
0N/A *
0N/A * <p> Namespaces are ignored in this implementation. The terms "tag
0N/A * name" and "node name" are always considered to be synonymous.
0N/A *
0N/A * <em>Note:</em>
0N/A * The DOM Level 3 specification added a number of new methods to the
0N/A * {@code Node}, {@code Element} and {@code Attr} interfaces that are not
0N/A * of value to the {@code IIOMetadataNode} implementation or specification.
0N/A *
0N/A * Calling such methods on an {@code IIOMetadataNode}, or an {@code Attr}
0N/A * instance returned from an {@code IIOMetadataNode} will result in a
0N/A * {@code DOMException} being thrown.
0N/A *
0N/A * @see IIOMetadata#getAsTree
0N/A * @see IIOMetadata#setFromTree
0N/A * @see IIOMetadata#mergeTree
0N/A *
0N/A */
0N/Apublic class IIOMetadataNode implements Element, NodeList {
0N/A
0N/A /**
0N/A * The name of the node as a <code>String</code>.
0N/A */
0N/A private String nodeName = null;
0N/A
0N/A /**
0N/A * The value of the node as a <code>String</code>. The Image I/O
0N/A * API typically does not make use of the node value.
0N/A */
0N/A private String nodeValue = null;
0N/A
0N/A /**
0N/A * The <code>Object</code> value associated with this node.
0N/A */
0N/A private Object userObject = null;
0N/A
0N/A /**
0N/A * The parent node of this node, or <code>null</code> if this node
0N/A * forms the root of its own tree.
0N/A */
0N/A private IIOMetadataNode parent = null;
0N/A
0N/A /**
0N/A * The number of child nodes.
0N/A */
0N/A private int numChildren = 0;
0N/A
0N/A /**
0N/A * The first (leftmost) child node of this node, or
0N/A * <code>null</code> if this node is a leaf node.
0N/A */
0N/A private IIOMetadataNode firstChild = null;
0N/A
0N/A /**
0N/A * The last (rightmost) child node of this node, or
0N/A * <code>null</code> if this node is a leaf node.
0N/A */
0N/A private IIOMetadataNode lastChild = null;
0N/A
0N/A /**
0N/A * The next (right) sibling node of this node, or
0N/A * <code>null</code> if this node is its parent's last child node.
0N/A */
0N/A private IIOMetadataNode nextSibling = null;
0N/A
0N/A /**
0N/A * The previous (left) sibling node of this node, or
0N/A * <code>null</code> if this node is its parent's first child node.
0N/A */
0N/A private IIOMetadataNode previousSibling = null;
0N/A
0N/A /**
0N/A * A <code>List</code> of <code>IIOAttr</code> nodes representing
0N/A * attributes.
0N/A */
0N/A private List attributes = new ArrayList();
0N/A
0N/A /**
0N/A * Constructs an empty <code>IIOMetadataNode</code>.
0N/A */
0N/A public IIOMetadataNode() {}
0N/A
0N/A /**
0N/A * Constructs an <code>IIOMetadataNode</code> with a given node
0N/A * name.
0N/A *
0N/A * @param nodeName the name of the node, as a <code>String</code>.
0N/A */
0N/A public IIOMetadataNode(String nodeName) {
0N/A this.nodeName = nodeName;
0N/A }
0N/A
0N/A /**
0N/A * Check that the node is either <code>null</code> or an
0N/A * <code>IIOMetadataNode</code>.
0N/A */
0N/A private void checkNode(Node node) throws DOMException {
0N/A if (node == null) {
0N/A return;
0N/A }
0N/A if (!(node instanceof IIOMetadataNode)) {
0N/A throw new IIODOMException(DOMException.WRONG_DOCUMENT_ERR,
0N/A "Node not an IIOMetadataNode!");
0N/A }
0N/A }
0N/A
0N/A // Methods from Node
0N/A
0N/A /**
0N/A * Returns the node name associated with this node.
0N/A *
0N/A * @return the node name, as a <code>String</code>.
0N/A */
0N/A public String getNodeName() {
0N/A return nodeName;
0N/A }
0N/A
0N/A /**
0N/A * Returns the value associated with this node.
0N/A *
0N/A * @return the node value, as a <code>String</code>.
0N/A */
0N/A public String getNodeValue(){
0N/A return nodeValue;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>String</code> value associated with this node.
0N/A */
0N/A public void setNodeValue(String nodeValue) {
0N/A this.nodeValue = nodeValue;
0N/A }
0N/A
0N/A /**
0N/A * Returns the node type, which is always
0N/A * <code>ELEMENT_NODE</code>.
0N/A *
0N/A * @return the <code>short</code> value <code>ELEMENT_NODE</code>.
0N/A */
0N/A public short getNodeType() {
0N/A return ELEMENT_NODE;
0N/A }
0N/A
0N/A /**
0N/A * Returns the parent of this node. A <code>null</code> value
0N/A * indicates that the node is the root of its own tree. To add a
0N/A * node to an existing tree, use one of the
0N/A * <code>insertBefore</code>, <code>replaceChild</code>, or
0N/A * <code>appendChild</code> methods.
0N/A *
0N/A * @return the parent, as a <code>Node</code>.
0N/A *
0N/A * @see #insertBefore
0N/A * @see #replaceChild
0N/A * @see #appendChild
0N/A */
0N/A public Node getParentNode() {
0N/A return parent;
0N/A }
0N/A
0N/A /**
0N/A * Returns a <code>NodeList</code> that contains all children of this node.
0N/A * If there are no children, this is a <code>NodeList</code> containing
0N/A * no nodes.
0N/A *
0N/A * @return the children as a <code>NodeList</code>
0N/A */
0N/A public NodeList getChildNodes() {
0N/A return this;
0N/A }
0N/A
0N/A /**
0N/A * Returns the first child of this node, or <code>null</code> if
0N/A * the node has no children.
0N/A *
0N/A * @return the first child, as a <code>Node</code>, or
0N/A * <code>null</code>
0N/A */
0N/A public Node getFirstChild() {
0N/A return firstChild;
0N/A }
0N/A
0N/A /**
0N/A * Returns the last child of this node, or <code>null</code> if
0N/A * the node has no children.
0N/A *
0N/A * @return the last child, as a <code>Node</code>, or
0N/A * <code>null</code>.
0N/A */
0N/A public Node getLastChild() {
0N/A return lastChild;
0N/A }
0N/A
0N/A /**
0N/A * Returns the previous sibling of this node, or <code>null</code>
0N/A * if this node has no previous sibling.
0N/A *
0N/A * @return the previous sibling, as a <code>Node</code>, or
0N/A * <code>null</code>.
0N/A */
0N/A public Node getPreviousSibling() {
0N/A return previousSibling;
0N/A }
0N/A
0N/A /**
0N/A * Returns the next sibling of this node, or <code>null</code> if
0N/A * the node has no next sibling.
0N/A *
0N/A * @return the next sibling, as a <code>Node</code>, or
0N/A * <code>null</code>.
0N/A */
0N/A public Node getNextSibling() {
0N/A return nextSibling;
0N/A }
0N/A
0N/A /**
0N/A * Returns a <code>NamedNodeMap</code> containing the attributes of
0N/A * this node.
0N/A *
0N/A * @return a <code>NamedNodeMap</code> containing the attributes of
0N/A * this node.
0N/A */
0N/A public NamedNodeMap getAttributes() {
0N/A return new IIONamedNodeMap(attributes);
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>null</code>, since <code>IIOMetadataNode</code>s
0N/A * do not belong to any <code>Document</code>.
0N/A *
0N/A * @return <code>null</code>.
0N/A */
0N/A public Document getOwnerDocument() {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Inserts the node <code>newChild</code> before the existing
0N/A * child node <code>refChild</code>. If <code>refChild</code> is
0N/A * <code>null</code>, insert <code>newChild</code> at the end of
0N/A * the list of children.
0N/A *
0N/A * @param newChild the <code>Node</code> to insert.
0N/A * @param refChild the reference <code>Node</code>.
0N/A *
0N/A * @return the node being inserted.
0N/A *
0N/A * @exception IllegalArgumentException if <code>newChild</code> is
0N/A * <code>null</code>.
0N/A */
0N/A public Node insertBefore(Node newChild,
0N/A Node refChild) {
0N/A if (newChild == null) {
0N/A throw new IllegalArgumentException("newChild == null!");
0N/A }
0N/A
0N/A checkNode(newChild);
0N/A checkNode(refChild);
0N/A
0N/A IIOMetadataNode newChildNode = (IIOMetadataNode)newChild;
0N/A IIOMetadataNode refChildNode = (IIOMetadataNode)refChild;
0N/A
0N/A // Siblings, can be null.
0N/A IIOMetadataNode previous = null;
0N/A IIOMetadataNode next = null;
0N/A
0N/A if (refChild == null) {
0N/A previous = this.lastChild;
0N/A next = null;
0N/A this.lastChild = newChildNode;
0N/A } else {
0N/A previous = refChildNode.previousSibling;
0N/A next = refChildNode;
0N/A }
0N/A
0N/A if (previous != null) {
0N/A previous.nextSibling = newChildNode;
0N/A }
0N/A if (next != null) {
0N/A next.previousSibling = newChildNode;
0N/A }
0N/A
0N/A newChildNode.parent = this;
0N/A newChildNode.previousSibling = previous;
0N/A newChildNode.nextSibling = next;
0N/A
0N/A // N.B.: O.K. if refChild == null
0N/A if (this.firstChild == refChildNode) {
0N/A this.firstChild = newChildNode;
0N/A }
0N/A
0N/A ++numChildren;
0N/A return newChildNode;
0N/A }
0N/A
0N/A /**
0N/A * Replaces the child node <code>oldChild</code> with
0N/A * <code>newChild</code> in the list of children, and returns the
0N/A * <code>oldChild</code> node.
0N/A *
0N/A * @param newChild the <code>Node</code> to insert.
0N/A * @param oldChild the <code>Node</code> to be replaced.
0N/A *
0N/A * @return the node replaced.
0N/A *
0N/A * @exception IllegalArgumentException if <code>newChild</code> is
0N/A * <code>null</code>.
0N/A */
0N/A public Node replaceChild(Node newChild,
0N/A Node oldChild) {
0N/A if (newChild == null) {
0N/A throw new IllegalArgumentException("newChild == null!");
0N/A }
0N/A
0N/A checkNode(newChild);
0N/A checkNode(oldChild);
0N/A
0N/A IIOMetadataNode newChildNode = (IIOMetadataNode)newChild;
0N/A IIOMetadataNode oldChildNode = (IIOMetadataNode)oldChild;
0N/A
0N/A IIOMetadataNode previous = oldChildNode.previousSibling;
0N/A IIOMetadataNode next = oldChildNode.nextSibling;
0N/A
0N/A if (previous != null) {
0N/A previous.nextSibling = newChildNode;
0N/A }
0N/A if (next != null) {
0N/A next.previousSibling = newChildNode;
0N/A }
0N/A
0N/A newChildNode.parent = this;
0N/A newChildNode.previousSibling = previous;
0N/A newChildNode.nextSibling = next;
0N/A
0N/A if (firstChild == oldChildNode) {
0N/A firstChild = newChildNode;
0N/A }
0N/A if (lastChild == oldChildNode) {
0N/A lastChild = newChildNode;
0N/A }
0N/A
0N/A oldChildNode.parent = null;
0N/A oldChildNode.previousSibling = null;
0N/A oldChildNode.nextSibling = null;
0N/A
0N/A return oldChildNode;
0N/A }
0N/A
0N/A /**
0N/A * Removes the child node indicated by <code>oldChild</code> from
0N/A * the list of children, and returns it.
0N/A *
0N/A * @param oldChild the <code>Node</code> to be removed.
0N/A *
0N/A * @return the node removed.
0N/A *
0N/A * @exception IllegalArgumentException if <code>oldChild</code> is
0N/A * <code>null</code>.
0N/A */
0N/A public Node removeChild(Node oldChild) {
0N/A if (oldChild == null) {
0N/A throw new IllegalArgumentException("oldChild == null!");
0N/A }
0N/A checkNode(oldChild);
0N/A
0N/A IIOMetadataNode oldChildNode = (IIOMetadataNode)oldChild;
0N/A
0N/A IIOMetadataNode previous = oldChildNode.previousSibling;
0N/A IIOMetadataNode next = oldChildNode.nextSibling;
0N/A
0N/A if (previous != null) {
0N/A previous.nextSibling = next;
0N/A }
0N/A if (next != null) {
0N/A next.previousSibling = previous;
0N/A }
0N/A
0N/A if (this.firstChild == oldChildNode) {
0N/A this.firstChild = next;
0N/A }
0N/A if (this.lastChild == oldChildNode) {
0N/A this.lastChild = previous;
0N/A }
0N/A
0N/A oldChildNode.parent = null;
0N/A oldChildNode.previousSibling = null;
0N/A oldChildNode.nextSibling = null;
0N/A
0N/A --numChildren;
0N/A return oldChildNode;
0N/A }
0N/A
0N/A /**
0N/A * Adds the node <code>newChild</code> to the end of the list of
0N/A * children of this node.
0N/A *
0N/A * @param newChild the <code>Node</code> to insert.
0N/A *
0N/A * @return the node added.
0N/A *
0N/A * @exception IllegalArgumentException if <code>newChild</code> is
0N/A * <code>null</code>.
0N/A */
0N/A public Node appendChild(Node newChild) {
0N/A if (newChild == null) {
0N/A throw new IllegalArgumentException("newChild == null!");
0N/A }
0N/A checkNode(newChild);
0N/A
0N/A // insertBefore will increment numChildren
0N/A return insertBefore(newChild, null);
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if this node has child nodes.
0N/A *
0N/A * @return <code>true</code> if this node has children.
0N/A */
0N/A public boolean hasChildNodes() {
0N/A return numChildren > 0;
0N/A }
0N/A
0N/A /**
0N/A * Returns a duplicate of this node. The duplicate node has no
0N/A * parent (<code>getParentNode</code> returns <code>null</code>).
0N/A * If a shallow clone is being performed (<code>deep</code> is
0N/A * <code>false</code>), the new node will not have any children or
0N/A * siblings. If a deep clone is being performed, the new node
0N/A * will form the root of a complete cloned subtree.
0N/A *
0N/A * @param deep if <code>true</code>, recursively clone the subtree
0N/A * under the specified node; if <code>false</code>, clone only the
0N/A * node itself.
0N/A *
0N/A * @return the duplicate node.
0N/A */
0N/A public Node cloneNode(boolean deep) {
0N/A IIOMetadataNode newNode = new IIOMetadataNode(this.nodeName);
0N/A newNode.setUserObject(getUserObject());
0N/A // Attributes
0N/A
0N/A if (deep) {
0N/A for (IIOMetadataNode child = firstChild;
0N/A child != null;
0N/A child = child.nextSibling) {
0N/A newNode.appendChild(child.cloneNode(true));
0N/A }
0N/A }
0N/A
0N/A return newNode;
0N/A }
0N/A
0N/A /**
0N/A * Does nothing, since <code>IIOMetadataNode</code>s do not
0N/A * contain <code>Text</code> children.
0N/A */
0N/A public void normalize() {
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>false</code> since DOM features are not
0N/A * supported.
0N/A *
0N/A * @return <code>false</code>.
0N/A *
0N/A * @param feature a <code>String</code>, which is ignored.
0N/A * @param version a <code>String</code>, which is ignored.
0N/A */
0N/A public boolean isSupported(String feature, String version) {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>null</code>, since namespaces are not supported.
0N/A */
0N/A public String getNamespaceURI() throws DOMException {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>null</code>, since namespaces are not supported.
0N/A *
0N/A * @return <code>null</code>.
0N/A *
0N/A * @see #setPrefix
0N/A */
0N/A public String getPrefix() {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Does nothing, since namespaces are not supported.
0N/A *
0N/A * @param prefix a <code>String</code>, which is ignored.
0N/A *
0N/A * @see #getPrefix
0N/A */
0N/A public void setPrefix(String prefix) {
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>getNodeName</code>.
0N/A *
0N/A * @return the node name, as a <code>String</code>.
0N/A */
0N/A public String getLocalName() {
0N/A return nodeName;
0N/A }
0N/A
0N/A // Methods from Element
0N/A
0N/A
0N/A /**
0N/A * Equivalent to <code>getNodeName</code>.
0N/A *
3817N/A * @return the node name, as a <code>String</code>
0N/A */
0N/A public String getTagName() {
0N/A return nodeName;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves an attribute value by name.
0N/A * @param name The name of the attribute to retrieve.
0N/A * @return The <code>Attr</code> value as a string, or the empty string
0N/A * if that attribute does not have a specified or default value.
0N/A */
0N/A public String getAttribute(String name) {
0N/A Attr attr = getAttributeNode(name);
0N/A if (attr == null) {
0N/A return "";
0N/A }
0N/A return attr.getValue();
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>getAttribute(localName)</code>.
0N/A *
0N/A * @see #setAttributeNS
0N/A */
0N/A public String getAttributeNS(String namespaceURI, String localName) {
0N/A return getAttribute(localName);
0N/A }
0N/A
0N/A public void setAttribute(String name, String value) {
0N/A // Name must be valid unicode chars
0N/A boolean valid = true;
0N/A char[] chs = name.toCharArray();
0N/A for (int i=0;i<chs.length;i++) {
0N/A if (chs[i] >= 0xfffe) {
0N/A valid = false;
0N/A break;
0N/A }
0N/A }
0N/A if (!valid) {
0N/A throw new IIODOMException(DOMException.INVALID_CHARACTER_ERR,
0N/A "Attribute name is illegal!");
0N/A }
0N/A removeAttribute(name, false);
0N/A attributes.add(new IIOAttr(this, name, value));
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>setAttribute(qualifiedName, value)</code>.
0N/A *
0N/A * @see #getAttributeNS
0N/A */
0N/A public void setAttributeNS(String namespaceURI,
0N/A String qualifiedName, String value) {
0N/A setAttribute(qualifiedName, value);
0N/A }
0N/A
0N/A public void removeAttribute(String name) {
0N/A removeAttribute(name, true);
0N/A }
0N/A
0N/A private void removeAttribute(String name, boolean checkPresent) {
0N/A int numAttributes = attributes.size();
0N/A for (int i = 0; i < numAttributes; i++) {
0N/A IIOAttr attr = (IIOAttr)attributes.get(i);
0N/A if (name.equals(attr.getName())) {
0N/A attr.setOwnerElement(null);
0N/A attributes.remove(i);
0N/A return;
0N/A }
0N/A }
0N/A
0N/A // If we get here, the attribute doesn't exist
0N/A if (checkPresent) {
0N/A throw new IIODOMException(DOMException.NOT_FOUND_ERR,
0N/A "No such attribute!");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>removeAttribute(localName)</code>.
0N/A */
0N/A public void removeAttributeNS(String namespaceURI,
0N/A String localName) {
0N/A removeAttribute(localName);
0N/A }
0N/A
0N/A public Attr getAttributeNode(String name) {
0N/A Node node = getAttributes().getNamedItem(name);
0N/A return (Attr)node;
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>getAttributeNode(localName)</code>.
0N/A *
0N/A * @see #setAttributeNodeNS
0N/A */
0N/A public Attr getAttributeNodeNS(String namespaceURI,
0N/A String localName) {
0N/A return getAttributeNode(localName);
0N/A }
0N/A
0N/A public Attr setAttributeNode(Attr newAttr) throws DOMException {
0N/A Element owner = newAttr.getOwnerElement();
0N/A if (owner != null) {
0N/A if (owner == this) {
0N/A return null;
0N/A } else {
0N/A throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
0N/A "Attribute is already in use");
0N/A }
0N/A }
0N/A
0N/A IIOAttr attr;
0N/A if (newAttr instanceof IIOAttr) {
0N/A attr = (IIOAttr)newAttr;
0N/A attr.setOwnerElement(this);
0N/A } else {
0N/A attr = new IIOAttr(this,
0N/A newAttr.getName(),
0N/A newAttr.getValue());
0N/A }
0N/A
0N/A Attr oldAttr = getAttributeNode(attr.getName());
0N/A if (oldAttr != null) {
0N/A removeAttributeNode(oldAttr);
0N/A }
0N/A
0N/A attributes.add(attr);
0N/A
0N/A return oldAttr;
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>setAttributeNode(newAttr)</code>.
0N/A *
0N/A * @see #getAttributeNodeNS
0N/A */
0N/A public Attr setAttributeNodeNS(Attr newAttr) {
0N/A return setAttributeNode(newAttr);
0N/A }
0N/A
0N/A public Attr removeAttributeNode(Attr oldAttr) {
0N/A removeAttribute(oldAttr.getName());
0N/A return oldAttr;
0N/A }
0N/A
0N/A public NodeList getElementsByTagName(String name) {
0N/A List l = new ArrayList();
0N/A getElementsByTagName(name, l);
0N/A return new IIONodeList(l);
0N/A }
0N/A
0N/A private void getElementsByTagName(String name, List l) {
0N/A if (nodeName.equals(name)) {
0N/A l.add(this);
0N/A }
0N/A
0N/A Node child = getFirstChild();
0N/A while (child != null) {
0N/A ((IIOMetadataNode)child).getElementsByTagName(name, l);
0N/A child = child.getNextSibling();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>getElementsByTagName(localName)</code>.
0N/A */
0N/A public NodeList getElementsByTagNameNS(String namespaceURI,
0N/A String localName) {
0N/A return getElementsByTagName(localName);
0N/A }
0N/A
0N/A public boolean hasAttributes() {
0N/A return attributes.size() > 0;
0N/A }
0N/A
0N/A public boolean hasAttribute(String name) {
0N/A return getAttributeNode(name) != null;
0N/A }
0N/A
0N/A /**
0N/A * Equivalent to <code>hasAttribute(localName)</code>.
0N/A */
0N/A public boolean hasAttributeNS(String namespaceURI,
0N/A String localName) {
0N/A return hasAttribute(localName);
0N/A }
0N/A
0N/A // Methods from NodeList
0N/A
0N/A public int getLength() {
0N/A return numChildren;
0N/A }
0N/A
0N/A public Node item(int index) {
0N/A if (index < 0) {
0N/A return null;
0N/A }
0N/A
0N/A Node child = getFirstChild();
0N/A while (child != null && index-- > 0) {
0N/A child = child.getNextSibling();
0N/A }
0N/A return child;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>Object</code> value associated with this node.
0N/A *
0N/A * @return the user <code>Object</code>.
0N/A *
0N/A * @see #setUserObject
0N/A */
0N/A public Object getUserObject() {
0N/A return userObject;
0N/A }
0N/A
0N/A /**
0N/A * Sets the value associated with this node.
0N/A *
0N/A * @param userObject the user <code>Object</code>.
0N/A *
0N/A * @see #getUserObject
0N/A */
0N/A public void setUserObject(Object userObject) {
0N/A this.userObject = userObject;
0N/A }
0N/A
0N/A // Start of dummy methods for DOM L3.
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public void setIdAttribute(String name,
0N/A boolean isId)
0N/A throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public void setIdAttributeNS(String namespaceURI,
0N/A String localName,
0N/A boolean isId)
0N/A throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public void setIdAttributeNode(Attr idAttr,
0N/A boolean isId)
0N/A throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public TypeInfo getSchemaTypeInfo() throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public Object setUserData(String key,
0N/A Object data,
0N/A UserDataHandler handler) throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public Object getUserData(String key) throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public Object getFeature(String feature, String version)
0N/A throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public boolean isSameNode(Node node) throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public boolean isEqualNode(Node node) throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public String lookupNamespaceURI(String prefix) throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public boolean isDefaultNamespace(String namespaceURI)
0N/A throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public String lookupPrefix(String namespaceURI) throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public String getTextContent() throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public void setTextContent(String textContent) throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public short compareDocumentPosition(Node other)
0N/A throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A
0N/A /**
0N/A * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
0N/A * and will throw a {@code DOMException}.
0N/A * @throws DOMException - always.
0N/A */
0N/A public String getBaseURI() throws DOMException {
0N/A throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
0N/A "Method not supported");
0N/A }
0N/A //End of dummy methods for DOM L3.
0N/A
0N/A
0N/A}