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