Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/javax/imageio/metadata/IIOMetadataNode.java
41153 views
1
/*
2
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package javax.imageio.metadata;
27
28
import java.io.Serial;
29
import java.util.ArrayList;
30
import java.util.List;
31
32
import org.w3c.dom.Attr;
33
import org.w3c.dom.DOMException;
34
import org.w3c.dom.Document;
35
import org.w3c.dom.Element;
36
import org.w3c.dom.NamedNodeMap;
37
import org.w3c.dom.Node;
38
import org.w3c.dom.NodeList;
39
import org.w3c.dom.TypeInfo;
40
import org.w3c.dom.UserDataHandler;
41
42
/**
43
* An {@code IIODOMException} is thrown by the {@code IIOMetadataNode} in
44
* "exceptional" circumstances.
45
*/
46
class IIODOMException extends DOMException {
47
48
/**
49
* Use serialVersionUID from JDK 9 for interoperability.
50
*/
51
@Serial
52
private static final long serialVersionUID = -4369510142067447468L;
53
54
public IIODOMException(short code, String message) {
55
super(code, message);
56
}
57
}
58
59
class IIONamedNodeMap implements NamedNodeMap {
60
61
List<? extends Node> nodes;
62
63
public IIONamedNodeMap(List<? extends Node> nodes) {
64
this.nodes = nodes;
65
}
66
67
public int getLength() {
68
return nodes.size();
69
}
70
71
public Node getNamedItem(String name) {
72
for (Node node : nodes) {
73
if (name.equals(node.getNodeName())) {
74
return node;
75
}
76
}
77
78
return null;
79
}
80
81
public Node item(int index) {
82
Node node = nodes.get(index);
83
return node;
84
}
85
86
public Node removeNamedItem(java.lang.String name) {
87
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
88
"This NamedNodeMap is read-only!");
89
}
90
91
public Node setNamedItem(Node arg) {
92
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
93
"This NamedNodeMap is read-only!");
94
}
95
96
/**
97
* Equivalent to {@code getNamedItem(localName)}.
98
*/
99
public Node getNamedItemNS(String namespaceURI, String localName) {
100
return getNamedItem(localName);
101
}
102
103
/**
104
* Equivalent to {@code setNamedItem(arg)}.
105
*/
106
public Node setNamedItemNS(Node arg) {
107
return setNamedItem(arg);
108
}
109
110
/**
111
* Equivalent to {@code removeNamedItem(localName)}.
112
*/
113
public Node removeNamedItemNS(String namespaceURI, String localName) {
114
return removeNamedItem(localName);
115
}
116
}
117
118
class IIONodeList implements NodeList {
119
120
List<? extends Node> nodes;
121
122
public IIONodeList(List<? extends Node> nodes) {
123
this.nodes = nodes;
124
}
125
126
public int getLength() {
127
return nodes.size();
128
}
129
130
public Node item(int index) {
131
if (index < 0 || index >= nodes.size()) {
132
return null;
133
}
134
return nodes.get(index);
135
}
136
}
137
138
class IIOAttr extends IIOMetadataNode implements Attr {
139
140
Element owner;
141
String name;
142
String value;
143
144
public IIOAttr(Element owner, String name, String value) {
145
this.owner = owner;
146
this.name = name;
147
this.value = value;
148
}
149
150
public String getName() {
151
return name;
152
}
153
154
public String getNodeName() {
155
return name;
156
}
157
158
public short getNodeType() {
159
return ATTRIBUTE_NODE;
160
}
161
162
public boolean getSpecified() {
163
return true;
164
}
165
166
public String getValue() {
167
return value;
168
}
169
170
public String getNodeValue() {
171
return value;
172
}
173
174
public void setValue(String value) {
175
this.value = value;
176
}
177
178
public void setNodeValue(String value) {
179
this.value = value;
180
}
181
182
public Element getOwnerElement() {
183
return owner;
184
}
185
186
public void setOwnerElement(Element owner) {
187
this.owner = owner;
188
}
189
190
/** This method is new in the DOM L3 for Attr interface.
191
* Could throw DOMException here, but its probably OK
192
* to always return false. One reason for this, is we have no good
193
* way to document this exception, since this class, IIOAttr,
194
* is not a public class. The rest of the methods that throw
195
* DOMException are publically documented as such on IIOMetadataNode.
196
* @return false
197
*/
198
public boolean isId() {
199
return false;
200
}
201
202
203
}
204
205
/**
206
* A class representing a node in a meta-data tree, which implements
207
* the {@link Element org.w3c.dom.Element} interface and additionally allows
208
* for the storage of non-textual objects via the
209
* {@code getUserObject} and {@code setUserObject} methods.
210
*
211
* <p> This class is not intended to be used for general XML
212
* processing. In particular, {@code Element} nodes created
213
* within the Image I/O API are not compatible with those created by
214
* Sun's standard implementation of the {@code org.w3.dom} API.
215
* In particular, the implementation is tuned for simple uses and may
216
* not perform well for intensive processing.
217
*
218
* <p> Namespaces are ignored in this implementation. The terms "tag
219
* name" and "node name" are always considered to be synonymous.
220
*
221
* <em>Note:</em>
222
* The DOM Level 3 specification added a number of new methods to the
223
* {@code Node}, {@code Element} and {@code Attr} interfaces that are not
224
* of value to the {@code IIOMetadataNode} implementation or specification.
225
*
226
* Calling such methods on an {@code IIOMetadataNode}, or an {@code Attr}
227
* instance returned from an {@code IIOMetadataNode} will result in a
228
* {@code DOMException} being thrown.
229
*
230
* @see IIOMetadata#getAsTree
231
* @see IIOMetadata#setFromTree
232
* @see IIOMetadata#mergeTree
233
*
234
*/
235
public class IIOMetadataNode implements Element, NodeList {
236
237
/**
238
* The name of the node as a {@code String}.
239
*/
240
private String nodeName = null;
241
242
/**
243
* The value of the node as a {@code String}. The Image I/O
244
* API typically does not make use of the node value.
245
*/
246
private String nodeValue = null;
247
248
/**
249
* The {@code Object} value associated with this node.
250
*/
251
private Object userObject = null;
252
253
/**
254
* The parent node of this node, or {@code null} if this node
255
* forms the root of its own tree.
256
*/
257
private IIOMetadataNode parent = null;
258
259
/**
260
* The number of child nodes.
261
*/
262
private int numChildren = 0;
263
264
/**
265
* The first (leftmost) child node of this node, or
266
* {@code null} if this node is a leaf node.
267
*/
268
private IIOMetadataNode firstChild = null;
269
270
/**
271
* The last (rightmost) child node of this node, or
272
* {@code null} if this node is a leaf node.
273
*/
274
private IIOMetadataNode lastChild = null;
275
276
/**
277
* The next (right) sibling node of this node, or
278
* {@code null} if this node is its parent's last child node.
279
*/
280
private IIOMetadataNode nextSibling = null;
281
282
/**
283
* The previous (left) sibling node of this node, or
284
* {@code null} if this node is its parent's first child node.
285
*/
286
private IIOMetadataNode previousSibling = null;
287
288
/**
289
* A {@code List} of {@code IIOAttr} nodes representing
290
* attributes.
291
*/
292
private List<IIOAttr> attributes = new ArrayList<>();
293
294
/**
295
* Constructs an empty {@code IIOMetadataNode}.
296
*/
297
public IIOMetadataNode() {}
298
299
/**
300
* Constructs an {@code IIOMetadataNode} with a given node
301
* name.
302
*
303
* @param nodeName the name of the node, as a {@code String}.
304
*/
305
public IIOMetadataNode(String nodeName) {
306
this.nodeName = nodeName;
307
}
308
309
/**
310
* Check that the node is either {@code null} or an
311
* {@code IIOMetadataNode}.
312
*
313
* @throws DOMException if {@code node} is not {@code null} and not an
314
* instance of {@code IIOMetadataNode}
315
*/
316
private void checkNode(Node node) throws DOMException {
317
if (node == null) {
318
return;
319
}
320
if (!(node instanceof IIOMetadataNode)) {
321
throw new IIODOMException(DOMException.WRONG_DOCUMENT_ERR,
322
"Node not an IIOMetadataNode!");
323
}
324
}
325
326
// Methods from Node
327
328
/**
329
* Returns the node name associated with this node.
330
*
331
* @return the node name, as a {@code String}.
332
*/
333
public String getNodeName() {
334
return nodeName;
335
}
336
337
/**
338
* Returns the value associated with this node.
339
*
340
* @return the node value, as a {@code String}.
341
*/
342
public String getNodeValue(){
343
return nodeValue;
344
}
345
346
/**
347
* Sets the {@code String} value associated with this node.
348
*/
349
public void setNodeValue(String nodeValue) {
350
this.nodeValue = nodeValue;
351
}
352
353
/**
354
* Returns the node type, which is always
355
* {@code ELEMENT_NODE}.
356
*
357
* @return the {@code short} value {@code ELEMENT_NODE}.
358
*/
359
public short getNodeType() {
360
return ELEMENT_NODE;
361
}
362
363
/**
364
* Returns the parent of this node. A {@code null} value
365
* indicates that the node is the root of its own tree. To add a
366
* node to an existing tree, use one of the
367
* {@code insertBefore}, {@code replaceChild}, or
368
* {@code appendChild} methods.
369
*
370
* @return the parent, as a {@code Node}.
371
*
372
* @see #insertBefore
373
* @see #replaceChild
374
* @see #appendChild
375
*/
376
public Node getParentNode() {
377
return parent;
378
}
379
380
/**
381
* Returns a {@code NodeList} that contains all children of this node.
382
* If there are no children, this is a {@code NodeList} containing
383
* no nodes.
384
*
385
* @return the children as a {@code NodeList}
386
*/
387
public NodeList getChildNodes() {
388
return this;
389
}
390
391
/**
392
* Returns the first child of this node, or {@code null} if
393
* the node has no children.
394
*
395
* @return the first child, as a {@code Node}, or
396
* {@code null}
397
*/
398
public Node getFirstChild() {
399
return firstChild;
400
}
401
402
/**
403
* Returns the last child of this node, or {@code null} if
404
* the node has no children.
405
*
406
* @return the last child, as a {@code Node}, or
407
* {@code null}.
408
*/
409
public Node getLastChild() {
410
return lastChild;
411
}
412
413
/**
414
* Returns the previous sibling of this node, or {@code null}
415
* if this node has no previous sibling.
416
*
417
* @return the previous sibling, as a {@code Node}, or
418
* {@code null}.
419
*/
420
public Node getPreviousSibling() {
421
return previousSibling;
422
}
423
424
/**
425
* Returns the next sibling of this node, or {@code null} if
426
* the node has no next sibling.
427
*
428
* @return the next sibling, as a {@code Node}, or
429
* {@code null}.
430
*/
431
public Node getNextSibling() {
432
return nextSibling;
433
}
434
435
/**
436
* Returns a {@code NamedNodeMap} containing the attributes of
437
* this node.
438
*
439
* @return a {@code NamedNodeMap} containing the attributes of
440
* this node.
441
*/
442
public NamedNodeMap getAttributes() {
443
return new IIONamedNodeMap(attributes);
444
}
445
446
/**
447
* Returns {@code null}, since {@code IIOMetadataNode}s
448
* do not belong to any {@code Document}.
449
*
450
* @return {@code null}.
451
*/
452
public Document getOwnerDocument() {
453
return null;
454
}
455
456
/**
457
* Inserts the node {@code newChild} before the existing
458
* child node {@code refChild}. If {@code refChild} is
459
* {@code null}, insert {@code newChild} at the end of
460
* the list of children.
461
*
462
* @param newChild the {@code Node} to insert.
463
* @param refChild the reference {@code Node}.
464
*
465
* @return the node being inserted.
466
*
467
* @exception IllegalArgumentException if {@code newChild} is
468
* {@code null}.
469
*/
470
public Node insertBefore(Node newChild,
471
Node refChild) {
472
if (newChild == null) {
473
throw new IllegalArgumentException("newChild == null!");
474
}
475
476
checkNode(newChild);
477
checkNode(refChild);
478
479
IIOMetadataNode newChildNode = (IIOMetadataNode)newChild;
480
IIOMetadataNode refChildNode = (IIOMetadataNode)refChild;
481
482
// Siblings, can be null.
483
IIOMetadataNode previous = null;
484
IIOMetadataNode next = null;
485
486
if (refChild == null) {
487
previous = this.lastChild;
488
next = null;
489
this.lastChild = newChildNode;
490
} else {
491
previous = refChildNode.previousSibling;
492
next = refChildNode;
493
}
494
495
if (previous != null) {
496
previous.nextSibling = newChildNode;
497
}
498
if (next != null) {
499
next.previousSibling = newChildNode;
500
}
501
502
newChildNode.parent = this;
503
newChildNode.previousSibling = previous;
504
newChildNode.nextSibling = next;
505
506
// N.B.: O.K. if refChild == null
507
if (this.firstChild == refChildNode) {
508
this.firstChild = newChildNode;
509
}
510
511
++numChildren;
512
return newChildNode;
513
}
514
515
/**
516
* Replaces the child node {@code oldChild} with
517
* {@code newChild} in the list of children, and returns the
518
* {@code oldChild} node.
519
*
520
* @param newChild the {@code Node} to insert.
521
* @param oldChild the {@code Node} to be replaced.
522
*
523
* @return the node replaced.
524
*
525
* @exception IllegalArgumentException if {@code newChild} is
526
* {@code null}.
527
*/
528
public Node replaceChild(Node newChild,
529
Node oldChild) {
530
if (newChild == null) {
531
throw new IllegalArgumentException("newChild == null!");
532
}
533
534
checkNode(newChild);
535
checkNode(oldChild);
536
537
IIOMetadataNode newChildNode = (IIOMetadataNode)newChild;
538
IIOMetadataNode oldChildNode = (IIOMetadataNode)oldChild;
539
540
IIOMetadataNode previous = oldChildNode.previousSibling;
541
IIOMetadataNode next = oldChildNode.nextSibling;
542
543
if (previous != null) {
544
previous.nextSibling = newChildNode;
545
}
546
if (next != null) {
547
next.previousSibling = newChildNode;
548
}
549
550
newChildNode.parent = this;
551
newChildNode.previousSibling = previous;
552
newChildNode.nextSibling = next;
553
554
if (firstChild == oldChildNode) {
555
firstChild = newChildNode;
556
}
557
if (lastChild == oldChildNode) {
558
lastChild = newChildNode;
559
}
560
561
oldChildNode.parent = null;
562
oldChildNode.previousSibling = null;
563
oldChildNode.nextSibling = null;
564
565
return oldChildNode;
566
}
567
568
/**
569
* Removes the child node indicated by {@code oldChild} from
570
* the list of children, and returns it.
571
*
572
* @param oldChild the {@code Node} to be removed.
573
*
574
* @return the node removed.
575
*
576
* @exception IllegalArgumentException if {@code oldChild} is
577
* {@code null}.
578
*/
579
public Node removeChild(Node oldChild) {
580
if (oldChild == null) {
581
throw new IllegalArgumentException("oldChild == null!");
582
}
583
checkNode(oldChild);
584
585
IIOMetadataNode oldChildNode = (IIOMetadataNode)oldChild;
586
587
IIOMetadataNode previous = oldChildNode.previousSibling;
588
IIOMetadataNode next = oldChildNode.nextSibling;
589
590
if (previous != null) {
591
previous.nextSibling = next;
592
}
593
if (next != null) {
594
next.previousSibling = previous;
595
}
596
597
if (this.firstChild == oldChildNode) {
598
this.firstChild = next;
599
}
600
if (this.lastChild == oldChildNode) {
601
this.lastChild = previous;
602
}
603
604
oldChildNode.parent = null;
605
oldChildNode.previousSibling = null;
606
oldChildNode.nextSibling = null;
607
608
--numChildren;
609
return oldChildNode;
610
}
611
612
/**
613
* Adds the node {@code newChild} to the end of the list of
614
* children of this node.
615
*
616
* @param newChild the {@code Node} to insert.
617
*
618
* @return the node added.
619
*
620
* @exception IllegalArgumentException if {@code newChild} is
621
* {@code null}.
622
*/
623
public Node appendChild(Node newChild) {
624
if (newChild == null) {
625
throw new IllegalArgumentException("newChild == null!");
626
}
627
checkNode(newChild);
628
629
// insertBefore will increment numChildren
630
return insertBefore(newChild, null);
631
}
632
633
/**
634
* Returns {@code true} if this node has child nodes.
635
*
636
* @return {@code true} if this node has children.
637
*/
638
public boolean hasChildNodes() {
639
return numChildren > 0;
640
}
641
642
/**
643
* Returns a duplicate of this node. The duplicate node has no
644
* parent ({@code getParentNode} returns {@code null}).
645
* If a shallow clone is being performed ({@code deep} is
646
* {@code false}), the new node will not have any children or
647
* siblings. If a deep clone is being performed, the new node
648
* will form the root of a complete cloned subtree.
649
*
650
* @param deep if {@code true}, recursively clone the subtree
651
* under the specified node; if {@code false}, clone only the
652
* node itself.
653
*
654
* @return the duplicate node.
655
*/
656
public Node cloneNode(boolean deep) {
657
IIOMetadataNode newNode = new IIOMetadataNode(this.nodeName);
658
newNode.setUserObject(getUserObject());
659
// Attributes
660
661
if (deep) {
662
for (IIOMetadataNode child = firstChild;
663
child != null;
664
child = child.nextSibling) {
665
newNode.appendChild(child.cloneNode(true));
666
}
667
}
668
669
return newNode;
670
}
671
672
/**
673
* Does nothing, since {@code IIOMetadataNode}s do not
674
* contain {@code Text} children.
675
*/
676
public void normalize() {
677
}
678
679
/**
680
* Returns {@code false} since DOM features are not
681
* supported.
682
*
683
* @return {@code false}.
684
*
685
* @param feature a {@code String}, which is ignored.
686
* @param version a {@code String}, which is ignored.
687
*/
688
public boolean isSupported(String feature, String version) {
689
return false;
690
}
691
692
/**
693
* Returns {@code null}, since namespaces are not supported.
694
*/
695
public String getNamespaceURI() throws DOMException {
696
return null;
697
}
698
699
/**
700
* Returns {@code null}, since namespaces are not supported.
701
*
702
* @return {@code null}.
703
*
704
* @see #setPrefix
705
*/
706
public String getPrefix() {
707
return null;
708
}
709
710
/**
711
* Does nothing, since namespaces are not supported.
712
*
713
* @param prefix a {@code String}, which is ignored.
714
*
715
* @see #getPrefix
716
*/
717
public void setPrefix(String prefix) {
718
}
719
720
/**
721
* Equivalent to {@code getNodeName}.
722
*
723
* @return the node name, as a {@code String}.
724
*/
725
public String getLocalName() {
726
return nodeName;
727
}
728
729
// Methods from Element
730
731
732
/**
733
* Equivalent to {@code getNodeName}.
734
*
735
* @return the node name, as a {@code String}
736
*/
737
public String getTagName() {
738
return nodeName;
739
}
740
741
/**
742
* Retrieves an attribute value by name.
743
* @param name The name of the attribute to retrieve.
744
* @return The {@code Attr} value as a string, or the empty string
745
* if that attribute does not have a specified or default value.
746
*/
747
public String getAttribute(String name) {
748
Attr attr = getAttributeNode(name);
749
if (attr == null) {
750
return "";
751
}
752
return attr.getValue();
753
}
754
755
/**
756
* Equivalent to {@code getAttribute(localName)}.
757
*
758
* @see #setAttributeNS
759
*/
760
public String getAttributeNS(String namespaceURI, String localName) {
761
return getAttribute(localName);
762
}
763
764
public void setAttribute(String name, String value) {
765
// Name must be valid unicode chars
766
boolean valid = true;
767
char[] chs = name.toCharArray();
768
for (int i=0;i<chs.length;i++) {
769
if (chs[i] >= 0xfffe) {
770
valid = false;
771
break;
772
}
773
}
774
if (!valid) {
775
throw new IIODOMException(DOMException.INVALID_CHARACTER_ERR,
776
"Attribute name is illegal!");
777
}
778
removeAttribute(name, false);
779
attributes.add(new IIOAttr(this, name, value));
780
}
781
782
/**
783
* Equivalent to {@code setAttribute(qualifiedName, value)}.
784
*
785
* @see #getAttributeNS
786
*/
787
public void setAttributeNS(String namespaceURI,
788
String qualifiedName, String value) {
789
setAttribute(qualifiedName, value);
790
}
791
792
public void removeAttribute(String name) {
793
removeAttribute(name, true);
794
}
795
796
private void removeAttribute(String name, boolean checkPresent) {
797
int numAttributes = attributes.size();
798
for (int i = 0; i < numAttributes; i++) {
799
IIOAttr attr = attributes.get(i);
800
if (name.equals(attr.getName())) {
801
attr.setOwnerElement(null);
802
attributes.remove(i);
803
return;
804
}
805
}
806
807
// If we get here, the attribute doesn't exist
808
if (checkPresent) {
809
throw new IIODOMException(DOMException.NOT_FOUND_ERR,
810
"No such attribute!");
811
}
812
}
813
814
/**
815
* Equivalent to {@code removeAttribute(localName)}.
816
*/
817
public void removeAttributeNS(String namespaceURI,
818
String localName) {
819
removeAttribute(localName);
820
}
821
822
public Attr getAttributeNode(String name) {
823
Node node = getAttributes().getNamedItem(name);
824
return (Attr)node;
825
}
826
827
/**
828
* Equivalent to {@code getAttributeNode(localName)}.
829
*
830
* @see #setAttributeNodeNS
831
*/
832
public Attr getAttributeNodeNS(String namespaceURI,
833
String localName) {
834
return getAttributeNode(localName);
835
}
836
837
public Attr setAttributeNode(Attr newAttr) throws DOMException {
838
Element owner = newAttr.getOwnerElement();
839
if (owner != null) {
840
if (owner == this) {
841
return null;
842
} else {
843
throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
844
"Attribute is already in use");
845
}
846
}
847
848
IIOAttr attr;
849
if (newAttr instanceof IIOAttr) {
850
attr = (IIOAttr)newAttr;
851
attr.setOwnerElement(this);
852
} else {
853
attr = new IIOAttr(this,
854
newAttr.getName(),
855
newAttr.getValue());
856
}
857
858
Attr oldAttr = getAttributeNode(attr.getName());
859
if (oldAttr != null) {
860
removeAttributeNode(oldAttr);
861
}
862
863
attributes.add(attr);
864
865
return oldAttr;
866
}
867
868
/**
869
* Equivalent to {@code setAttributeNode(newAttr)}.
870
*
871
* @see #getAttributeNodeNS
872
*/
873
public Attr setAttributeNodeNS(Attr newAttr) {
874
return setAttributeNode(newAttr);
875
}
876
877
public Attr removeAttributeNode(Attr oldAttr) {
878
removeAttribute(oldAttr.getName());
879
return oldAttr;
880
}
881
882
public NodeList getElementsByTagName(String name) {
883
List<Node> l = new ArrayList<>();
884
getElementsByTagName(name, l);
885
return new IIONodeList(l);
886
}
887
888
private void getElementsByTagName(String name, List<Node> l) {
889
if (nodeName.equals(name) || "*".equals(name)) {
890
l.add(this);
891
}
892
893
Node child = getFirstChild();
894
while (child != null) {
895
((IIOMetadataNode)child).getElementsByTagName(name, l);
896
child = child.getNextSibling();
897
}
898
}
899
900
/**
901
* Equivalent to {@code getElementsByTagName(localName)}.
902
*/
903
public NodeList getElementsByTagNameNS(String namespaceURI,
904
String localName) {
905
return getElementsByTagName(localName);
906
}
907
908
public boolean hasAttributes() {
909
return attributes.size() > 0;
910
}
911
912
public boolean hasAttribute(String name) {
913
return getAttributeNode(name) != null;
914
}
915
916
/**
917
* Equivalent to {@code hasAttribute(localName)}.
918
*/
919
public boolean hasAttributeNS(String namespaceURI,
920
String localName) {
921
return hasAttribute(localName);
922
}
923
924
// Methods from NodeList
925
926
public int getLength() {
927
return numChildren;
928
}
929
930
public Node item(int index) {
931
if (index < 0) {
932
return null;
933
}
934
935
Node child = getFirstChild();
936
while (child != null && index-- > 0) {
937
child = child.getNextSibling();
938
}
939
return child;
940
}
941
942
/**
943
* Returns the {@code Object} value associated with this node.
944
*
945
* @return the user {@code Object}.
946
*
947
* @see #setUserObject
948
*/
949
public Object getUserObject() {
950
return userObject;
951
}
952
953
/**
954
* Sets the value associated with this node.
955
*
956
* @param userObject the user {@code Object}.
957
*
958
* @see #getUserObject
959
*/
960
public void setUserObject(Object userObject) {
961
this.userObject = userObject;
962
}
963
964
// Start of dummy methods for DOM L3.
965
966
/**
967
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
968
* and will throw a {@code DOMException}.
969
* @throws DOMException always.
970
*/
971
public void setIdAttribute(String name,
972
boolean isId)
973
throws DOMException {
974
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
975
"Method not supported");
976
}
977
978
/**
979
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
980
* and will throw a {@code DOMException}.
981
* @throws DOMException always.
982
*/
983
public void setIdAttributeNS(String namespaceURI,
984
String localName,
985
boolean isId)
986
throws DOMException {
987
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
988
"Method not supported");
989
}
990
991
/**
992
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
993
* and will throw a {@code DOMException}.
994
* @throws DOMException always.
995
*/
996
public void setIdAttributeNode(Attr idAttr,
997
boolean isId)
998
throws DOMException {
999
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1000
"Method not supported");
1001
}
1002
1003
/**
1004
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1005
* and will throw a {@code DOMException}.
1006
* @throws DOMException always.
1007
*/
1008
public TypeInfo getSchemaTypeInfo() throws DOMException {
1009
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1010
"Method not supported");
1011
}
1012
1013
/**
1014
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1015
* and will throw a {@code DOMException}.
1016
* @throws DOMException always.
1017
*/
1018
public Object setUserData(String key,
1019
Object data,
1020
UserDataHandler handler) throws DOMException {
1021
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1022
"Method not supported");
1023
}
1024
1025
/**
1026
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1027
* and will throw a {@code DOMException}.
1028
* @throws DOMException always.
1029
*/
1030
public Object getUserData(String key) throws DOMException {
1031
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1032
"Method not supported");
1033
}
1034
1035
/**
1036
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1037
* and will throw a {@code DOMException}.
1038
* @throws DOMException always.
1039
*/
1040
public Object getFeature(String feature, String version)
1041
throws DOMException {
1042
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1043
"Method not supported");
1044
}
1045
1046
/**
1047
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1048
* and will throw a {@code DOMException}.
1049
* @throws DOMException always.
1050
*/
1051
public boolean isSameNode(Node node) throws DOMException {
1052
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1053
"Method not supported");
1054
}
1055
1056
/**
1057
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1058
* and will throw a {@code DOMException}.
1059
* @throws DOMException always.
1060
*/
1061
public boolean isEqualNode(Node node) throws DOMException {
1062
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1063
"Method not supported");
1064
}
1065
1066
/**
1067
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1068
* and will throw a {@code DOMException}.
1069
* @throws DOMException always.
1070
*/
1071
public String lookupNamespaceURI(String prefix) throws DOMException {
1072
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1073
"Method not supported");
1074
}
1075
1076
/**
1077
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1078
* and will throw a {@code DOMException}.
1079
* @throws DOMException always.
1080
*/
1081
public boolean isDefaultNamespace(String namespaceURI)
1082
throws DOMException {
1083
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1084
"Method not supported");
1085
}
1086
1087
/**
1088
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1089
* and will throw a {@code DOMException}.
1090
* @throws DOMException always.
1091
*/
1092
public String lookupPrefix(String namespaceURI) throws DOMException {
1093
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1094
"Method not supported");
1095
}
1096
1097
/**
1098
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1099
* and will throw a {@code DOMException}.
1100
* @throws DOMException always.
1101
*/
1102
public String getTextContent() throws DOMException {
1103
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1104
"Method not supported");
1105
}
1106
1107
/**
1108
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1109
* and will throw a {@code DOMException}.
1110
* @throws DOMException always.
1111
*/
1112
public void setTextContent(String textContent) throws DOMException {
1113
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1114
"Method not supported");
1115
}
1116
1117
/**
1118
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1119
* and will throw a {@code DOMException}.
1120
* @throws DOMException always.
1121
*/
1122
public short compareDocumentPosition(Node other)
1123
throws DOMException {
1124
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1125
"Method not supported");
1126
}
1127
1128
/**
1129
* This DOM Level 3 method is not supported for {@code IIOMetadataNode}
1130
* and will throw a {@code DOMException}.
1131
* @throws DOMException always.
1132
*/
1133
public String getBaseURI() throws DOMException {
1134
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
1135
"Method not supported");
1136
}
1137
//End of dummy methods for DOM L3.
1138
1139
1140
}
1141
1142