gnodet commented on code in PR #697:
URL: https://github.com/apache/maven/pull/697#discussion_r846990273
##########
maven-model-transform/src/main/java/org/apache/maven/model/transform/pull/NodeBufferingParser.java:
##########
@@ -38,44 +37,54 @@
private final List<Event> buffer = new ArrayList<>();
- private final String nodeName;
+ private final ArrayList<String> stack = new ArrayList<>();
private boolean buffering;
- public NodeBufferingParser( XmlPullParser xmlPullParser, String nodeName )
+ public NodeBufferingParser( XmlPullParser xmlPullParser )
{
super( xmlPullParser );
- this.nodeName = Objects.requireNonNull( nodeName );
}
@Override
protected boolean accept() throws XmlPullParserException, IOException
{
- if ( nodeName.equals( xmlPullParser.getName() ) )
+ int event = xmlPullParser.getEventType();
+ if ( event == START_TAG )
{
- if ( xmlPullParser.getEventType() == START_TAG && !buffering )
+ String name = xmlPullParser.getName();
+ stack.add( name );
+ if ( !buffering )
{
- buffer.add( bufferEvent() );
- buffering = true;
- return false;
+ buffering = shouldBuffer( stack );
}
- if ( xmlPullParser.getEventType() == END_TAG && buffering )
+ }
+ else if ( event == END_TAG )
+ {
+ stack.remove( stack.size() - 1 );
+ if ( buffering )
{
- buffer.add( bufferEvent() );
- process( buffer );
- buffering = false;
- buffer.clear();
- return false;
+ buffering = shouldBuffer( stack );
+ if ( !buffering )
+ {
+ buffer.add( bufferEvent() );
+ process( buffer );
+ buffering = false;
+ buffer.clear();
+ return false;
+ }
}
}
- else if ( buffering )
+ if ( buffering )
{
buffer.add( bufferEvent() );
return false;
}
return true;
}
+ protected abstract boolean shouldBuffer( ArrayList<String> stack );
Review Comment:
@mthmulders I agree with your here, not sure why I ended up with an
ArrayList in the method signature...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]