1 package org.apache.maven.model.transform.pull;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Objects;
26
27 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
28 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
29
30
31
32
33
34
35
36 public abstract class NodeBufferingParser extends BufferingParser
37 {
38
39 private final List<Event> buffer = new ArrayList<>();
40
41 private final String nodeName;
42
43 private boolean buffering;
44
45 public NodeBufferingParser( XmlPullParser xmlPullParser, String nodeName )
46 {
47 super( xmlPullParser );
48 this.nodeName = Objects.requireNonNull( nodeName );
49 }
50
51 @Override
52 protected boolean accept() throws XmlPullParserException, IOException
53 {
54 if ( nodeName.equals( xmlPullParser.getName() ) )
55 {
56 if ( xmlPullParser.getEventType() == START_TAG && !buffering )
57 {
58 buffer.add( bufferEvent() );
59 buffering = true;
60 return false;
61 }
62 if ( xmlPullParser.getEventType() == END_TAG && buffering )
63 {
64 buffer.add( bufferEvent() );
65 process( buffer );
66 buffering = false;
67 buffer.clear();
68 return false;
69 }
70 }
71 else if ( buffering )
72 {
73 buffer.add( bufferEvent() );
74 return false;
75 }
76 return true;
77 }
78
79 protected abstract void process( List<Event> buffer );
80
81 }