1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.project.harness;
20
21 import java.util.ArrayList;
22 import java.util.LinkedHashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.commons.jxpath.ri.QName;
27 import org.apache.commons.jxpath.ri.model.NodeIterator;
28 import org.apache.commons.jxpath.ri.model.NodePointer;
29 import org.codehaus.plexus.util.xml.Xpp3Dom;
30
31
32
33
34
35
36 class Xpp3DomAttributeIterator implements NodeIterator {
37
38 private NodePointer parent;
39
40 private Xpp3Dom node;
41
42 private List<Map.Entry<String, String>> attributes;
43
44 private Map.Entry<String, String> attribute;
45
46 private int position;
47
48 public Xpp3DomAttributeIterator(NodePointer parent, QName qname) {
49 this.parent = parent;
50 this.node = (Xpp3Dom) parent.getNode();
51
52 Map<String, String> map = new LinkedHashMap<>();
53 for (String name : this.node.getAttributeNames()) {
54 if (name.equals(qname.getName()) || "*".equals(qname.getName())) {
55 String value = this.node.getAttribute(name);
56 map.put(name, value);
57 }
58 }
59 this.attributes = new ArrayList<>(map.entrySet());
60 }
61
62 public NodePointer getNodePointer() {
63 if (position == 0) {
64 setPosition(1);
65 }
66 return (attribute == null) ? null : new Xpp3DomAttributePointer(parent, attribute);
67 }
68
69 public int getPosition() {
70 return position;
71 }
72
73 public boolean setPosition(int position) {
74 this.position = position;
75 attribute = (position > 0 && position <= attributes.size()) ? attributes.get(position - 1) : null;
76 return attribute != null;
77 }
78 }