1 package org.apache.maven.model.transform;
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.ArrayDeque;
24 import java.util.Deque;
25
26 import org.apache.maven.model.transform.pull.BufferingParser;
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
37
38
39 class FastForwardFilter extends BufferingParser
40 {
41
42
43
44
45
46
47
48
49
50
51
52
53 private final Deque<String> state = new ArrayDeque<>();
54
55 private int domDepth = 0;
56
57 FastForwardFilter( XmlPullParser xmlPullParser )
58 {
59 super( xmlPullParser );
60 }
61
62 @Override
63 public int next() throws XmlPullParserException, IOException
64 {
65 int event = super.next();
66 filter();
67 return event;
68 }
69
70 @Override
71 public int nextToken() throws XmlPullParserException, IOException
72 {
73 int event = super.nextToken();
74 filter();
75 return event;
76 }
77
78 protected void filter() throws XmlPullParserException, IOException
79 {
80 if ( xmlPullParser.getEventType() == START_TAG )
81 {
82 String localName = xmlPullParser.getName();
83 if ( domDepth > 0 )
84 {
85 domDepth++;
86 }
87 else
88 {
89 final String key = state.peekLast() + '/' + localName;
90 switch ( key )
91 {
92 case "execution/configuration":
93 case "plugin/configuration":
94 case "plugin/goals":
95 case "profile/reports":
96 case "project/reports":
97 case "reportSet/configuration":
98 if ( domDepth == 0 )
99 {
100 bypass( true );
101 }
102 domDepth++;
103 break;
104 default:
105 break;
106 }
107 }
108 state.add( localName );
109 }
110 else if ( xmlPullParser.getEventType() == END_TAG )
111 {
112 if ( domDepth > 0 )
113 {
114 if ( --domDepth == 0 )
115 {
116 bypass( false );
117 }
118 }
119 state.removeLast();
120 }
121 }
122
123 @Override
124 public void bypass( boolean bypass )
125 {
126 this.bypass = bypass;
127 }
128 }