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.List;
22 import java.util.Map;
23 import java.util.stream.Collectors;
24
25 import org.apache.commons.jxpath.ri.QName;
26 import org.apache.commons.jxpath.ri.model.NodeIterator;
27 import org.apache.commons.jxpath.ri.model.NodePointer;
28 import org.apache.maven.internal.xml.XmlNodeImpl;
29
30
31
32
33
34 class Xpp3DomAttributeIterator implements NodeIterator {
35
36 private NodePointer parent;
37
38 private XmlNodeImpl node;
39
40 private List<Map.Entry<String, String>> attributes;
41
42 private Map.Entry<String, String> attribute;
43
44 private int position;
45
46 public Xpp3DomAttributeIterator(NodePointer parent, QName qname) {
47 this.parent = parent;
48 this.node = (XmlNodeImpl) parent.getNode();
49
50 this.attributes = this.node.getAttributes().entrySet().stream()
51 .filter(a -> a.getKey().equals(qname.getName()) || "*".equals(qname.getName()))
52 .collect(Collectors.toList());
53 }
54
55 public NodePointer getNodePointer() {
56 if (position == 0) {
57 setPosition(1);
58 }
59 return (attribute == null) ? null : new Xpp3DomAttributePointer(parent, attribute);
60 }
61
62 public int getPosition() {
63 return position;
64 }
65
66 public boolean setPosition(int position) {
67 this.position = position;
68 attribute = (position > 0 && position <= attributes.size()) ? attributes.get(position - 1) : null;
69 return attribute != null;
70 }
71 }