1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.transform;
20
21 import java.io.IOException;
22 import java.util.ArrayDeque;
23 import java.util.Deque;
24
25 import org.apache.maven.model.transform.pull.BufferingParser;
26 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
27 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
28
29
30
31
32
33
34
35
36
37
38 class FastForwardFilter extends BufferingParser {
39
40
41
42
43
44
45
46
47
48
49
50
51 private final Deque<String> state = new ArrayDeque<>();
52
53 private int domDepth = 0;
54
55 FastForwardFilter(XmlPullParser xmlPullParser) {
56 super(xmlPullParser);
57 }
58
59 @Override
60 public int next() throws XmlPullParserException, IOException {
61 int event = super.next();
62 filter();
63 return event;
64 }
65
66 @Override
67 public int nextToken() throws XmlPullParserException, IOException {
68 int event = super.nextToken();
69 filter();
70 return event;
71 }
72
73 protected void filter() throws XmlPullParserException, IOException {
74 if (xmlPullParser.getEventType() == START_TAG) {
75 String localName = xmlPullParser.getName();
76 if (domDepth > 0) {
77 domDepth++;
78 } else {
79 final String key = state.peekLast() + '/' + localName;
80 switch (key) {
81 case "execution/configuration":
82 case "plugin/configuration":
83 case "plugin/goals":
84 case "profile/reports":
85 case "project/reports":
86 case "reportSet/configuration":
87 if (domDepth == 0) {
88 bypass(true);
89 }
90 domDepth++;
91 break;
92 default:
93 break;
94 }
95 }
96 state.add(localName);
97 } else if (xmlPullParser.getEventType() == END_TAG) {
98 if (domDepth > 0) {
99 if (--domDepth == 0) {
100 bypass(false);
101 }
102 }
103 state.removeLast();
104 }
105 }
106
107 @Override
108 public void bypass(boolean bypass) {
109 this.bypass = bypass;
110 }
111 }